From: rsk on
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


From: Rune Allnor on
On 5 Feb, 17:03, "rsk" <kalera...(a)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
From: foxcob on
>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

From: robert bristow-johnson on
On Feb 5, 1:38 pm, "foxcob" <jacob.the...(a)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.  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.

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
From: dbd on
On Feb 5, 8:03 am, "rsk" <kalera...(a)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