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?
No products are associated with this question.
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.
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]))
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)