我已經爲音頻信號的頻率調製寫了下面的代碼。音頻本身是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;
}
好的,但是你的問題是什麼? – 2011-12-30 09:09:48
那麼,這段代碼似乎並沒有工作,我甚至不知道它是否應該工作。我在另一個線程(http://stackoverflow.com/questions/8655121/frequency-modulation-fm)問這個問題,只是試圖實現我在那裏被告知。 – 2011-12-30 09:30:07