Why are the peaks of my spectrum not exactly at the frequencies of my sinusoidal input signal?

6 次查看(过去 30 天)
I consider an input signal, which is the superposition of 2 sine-waves of different frequencies and phases, but the same amplitude. I want to create the spectrum of it. Since the 2 frequencies are 11 GHz and 11.5 GHz, I expect the peaks of my spectrum to be at exactly these 2 frequencies. However when I plot the spectrum, one peak is at 1.101e+10 and the other is at 1.151e+10 Hz. I am new to fft so I don't understand what I have done wrong. Do you think a window-function might help? I'd take the time to read about it then.
T = 100e-9; % acquisition
f_s = 1e12; % sampling rate
t = transpose(0 : 1/f_s : T-1/f_s); % samples, size = 10000
f_c = 11.5e9; % specify carrier frequency in Hz
% we consider the sum of 2 input signals
f_1 = -0.5e9;
f_2 = 0;
f = [f_1 f_2]';
% specify phase in degree
theta_1_deg = 0;
theta_2_deg = 0;
theta_1 = degtorad(theta_1_deg);
theta_2 = degtorad(theta_2_deg);
theta = [theta_1 theta_2]';
A single sine-wave looks like this:
x_sine(:,i) = A_in*sin(2*pi*(f_c+f(i))*t + theta(i));
I generate it for f1 and f2 and then I add it and perform a one-sided fft.

采纳的回答

David Goodmanson
David Goodmanson 2016-12-27
Hi Luc, I don't believe that the fft or ifft is necessarily inaccurate just because it is discrete or has finite boundaries. Your time grid is correct, but I think you just have an off-by-one problem with the frequency grid, which for an fft should start at f = 0. If you run the code below you will find the two peaks exactly where you think they should be.
T = 100e-9; % acquisition
f_s = 1e12; % sampling rate
t = transpose(0 : 1/f_s : T-1/f_s); % samples, size = 10000
% construct frequency grid
N = length(t);
delf = f_s/N;
f = (0:N-1)*delf;
f_c = 11.5e9; % specify carrier frequency in Hz
% we consider the sum of 2 input signals
f_1 = -0.5e9;
f_2 = 0;
x = sin(2*pi*(f_c + f_1)*t) + sin(2*pi*(f_c + f_2)*t);
z = fft(x);
plot(f,abs(z))
xlim([1e10 1.2e10])
  2 个评论
Luki
Luki 2016-12-27
编辑:Luki 2016-12-27
ok, thx very much! Can you explain why your code works:
N = length(t);
delf = f_s/N;
f = (0:N-1)*delf;
and this does not:
f_negative = linspace(-f_s/2,f_s/2,length(x));
f_positive = f1(end/2+1:end);
Am I not addressing frequency 0 ? I would plot x vs f_positive
David Goodmanson
David Goodmanson 2016-12-27
The issue is that fft(x) always puts zero frequency at the first point in the array. If you had used
z = fftshift(fft(z))
then the point in z corresponding to f = 0 is in the middle of the array. I will discuss only N even here, so f = 0 is at point N/2+1. If you were going to make a plot or something, you could make the appropriate frequency grid for that,
(-N/2:N/2-1)*delf.
Then pull off the upper half of that array for positive frequencies. However, without using fftshift the positive frequency points are always in the lower half of the array. To get positive frequencies I think it's easier to just do
z(1:N/2) % values
(0:N/2-1)*delf % freqs
f(1:N/2) % freqs if you already have the right f grid
Note the off-by-one situation between z and f. f=0 has to be at point 1 since Matlab is one-based.
There is a slight change in the details for N odd.

请先登录,再进行评论。

更多回答(2 个)

John D'Errico
John D'Errico 2016-12-26
Is a fast Fourier transform, based on a finitely sampled signal, identical to a true Fourier transform, based on integration of functions? (Hint: No.)
A FFT is an approximation, based on a finitely sampled signal. Just as a trapezoidal rule for integration is not exactly correct for almost all smooth functions, this is also true for the FFT.
On the other hand, an FFT is a hell of a lot easier and faster to compute.
Did your result actually come pretty close to what you expected? (Yes.) So why do you think you have a problem? (I don't know.)

Image Analyst
Image Analyst 2016-12-26
编辑:Image Analyst 2016-12-26
See my attached demo.
Note that there are two frequencies added together and you do get the 4 spikes as expected. But see there is still some energy near the bottom of the spikes. This is due to cropping the signal. As you know the transform of a rect (your cropping function) is a sinc function so the spikes are convolved with a sinc. Recall that multiplication by a rect in the time domain is convolution of the two spectra, in other words convolution of delta functions (FT of sine waves) with sincs (FT of rect).

类别

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