ifft returns a complex signal from a real fft spectrum; i desire a real signal

68 次查看(过去 30 天)
Hi all,
I've been trying to synthesize a 1 second long complex tone with 10 harmonics (at 200Hz, 400Hz, ... 2000Hz) of equal power using Matlab. My code below assigns real fft values (nothing in the imaginary domain), then performs an ifft. However, the ifft produces real + imag values, and I want a real signal.
sigfft = zeros(44100,1);
for i=1:10
sigfft(i*200) = 1000;
sigfft(44100-i*200) = 1000;
end
sig = ifft(sigfft);
Questions: First, why am I getting these imag values?
Second, how do I force ifft to give me real values instead of real + imag values?
Cheers

采纳的回答

Walter Roberson
Walter Roberson 2011-8-11
The first non-zero frequency is at sigfft(2) not sigfft(1) -- you have to shift the left-hand side frequencies by one bin to the right, sigfft(1+i*200)
Likewise, suppose for a moment that the harmonics were 1 Hz apart starting from 1 Hz. Your code would use sigfft(44100-i*1) which would be sigfft(44099). The last bin though, corresponds to the first non-zero point, so you should be using sigfft(44100+1-i*200)
You now need to take in to account that because the first bin is occupied by the constant power (like the DC frequency 0 Hz) but the last bin does not include that, then if you have an even number of bins to start, and you proceed far enough with the harmonics, you may find that bin 22051 corresponds to both an harmonic "starting from the front" and a harmonic "starting from the back". You need to work out whether that means that a special value should be put in to that location.

更多回答(3 个)

Honglei Chen
Honglei Chen 2011-8-11
Hi Jeff,
There is no guarantee that the real spectrum will generate a real signal. Between time domain and frequency domain, if the signal in one domain is real, then the signal in the other domain has to be symmetric. You can find details in any DSP book such as Oppenheim's. A subtle point in programming this is that in MATLAB, the frequency domain is often represented from 0 to 2*pi so if you want to start with a symmetric sequence, you may want to use iffshift first to make it correctly mapped from 0 to 2*pi. Here is a quick example:
>> ifft(ifftshift([1 0 0 0 1 0 0 0 1]))
HTH

Daniel Shub
Daniel Shub 2011-8-11
try
sigfft(44100+2-i*200) = 1000;
notice the +2.
  2 个评论
Walter Roberson
Walter Roberson 2011-8-11
I'm not convinced, Daniel. If the increment were 1 instead of 200, then for i=1, you would have sigfft(44100+2-1) which would be outside of the defined sigfft vector.
Daniel Shub
Daniel Shub 2011-8-12
Walter you are correct. I was only focusing on making sigfft symmetric to get a real signal, and not on the frequency components. My answer will produce a real signal with frequencies that are off by one frequency bin (i.e., 1+i*200 instead of i*200).

请先登录,再进行评论。


Nike
Nike 2013-3-25
Hi , why havent you tried adding multiple sine waves as below.
fs = 44100; %sampling frequency
dur = 1; %duration in seconds
n = fs*dur; % number off samples
t = 1/fs:1/fs:dur; %time array
freq = [200:200:10*200];%frequency components
db = 80; % intensity
amp = 10^((db-100)/20);
for i = 1:length(freq)
tone = amp*sin(2*pi*freq(i)*t);
tones(:,i) = tone;
end
complex = sum(tones,2);
plot(t,complex)
sound(complex,fs)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by