필터 지우기
필터 지우기

FFT of a single sinusoid showing noise ?!

조회 수: 11 (최근 30일)
Nathan Kennedy
Nathan Kennedy 2018년 10월 22일
편집: Bruno Luong 2018년 10월 22일
Hi,
I have a signal which I am sampling so at least 10 wavelengths or 10 time periods can be plotted. It then works out how many samples are required based on the sample frequency.
I have done a FFT quite a few times but this is somehow showing unwanted frequency components on a pure sinusoidal signal...
clear all
f = 30 %Carrier freqency
Fs = 20* f; %Sample frequency atleast 2*f
Ts = 1/Fs; %Sample time
%Number of points must be a factor of 2^n and be greater than the number of
%points required for the wanted number of time periods on the plot
plot_periods_of_f = 10;
min_num_samples = (plot_periods_of_f * (1/f)) / (Ts)
%Make sure the number of samples, Ns, is greater than min_num_samples
a=1
while 2^a < min_num_samples
a = a+1;
Ns = 2^a;
end
n = (0:Ns-1)*Ts; %Time vector
sig = cos(2*pi*f*n );
%Setup FFT
N=Ns;
freq_domain = (0:N/2); %Show positive frequency only
freq_domain = freq_domain * Fs / N;
%FFT
ft_raw = fft(sig)/N;
ft = 2*abs(ft_raw); % 2* to compensate for negative frequency energy
ft = ft(1:N/2+1); %Show positive frequency only so it matches the setup of frequency domain
%plot
figure(1);cla;clf
subplot(2,1,1)
plot(n,sig)
subplot(2,1,2);
bar(ft)
For some odd reason my fft is showing noise and I cant seem to work out why... what have I done incorrectly? I thought its all okay..
  댓글 수: 4
Adam
Adam 2018년 10월 22일
The fft assumes an infinite signal. You would only get a pure dirac in the frequency domain if you could run it on an infinite sine wave, which you can't. The truncation means that you are running it on an approximation instead, which will be zero to plus/minus infinity.
Your script below also has leakage, it is just a lot smaller because your sine wave has a lot more cycles so is closer to an infinite sine wave (though obviously still not one).
Nathan Kennedy
Nathan Kennedy 2018년 10월 22일
편집: Nathan Kennedy 2018년 10월 22일
Do you mean truncated in that when the discrete sinusoid is placed as infinite signal in the fft, the start and end are not seen as continuous because the my signal starts at 1 and finishes at a value other than 1?
If so, then I see what you are getting at. Is there any neat tricks of setting up a discrete wave so ensure its looks sinusoidal when placed end to end ie, start and finish at same value and also I can specify how many wavelengths I want?

댓글을 달려면 로그인하십시오.

답변 (2개)

Matt J
Matt J 2018년 10월 22일
편집: Matt J 2018년 10월 22일
Looks normal to me, too. Aside from the fact that the sinusoid is discrete, it is also a truncated, non-periodic sampling, so there's no reason to expect only a single frequency component.
  댓글 수: 10
Matt J
Matt J 2018년 10월 22일
I have been using this previously and it works for all frequencies
It doesn't. For example,
Fs =2^8;
Ts = 1/Fs;
Ns = (2^12);
n = (0:Ns-1)*Ts;
s=cos(2*pi*(Fs/567)*n);
figure(1);
plot(n,s);
figure(2);
F=abs(fft(s));
bar(F/max(F))
xlim([0,100]);
ylim([0,.3])
title 'Normalized Amplitude Response'
Matt J
Matt J 2018년 10월 22일
편집: Matt J 2018년 10월 22일
Maybe this is what you're looking for
%%User-selected parameters
f=30; %Frequency of sinusoid
M=5; %number of periods of the sinusoid
Fs=2^8; %Number of samples per period
%%Generate signal
T=M/f; %Total duration of signal - M periods
n=linspace(0,T,M*Fs+1); %sample times
n(end)=[];
Ts=n(2)-n(1);
s = cos(2*pi*f*n);
%%Plot
figure(1);
plot(n,s);
figure(2);
F=abs(fft(s));
bar(F/max(F))
xlim([0,100]);
ylim([0,.3])
title 'Normalized Amplitude Response'
shg

댓글을 달려면 로그인하십시오.


Bruno Luong
Bruno Luong 2018년 10월 22일
편집: Bruno Luong 2018년 10월 22일
FFT/DFT returns components of the sins/cosine function that are exactly periodic with respect to the number of input data points. You can see as circular spectrum.
If you feed FFT with an input sig with a mono frequency but that is not exactly one of those periodic frequencies, meaning your signal when wrap around has a jump (~ sig(end)-sig(1)), the spectrum will stretch out to accommodate to the jump (similar to a continuous transform of the heaviside fct).
This is not "noise", but miss-understanding of the fundamental of DFT (by too many people unfortunately).

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by