Electronics > Projects, Designs, and Technical Stuff
why The FFT can not compute this second harmonic correctly?
<< < (3/6) > >>
GeoffreyF:
A single cycle as you show also has a sharp cut off which generates harmonics.  The ideal FFT is for something that begins infinitely in the past and ends infinitely in the future.  Often a sample signal has many cycles beginning with a very small amplitude and ending the same.

A single cycle is just that, it's not even an approximation of a wave over time.
Conrad Hoffman:
And thus, windowing, which can be done in about a dozen different ways.
ali_asadzadeh:

--- Quote ---And thus, windowing, which can be done in about a dozen different ways.
--- End quote ---
Thanks, I was thinking of windowing too, any ideas what type and how should I apply that?
Marco:

--- Quote from: ali_asadzadeh on December 25, 2018, 11:34:55 am ---Thanks for the response, so, do you have any idea how I can extract that 100Hz from the 32 sub-samples?

--- End quote ---

Zero pad the 32 samples to 64, then do the DFT. But you're not really extracting the 1/64 frequency signal, you are assuming it's present and based on that assumption determining it's strength. It could just as well not be, the 32 sample signal is a perfectly valid periodic signal without any 1/64 frequency component at all.
radioactive:
The problem is that even though the cut samples of 32 length still contains the shorter wavelength, it is still a composite signal.  As others mentioned, the cut causes the boundaries of the finite sequence to be non-zero.  This causes lots of undesired output in the fft.  Windowing can be used to force the boundaries to zero.  I changed the start point of the cut to be 1/8 of the way into the 32-sample sequence and applied triangular windows.  Somewhat of trick question, so here is somewhat of a trick answer:   If nothing else, it shows how to do windowing and zero padding.


--- Code: ---pkg load signal
N=4096; %zero pad results to N-bin fft
t=linspace(0,2*pi,64);
x=sin(t);
y=sin(2*t);
s1= x + y;
s2= s1((64/8):(64/8)+length(s1)/2-1); %grab half(32) the samples from s1 starting 1/8 in
win1=triang(length(s1)); %generate triangular windows
win2=triang(length(s2));
k1=24  %gain adj for win1
k2=k1/2  %gain adj for win2
s1 = s1.*win1'; %apply windows to samples
s2 = s2.*win2';
s1 = [zeros(1,N/2-32) s1 zeros(1,N/2-32)];  %zero pad for higher-res fft
s2 = [zeros(1,N/2-16) s2 zeros(1,N/2-16)];
fft1 = abs(fft(s1)); %get the mag of fft
fft2 = abs(fft(s2));
plot( fft1(1:length(fft1)/2)/k1, '*r' );
hold on;
plot( fft2(1:length(fft2)/2)/k2, '+b' );
hold off;
--- End code ---


Navigation
Message Index
Next page
Previous page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod