2011-12-30 85 views
0

我已经为音频信号的频率调制写了下面的代码。音频本身是1秒长,以8000赫兹采样。我想通过使用频率为50 Hz的正弦波(表示为采样频率的一部分)将FM应用于此音频信号。调制信号的调制指数为0.25,以便只产生一对边带。调频(FM)代码片段

for (i = 0; i < 7999; i++) { 
    phi_delta = 8000 - 8000 * (1 + 0.25 * sin(2* pi * mf * i)); 
    f_phi_accum += phi_delta; //this can have a negative value 
    /*keep only the integer part that'll be used as an index into the input array*/ 
    i_phi_accum = f_phi_accum; 
    /*keep only the fractional part that'll be used to interpolate between samples*/ 
    r_phi_accum = f_phi_accum - i_phi_accum; 
    //If I'm getting negative values should I convert them to positive 
    //r_phi_accum = fabs(f_phi_accum - i_phi_accum); 
    i_phi_accum = abs(i_phi_accum); 
    /*since i_phi_accum often exceeds 7999 I have to add this if statement so as to  prevent out of bounds errors */ 
    if (i_phi_accum < 7999) 
     output[i] = ((input[i_phi_accum] + input[i_phi_accum + 1])/2) * r_phi_accum;    
} 
+1

好的,但是你的问题是什么? – 2011-12-30 09:09:48

+0

那么,这段代码似乎并没有工作,我甚至不知道它是否应该工作。我在另一个线程(http://stackoverflow.com/questions/8655121/frequency-modulation-fm)问这个问题,只是试图实现我在那里被告知。 – 2011-12-30 09:30:07

回答

1

你phi_delta的计算是关闭的8000因子和偏移 - 它应该是1个+/-小的值,即

phi_delta = 1.0 + 0.25 * sin(2.0 * pi * mf * i)); 

这将导致phi_delta具有一定范围的0.75至1.25。

+0

好的,谢谢,我会试一试并报告结果。还有一个额外的问题。如果我的调制指数使用2而不是0.25,那么我会得到phi_delta在-1到3的范围内,所以我可能会得到一些phi_accum的负值(如果phi_delta在循环)。现在我该如何处理这种情况? – 2011-12-30 10:10:48

+0

其实忘了我最后的评论。我会先试一试 – 2011-12-30 10:14:36

+0

通常情况下,波形表会是周期性的,您会将查找表索引以表格的大小为模,即索引应该“环绕”。您的采样音频可能不是周期性的,但您现在仍然可以使用模索引作为第一个近似值。 – 2011-12-30 10:29:49