DSPRelated.com
Forums

Should the normal SINE and Zero padded SINE curves be the same for fft output?

Started by rsk February 5, 2010
All

This might have been discussed multiple times. However, I am new comer to
the site.

My question is given below. I wanted to put plots but could not find the
way to do it.



I took a sine curve from 0-1 s( 1Hz)and 'fft'ed it in MATLAB. I get unit
magnitude at 1 Hz as expected. Sampling rate 1024.

Then I zero padded it till 2 sec. So, total lines = 2048. The fft then
showed major peak(0.5 magnitude) at 2 Hz with other higher frequencies
present.

All articles on zero padding say that, zero padding does not add more
information but just makes existing information more fine. Going by that,
the fft in second case should also have shown peak at 1 Hz. May I know
where did I go wrong?

In Summary, should there be a difference in the usual sine wave and zero
padded sine wave with respect to frequency spectrum? 

Thanks 

Rahul


rsk wrote:
> All > > This might have been discussed multiple times. However, I am new comer to > the site. > > My question is given below. I wanted to put plots but could not find the > way to do it. > > > > I took a sine curve from 0-1 s( 1Hz)and 'fft'ed it in MATLAB. I get unit > magnitude at 1 Hz as expected. Sampling rate 1024. > > Then I zero padded it till 2 sec. So, total lines = 2048. The fft then > showed major peak(0.5 magnitude) at 2 Hz with other higher frequencies > present. > > All articles on zero padding say that, zero padding does not add more > information but just makes existing information more fine. Going by that, > the fft in second case should also have shown peak at 1 Hz. May I know > where did I go wrong? > > In Summary, should there be a difference in the usual sine wave and zero > padded sine wave with respect to frequency spectrum?
You tell us what you intended to do, but I can't analyze your result without knowing what you actually did. I can guess, though. Have you misinterpreted the frequencies associated with the bins in the second case? zero padding will make twice as many bins, so what was 1 Hz before becomes 0.5 Hz after padding. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
On 5 Feb, 17:03, "rsk" <kalera...@yahoo.com> wrote:

> In Summary, should there be a difference in the usual sine wave and zero > padded sine wave with respect to frequency spectrum?
Of course. The two signals are diffrent, so their spectra should be different. This is a trivial consequence of the DFT being a linear operation. Rune
>All > >This might have been discussed multiple times. However, I am new comer
to
>the site. > >My question is given below. I wanted to put plots but could not find the >way to do it. > > > >I took a sine curve from 0-1 s( 1Hz)and 'fft'ed it in MATLAB. I get unit >magnitude at 1 Hz as expected. Sampling rate 1024. > >Then I zero padded it till 2 sec. So, total lines = 2048. The fft then >showed major peak(0.5 magnitude) at 2 Hz with other higher frequencies >present. > >All articles on zero padding say that, zero padding does not add more >information but just makes existing information more fine. Going by
that,
>the fft in second case should also have shown peak at 1 Hz. May I know >where did I go wrong? > >In Summary, should there be a difference in the usual sine wave and zero >padded sine wave with respect to frequency spectrum? > >Thanks > >Rahul >
I believe what you are seeing is the Gibbs phenomenon. When you pad the input with zeros, you are creating an edge or transition where the sine wave stops. This transition contains harmonics of the 1Hz sine wave you sampled. Jacob
On Feb 5, 1:38&#4294967295;pm, "foxcob" <jacob.the...@gmail.com> wrote:
> > >This might have been discussed multiple times. However, I am new comer to > >the site. > > >My question is given below. I wanted to put plots but could not find the > >way to do it. > > >I took a sine curve from 0-1 s( 1Hz)and 'fft'ed it in MATLAB. I get unit > >magnitude at 1 Hz as expected. Sampling rate 1024. > > >Then I zero padded it till 2 sec. So, total lines = 2048. The fft then > >showed major peak(0.5 magnitude) at 2 Hz with other higher frequencies > >present. > > >All articles on zero padding say that, zero padding does not add more > >information but just makes existing information more fine. Going by that, > >the fft in second case should also have shown peak at 1 Hz. May I know > >where did I go wrong? > > >In Summary, should there be a difference in the usual sine wave and zero > >padded sine wave with respect to frequency spectrum? > > > I believe what you are seeing is the Gibbs phenomenon. &#4294967295;When you pad the > input with zeros, you are creating an edge or transition where the sine > wave stops. &#4294967295;This transition contains harmonics of the 1Hz sine wave you > sampled.
even if there is no zero-padding, there is Gibbs phenomena when the number of cycles of the sinusoid in the FFT buffer is not an integer (because of the discontinuity where it wraps around from x[N-1] to x[0]) if the number of cycles in the FFT buffer is a nice integer (let's say that integer is M) you will see a nice clean spike at X[M] and at X[N- M] (i mean that X[0] is the DC component, in case you're using MATLAB) with zeros or very low-level noise in the other bins. r b-j
On Feb 5, 8:03&#4294967295;am, "rsk" <kalera...@yahoo.com> wrote:
> ... > In Summary, should there be a difference in the usual sine wave and zero > padded sine wave with respect to frequency spectrum? > ...
When the fft results are plotted on the same frequency scale from 0 to Fs, the results should be the same for any frequency for which a sample is generated. Zero sampling to N timed the original data length will generate each of the unextended frequency samples and N-1 intermediate (in frequency) samples. If you have access to Matlab, you can plot examples from the following snippet: % 4 Hz Sine, 32 point fft, 64 point w/ zero fill % Sample Freq = 32 Hz hz4 = cos(4*2*pi*(0:31)/32); hz4zeros = zeros(1,64); hz4zeros(1:32) = hz4; hz4x128 = zeros(1,128); hz4x128(1:32) = hz4; hz4x512 = zeros(1,512); hz4x512(1:32) = hz4; figure % First plot( ... (0:31),hz4,'ro', (0:31),hz4,'r-', ... (0:63),hz4zeros,'kx', (0:63),hz4zeros,'k:') title('Time Domain Plot') xlabel('Sample: Red-o-32 samples Black-x-64 samples') axis([-2 66 -1.2 1.2]) grid on figure % Second plot( ... linspace(0,1-(1/128),128),real(fft(hz4x128)),'b+', ... linspace(0,1-(1/32),32),real(fft(hz4)),'ro', ... linspace(0,1-(1/64),64),real(fft(hz4zeros)),'kx', ... linspace(0,1-(1/128),128),real(fft(hz4x128)),'b-', ... linspace(0,1-(1/32),32),real(fft(hz4)),'r-', ... linspace(0,1-(1/64),64),real(fft(hz4zeros)),'k:') title('Frequency Domain Plot') ylabel('FFT Response') xlabel('Fraction of Sample Freq. Zero-fill:Red:none Blk:x2 Blu:x4') axis([-0.02 0.52 -18 18]); grid on figure % Third plot( ... linspace(0,1-(1/512),512),real(fft(hz4x512)),'g*', ... linspace(0,1-(1/512),512),real(fft(hz4x512)),'g-', ... linspace(0,1-(1/128),128),real(fft(hz4x128)),'bx', ... linspace(0,1-(1/32),32),real(fft(hz4)),'ro', ... linspace(0,1-(1/64),64),real(fft(hz4zeros)),'k+', ... linspace(0,1-(1/64),64),real(fft(hz4zeros)),'k-', ... linspace(0,1-(1/32),32),real(fft(hz4)),'r-', ... linspace(0,1-(1/128),128),real(fft(hz4x128)),'b-') title('Frequency Domain Plot, Expanded about peak') xlabel('Zero-fill Red:none Blk:x2 Blu:x4 Grn:x16') ylabel('FFT Response') axis([0.09 0.16 -18 18]); grid on Dale B. Dalrymple
On Feb 5, 9:03&#4294967295;pm, "rsk" <kalera...@yahoo.com> wrote:
> All > > This might have been discussed multiple times. However, I am new comer to > the site. > > My question is given below. I wanted to put plots but could not find the > way to do it. > > I took a sine curve from 0-1 s( 1Hz)and 'fft'ed it in MATLAB. I get unit > magnitude at 1 Hz as expected. Sampling rate 1024. > > Then I zero padded it till 2 sec. So, total lines = 2048. The fft then > showed major peak(0.5 magnitude) at 2 Hz with other higher frequencies > present. > > All articles on zero padding say that, zero padding does not add more > information but just makes existing information more fine. Going by that, > the fft in second case should also have shown peak at 1 Hz. May I know > where did I go wrong? > > In Summary, should there be a difference in the usual sine wave and zero > padded sine wave with respect to frequency spectrum? > > Thanks > > Rahul
Rahul, It seems that you misinterpreted the results. when you zero padded, you zero padded at the original sampling rate itself. so now you have 2048 points at your original sampling rate and when you took the FFT the bin at which you got the maximum power would now be twice the original bin. since you did the FFT using 2N points instead of the original N points,the actual freqeuency = new bin location*fs/(2N) where fs is the original sampling rate and N is the original number of points which in your case, is 1024. since the new bin location, is at twice the original bin location, the actual frequency is still 1 Hz. Hope this helps. regards suren
On Feb 5, 8:03&#4294967295;am, "rsk" <kalera...@yahoo.com> wrote:
> All > > This might have been discussed multiple times. However, I am new comer to > the site. > > My question is given below. I wanted to put plots but could not find the > way to do it. > > I took a sine curve from 0-1 s( 1Hz)and 'fft'ed it in MATLAB. I get unit > magnitude at 1 Hz as expected. Sampling rate 1024. > > Then I zero padded it till 2 sec. So, total lines = 2048. The fft then > showed major peak(0.5 magnitude) at 2 Hz with other higher frequencies > present. > > All articles on zero padding say that, zero padding does not add more > information but just makes existing information more fine. Going by that, > the fft in second case should also have shown peak at 1 Hz. May I know > where did I go wrong? > > In Summary, should there be a difference in the usual sine wave and zero > padded sine wave with respect to frequency spectrum?
Yes. You have doubled the number of samples, and multiplied your sine wave with a rectangular window formed by the zero padding. Since the period of your sine wave is now half the number of total samples, the frequency is doubled. And multiplication by a rectangular window in the time domain will convolve the frequency domain result with a (pair of) Sinc function, which is the transform of the rectangular window. The Sinc function has high frequency components across the entire spectrum. -- rhn A.T nicholson d.0.t C-o-M http://www.nicholson.com/rhn/dsp.html
>rsk wrote: >> All >> >> This might have been discussed multiple times. However, I am new comer
to
>> the site. >> >> My question is given below. I wanted to put plots but could not find
the
>> way to do it. >> >> >> >> I took a sine curve from 0-1 s( 1Hz)and 'fft'ed it in MATLAB. I get
unit
>> magnitude at 1 Hz as expected. Sampling rate 1024. >> >> Then I zero padded it till 2 sec. So, total lines = 2048. The fft then >> showed major peak(0.5 magnitude) at 2 Hz with other higher frequencies >> present. >> >> All articles on zero padding say that, zero padding does not add more >> information but just makes existing information more fine. Going by
that,
>> the fft in second case should also have shown peak at 1 Hz. May I know >> where did I go wrong? >> >> In Summary, should there be a difference in the usual sine wave and
zero
>> padded sine wave with respect to frequency spectrum? > >You tell us what you intended to do, but I can't analyze your result >without knowing what you actually did. I can guess, though. Have you >misinterpreted the frequencies associated with the bins in the second >case? zero padding will make twice as many bins, so what was 1 Hz before >becomes 0.5 Hz after padding. > >Jerry >-- >Engineering is the art of making what you want from things you can get. >&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; >Thanks for your reply. I am getting little confused with the
interpretation. Philosophically speaking, I think the sine wave and zero padded sine wave are two different signals and hence they should show different spectrum. However, it is commented in many articles that the zero padding adds no more information. My intention was just to check this. And, I am still confused with the outcome. Did you mean, even if I got 0.5 Hz as the frequency, it is actually 1 HZ?. Also, why did the amplitude change? Rahul
On 6 Feb, 11:16, "rsk" <kalera...@yahoo.com> wrote:
> . Philosophically speaking, I think the sine wave and zero > padded sine wave are two different signals and hence they should show > different spectrum. However, it is commented in many articles that the zero > padding adds no more information. My intention was just to check this. And, > I am still confused with the outcome.
You changed the signal in a deterministic way, which means that you didn't learn anything new about whatever process generated the data. In this sense you added no information. But the linear computations work on two different sets of data, which means the outcomes must be different.
> Did you mean, even if I got 0.5 Hz as > the frequency, it is actually 1 HZ?.
What makes you think that there are fixed frequency labels? There aren't. Read up on the basics.
> Also, why did the amplitude change?
Read up on the basics. Rune