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:
add zeros between every 512 elements

Subject: add zeros between every 512 elements

From: Haitham Tahbub

Date: 2 Jun, 2010 22:23:06

Message: 1 of 3

i have a vector of size 20000 X 1 of 20000 elements inside

i want to add 512 zeros between every 512 elements

so after the first 512 elements i want to add 512 zeros and then the second 512 elements in the signal and then 512 zeros and so on till the end of the signal so the signal will be of length 40000

i used this function

xr = reshape([x zeros(length(x),512)]',513*length(x),1)

but this function add 512 zeros between every two elements and the produced signal will be of length 513 *20000 = 10260000 elements !!!!!

ANy SOlutions ????
please Reply if you can help me
Regards
Haitham

Subject: add zeros between every 512 elements

From: Walter Roberson

Date: 2 Jun, 2010 22:26:03

Message: 2 of 3

Haitham Tahbub wrote:
> i have a vector of size 20000 X 1 of 20000 elements inside
>
> i want to add 512 zeros between every 512 elements
> so after the first 512 elements i want to add 512 zeros and then the
> second 512 elements in the signal and then 512 zeros and so on till the
> end of the signal so the signal will be of length 40000


T = reshape(x, 512, []);
xr = reshape([T, zeros(size(T))], [], 1);

Subject: add zeros between every 512 elements

From: Roger Stafford

Date: 3 Jun, 2010 04:14:04

Message: 3 of 3

"Haitham Tahbub" <the_mummy_n1@hotmail.com> wrote in message <hu6lka$oc7$1@fred.mathworks.com>...
> i have a vector of size 20000 X 1 of 20000 elements inside
>
> i want to add 512 zeros between every 512 elements
>
> so after the first 512 elements i want to add 512 zeros and then the second 512 elements in the signal and then 512 zeros and so on till the end of the signal so the signal will be of length 40000
>
> i used this function
>
> xr = reshape([x zeros(length(x),512)]',513*length(x),1)
>
> but this function add 512 zeros between every two elements and the produced signal will be of length 513 *20000 = 10260000 elements !!!!!
>
> ANy SOlutions ????
> please Reply if you can help me
> Regards
> Haitham

  Haitham, your arithmetic seems a bit faulty. The number 20000 is not divisible by 512, so after inserting 39 sets of 512 zeros, there will be 32 more left over from the original vector, and this would give you a total length of 20000+39*512 = 39968 elements, not 40000. Is that the result you want?

  If so, calling the original vector x,

 n = floor(20000/512);
 xr = [reshape([reshape(x(1:512*n),512,n);zeros(512,n)],[],1);x(512*n+1:end)];

Roger Stafford

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