fft showing frequency components at double rates
27 views (last 30 days)
worked with Lumerical (photonic simulating software) i got a output Time domain-signal and wanted to see it's spectrum via fft , so i used fft but the plot is showing me components at double rate which lumerical moniter visualizing spectrum shows the right spectrum, so i wondered why it is, if you have an experince or such it would be great , and Here's my code for making this happen:
% fs = 100; % sample frequency (Hz)
% t = 0:1/fs:10-1/fs; % 10 second span time vector
% y = (1.3)*sin(2*pi*15*t) ... % 15 Hz component
% + (1.7)*sin(2*pi*40*(t-2)) ... % 40 Hz component
% + 2.5*randn(size(t)); % Gaussian noise;
xlabel('Time in s')
ylabel('Output field Magnitude')
fft_y = fft(y);
% [A,B,C,D] = butter(20,[192.668e+12 192.945e+12]/fs);
% d = designfilt('bandpassiir','FilterOrder',20, ...
% 'HalfPowerFrequency1',192.668e+12,'HalfPowerFrequency2',192.945e+12, ...
n = length(y); % number of samples
f = (0:n-1)*(fs/n); % frequency range
power = abs(fft_y).^2/n; % power of the DFT
y0 = fftshift(fft_y); % shift y values
f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range
power0 = abs(y0).^2/n; % 0-centered power
as you can see plot worked and showed the frequency components for my output time-signal
at the top of script (comment lines) i added a sinus function to test this script and it works well and shows right components, i got this script from mathworks platform,
My script should show frequncy components at 192.806 THz , 193.431THz ,194.055 THz but shows these at 385.612 THz, 386.862 THz , 388.11 THz (around 0.3e+15 in plot)
can somebody tell me why is that? And How it can be solved right to get right plot?
i have a guess which may be relevent that Nyquist theorm for complex signals states that the fsampling is maximum frequency that you can show unambigiously which in real signals are fsampling/2
David Goodmanson on 4 Jan 2022
Edited: David Goodmanson on 4 Jan 2022
Here is an observation and a possible answer. If you expand out plot(t,y) (I used
xlim([4 4.1]*1e-12) )
there are about 4 cycles in 10^-14 sec, or 400 THz, I think the fft is working correctly, given what its input is. However, you say you are fft-ing the magnitude of the signal. To me y doesn't look exactly like the magnitude of a signal might, but it is certainly always positive.
If you do an fft on a signal cos(2*pi*f0*t) you of course get peaks at +-f0. But abs(cos(2*pi*f0*t)) has twice as many oscillations per unit time as does cos(2*pi*f0*t). So you get peaks at 2*f0, plus a bunch of other smaller peaks that don't really seem to be showing up.