Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
To zero pad a signal using MATLAB

Subject: To zero pad a signal using MATLAB

From: Malcom Smith

Date: 25 May, 2009 14:24:01

Message: 1 of 9

Hi there,

I'm trying to extend the following data set to 512 points by zero padding:

x(t)=100sin(2*pi*100*t)+2sin(2*pi*184.25*t)+randn(size(t)) where the sampling frequency is 1 kHz and 64 samples are available.

Could you please provide me a code for implementing the zero padding and also plotting the resultant signal?

Many thanks in advance.

Subject: To zero pad a signal using MATLAB

From: Matt

Date: 25 May, 2009 14:35:02

Message: 2 of 9

"Malcom Smith" <jreal_kko@yahoo.com> wrote in message <gve9m1$n8d$1@fred.mathworks.com>...
> Hi there,
>
> I'm trying to extend the following data set to 512 points by zero padding:
>
> x(t)=100sin(2*pi*100*t)+2sin(2*pi*184.25*t)+randn(size(t)) where the sampling frequency is 1 kHz and 64 samples are available.
>
> Could you please provide me a code for implementing the zero padding and also plotting the resultant signal?
>
> Many thanks in advance.

No. I don't think I will.

Subject: To zero pad a signal using MATLAB

From: Sadik

Date: 25 May, 2009 15:23:01

Message: 3 of 9

Your t could be

t = 0:0.001:0.063

so that your sampling frequency will be 1KHz and you will have 64 samples.

Your signal will then be

x = 100*sin(2*pi*100*t)+2*sin(2*pi*184.25*t)+randn(size(t));

The zero padded signal will be

xZeroPadded = [x zeros(1,512-64)];

Then, you can plot your signal by

plot(t,x)

and

plot(0:0.001:0.512,xZeroPadded)





"Malcom Smith" <jreal_kko@yahoo.com> wrote in message <gve9m1$n8d$1@fred.mathworks.com>...
> Hi there,
>
> I'm trying to extend the following data set to 512 points by zero padding:
>
> x(t)=100sin(2*pi*100*t)+2sin(2*pi*184.25*t)+randn(size(t)) where the sampling frequency is 1 kHz and 64 samples are available.
>
> Could you please provide me a code for implementing the zero padding and also plotting the resultant signal?
>
> Many thanks in advance.

Subject: To zero pad a signal using MATLAB

From: Malcom Smith

Date: 25 May, 2009 15:25:04

Message: 4 of 9

"Malcom Smith" <jreal_kko@yahoo.com> wrote in message <gve9m1$n8d$1@fred.mathworks.com>...
> Hi there,
>
> I'm trying to extend the following data set to 512 points by zero padding:
>
> x(t)=100sin(2*pi*100*t)+2sin(2*pi*184.25*t)+randn(size(t)) where the sampling frequency is 1 kHz and 64 samples are available.
>
> Could you please provide me a code for implementing the zero padding and also plotting the resultant signal?
>
> Many thanks in advance.

Please find below the code I have tried (I'm simply not getting the output I need):

figure(10)
subplot(1,2,1);
f1=100;
f2=184.25;
fs=1000;
t1=0;
tstep=(1/fs);
t2=63/fs;
t=[t1:tstep:t2];
x=100*sin(2*pi*f1*t)+2*sin(2*pi*f2*t)+randn(size(t));
y=[x, zeros(1,(511*tstep))];
plot([t z],y);
subplot(1,2,2);
Pxx=periodogram(x);
Hpsd = dspdata.psd(Pxx, 'fs',fs);
plot(Hpsd);
datacursormode on

Could someone (other than Matt-xys@whatever.com) please help me on this.

Many thanks in advance.

Subject: To zero pad a signal using MATLAB

From: Sadik

Date: 25 May, 2009 15:33:02

Message: 5 of 9

Hey Malcom,

The function zeros gets integer inputs only.

The line

y=[x, zeros(1,(511*tstep))];

is problematic. You should say

y = [x,zeros(1,512-64)];

or equivalently,

y = [x,zeros(1,448)];

Please let me know if this works.


"Malcom Smith" <jreal_kko@yahoo.com> wrote in message <gved8f$4p5$1@fred.mathworks.com>...
> "Malcom Smith" <jreal_kko@yahoo.com> wrote in message <gve9m1$n8d$1@fred.mathworks.com>...
> > Hi there,
> >
> > I'm trying to extend the following data set to 512 points by zero padding:
> >
> > x(t)=100sin(2*pi*100*t)+2sin(2*pi*184.25*t)+randn(size(t)) where the sampling frequency is 1 kHz and 64 samples are available.
> >
> > Could you please provide me a code for implementing the zero padding and also plotting the resultant signal?
> >
> > Many thanks in advance.
>
> Please find below the code I have tried (I'm simply not getting the output I need):
>
> figure(10)
> subplot(1,2,1);
> f1=100;
> f2=184.25;
> fs=1000;
> t1=0;
> tstep=(1/fs);
> t2=63/fs;
> t=[t1:tstep:t2];
> x=100*sin(2*pi*f1*t)+2*sin(2*pi*f2*t)+randn(size(t));
> y=[x, zeros(1,(511*tstep))];
> plot([t z],y);
> subplot(1,2,2);
> Pxx=periodogram(x);
> Hpsd = dspdata.psd(Pxx, 'fs',fs);
> plot(Hpsd);
> datacursormode on
>
> Could someone (other than Matt-xys@whatever.com) please help me on this.
>
> Many thanks in advance.

Subject: To zero pad a signal using MATLAB

From: Sadik

Date: 25 May, 2009 15:36:01

Message: 6 of 9

What is z by the way in

plot([t z],...

I believe you had better write like this as I wrote just before your reply:

plot(0:0.001:0.512,...

in that line.



"Malcom Smith" <jreal_kko@yahoo.com> wrote in message <gved8f$4p5$1@fred.mathworks.com>...
> "Malcom Smith" <jreal_kko@yahoo.com> wrote in message <gve9m1$n8d$1@fred.mathworks.com>...
> > Hi there,
> >
> > I'm trying to extend the following data set to 512 points by zero padding:
> >
> > x(t)=100sin(2*pi*100*t)+2sin(2*pi*184.25*t)+randn(size(t)) where the sampling frequency is 1 kHz and 64 samples are available.
> >
> > Could you please provide me a code for implementing the zero padding and also plotting the resultant signal?
> >
> > Many thanks in advance.
>
> Please find below the code I have tried (I'm simply not getting the output I need):
>
> figure(10)
> subplot(1,2,1);
> f1=100;
> f2=184.25;
> fs=1000;
> t1=0;
> tstep=(1/fs);
> t2=63/fs;
> t=[t1:tstep:t2];
> x=100*sin(2*pi*f1*t)+2*sin(2*pi*f2*t)+randn(size(t));
> y=[x, zeros(1,(511*tstep))];
> plot([t z],y);
> subplot(1,2,2);
> Pxx=periodogram(x);
> Hpsd = dspdata.psd(Pxx, 'fs',fs);
> plot(Hpsd);
> datacursormode on
>
> Could someone (other than Matt-xys@whatever.com) please help me on this.
>
> Many thanks in advance.

Subject: To zero pad a signal using MATLAB

From: Sadik

Date: 25 May, 2009 15:43:01

Message: 7 of 9

I am sorry, it should have been

plot(0:0.001:0.511,...





"Sadik " <sadik.hava@gmail.com> wrote in message <gvedt1$f17$1@fred.mathworks.com>...
> What is z by the way in
>
> plot([t z],...
>
> I believe you had better write like this as I wrote just before your reply:
>
> plot(0:0.001:0.512,...
>
> in that line.
>
>
>
> "Malcom Smith" <jreal_kko@yahoo.com> wrote in message <gved8f$4p5$1@fred.mathworks.com>...
> > "Malcom Smith" <jreal_kko@yahoo.com> wrote in message <gve9m1$n8d$1@fred.mathworks.com>...
> > > Hi there,
> > >
> > > I'm trying to extend the following data set to 512 points by zero padding:
> > >
> > > x(t)=100sin(2*pi*100*t)+2sin(2*pi*184.25*t)+randn(size(t)) where the sampling frequency is 1 kHz and 64 samples are available.
> > >
> > > Could you please provide me a code for implementing the zero padding and also plotting the resultant signal?
> > >
> > > Many thanks in advance.
> >
> > Please find below the code I have tried (I'm simply not getting the output I need):
> >
> > figure(10)
> > subplot(1,2,1);
> > f1=100;
> > f2=184.25;
> > fs=1000;
> > t1=0;
> > tstep=(1/fs);
> > t2=63/fs;
> > t=[t1:tstep:t2];
> > x=100*sin(2*pi*f1*t)+2*sin(2*pi*f2*t)+randn(size(t));
> > y=[x, zeros(1,(511*tstep))];
> > plot([t z],y);
> > subplot(1,2,2);
> > Pxx=periodogram(x);
> > Hpsd = dspdata.psd(Pxx, 'fs',fs);
> > plot(Hpsd);
> > datacursormode on
> >
> > Could someone (other than Matt-xys@whatever.com) please help me on this.
> >
> > Many thanks in advance.

Subject: To zero pad a signal using MATLAB

From: Malcom Smith

Date: 25 May, 2009 18:07:01

Message: 8 of 9

Thanks ever so much, Sadik. It works! I'm very grateful, indeed.


"Sadik " <sadik.hava@gmail.com> wrote in message <gveea5$atj$1@fred.mathworks.com>...
> I am sorry, it should have been
>
> plot(0:0.001:0.511,...
>
>
>
>
>
> "Sadik " <sadik.hava@gmail.com> wrote in message <gvedt1$f17$1@fred.mathworks.com>...
> > What is z by the way in
> >
> > plot([t z],...
> >
> > I believe you had better write like this as I wrote just before your reply:
> >
> > plot(0:0.001:0.512,...
> >
> > in that line.
> >
> >
> >
> > "Malcom Smith" <jreal_kko@yahoo.com> wrote in message <gved8f$4p5$1@fred.mathworks.com>...
> > > "Malcom Smith" <jreal_kko@yahoo.com> wrote in message <gve9m1$n8d$1@fred.mathworks.com>...
> > > > Hi there,
> > > >
> > > > I'm trying to extend the following data set to 512 points by zero padding:
> > > >
> > > > x(t)=100sin(2*pi*100*t)+2sin(2*pi*184.25*t)+randn(size(t)) where the sampling frequency is 1 kHz and 64 samples are available.
> > > >
> > > > Could you please provide me a code for implementing the zero padding and also plotting the resultant signal?
> > > >
> > > > Many thanks in advance.
> > >
> > > Please find below the code I have tried (I'm simply not getting the output I need):
> > >
> > > figure(10)
> > > subplot(1,2,1);
> > > f1=100;
> > > f2=184.25;
> > > fs=1000;
> > > t1=0;
> > > tstep=(1/fs);
> > > t2=63/fs;
> > > t=[t1:tstep:t2];
> > > x=100*sin(2*pi*f1*t)+2*sin(2*pi*f2*t)+randn(size(t));
> > > y=[x, zeros(1,(511*tstep))];
> > > plot([t z],y);
> > > subplot(1,2,2);
> > > Pxx=periodogram(x);
> > > Hpsd = dspdata.psd(Pxx, 'fs',fs);
> > > plot(Hpsd);
> > > datacursormode on
> > >
> > > Could someone (other than Matt-xys@whatever.com) please help me on this.
> > >
> > > Many thanks in advance.

Subject: To zero pad a signal using MATLAB

From: Godzilla

Date: 26 May, 2009 00:42:02

Message: 9 of 9

help padarray

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us