フィルターのクリア

FFT of a single sinusoid showing noise ?!

12 ビュー (過去 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 Center および File ExchangeMatched 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