LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Zero-padding arrays

Am I missing the easy way here? To zero pad a complex or float array,
do I really need to concatenate 5 subarrays together? (ie the top
"sandwich bread" of zeros, the middle "meat" consisting of zeros on
either side of my original array, and bottom slice of zeros)?

Embedding arrays seems to involve embedding a given 2D array strung-out
as a line vector within the destination array at the input index. Is
there a 2D embed? Or perhaps I'm scared of For loops and arrays!

Thanks in advance,
Helen


--

Helen E. Kourous
Research Engineer - Veridian ERIM International
NO SPAM PLEASE

....and the Grinch with his Grinch feet ice cold in the snow, stood
puzzling and puzzling - how could it be so? ... He puzzled and puzzed
till his puzzler
was sore. Then the Grinch thought of something he
hadn�t before. Maybe Christmas, he thought, doesn�t come from a store.
Maybe Christmas, perhaps, means a little bit more.
0 Kudos
Message 1 of 8
(5,184 Views)
Helen,

I believe an easier way is the replace array subset (in labview 6). With
this method you can replace rows and columns at a time into an array. You
would initially create a single array as large as the final array you write
about below, then use replace array subset to fill in the rows and columns
of data (because you initialized the original array to all zeros) in one
operation. Another benefit is that build array makes copies of all the pieces
to construct the new array (a large waste of memory) where replace does not.
The vi will execute faster also.

If you are using 5.x, then you have to use replace array element which will
not allow for continguous blocks of data, but only 1 element at a time.
This may not be a problem if your data is only available
1 element at a time.
Again, the benefit is not continuously copying the arrays wasting time and
memeory (or re-sizing the array when the new array is bigger than what you
had originally allocated).

I hope this is a help.
jared

"Helen E. Kourous" wrote:
>Am I missing the easy way here? To zero pad a complex or float array,>do
I really need to concatenate 5 subarrays together? (ie the top>"sandwich
bread" of zeros, the middle "meat" consisting of zeros on>either side of
my original array, and bottom slice of zeros)?>>Embedding arrays seems to
involve embedding a given 2D array strung-out>as a line vector within the
destination array at the input index. Is>there a 2D embed? Or perhaps I'm
scared of For loops and arrays!>>Thanks in advance,>Helen>>>-->>Helen E.
Kourous>Research Engineer - Veridian ERIM International>NO SPAM PLEASE>>....and
the Grinch with his Grinch feet ice cold in the snow, stood>puzzling and
puzzling - how could it be so? ... He puzzled a
nd puzzed>till his puzzler
was sore. Then the Grinch thought of something he>hadn�t before. Maybe Christmas,
he thought, doesn�t come from a store.>Maybe Christmas, perhaps, means a
little bit more.>>
0 Kudos
Message 2 of 8
(5,183 Views)
Helen:

If you know the total size of your array in advance, you can create an
array of all zeros using the "intialize array" function, and then
replace a portion of it using the "replace array element" function
inside of a for loop. Use a shift register on the loop and intiialize
it with the array of zeros. Index your array of "meat" at the boundary
of the for loop and feed it into the "element data" input of the
replace function. If your "meat" array is of indeterminate size, your
probably better off using the "build array" function. If you have any
more questions on using the Replace Array Element function, email me.

Max



In article <3A34E688.9C715F4B@erim-int.com>,
"Helen E. Kourous" wrote:
> Am I missing the easy w
ay here? To zero pad a complex or float array,
> do I really need to concatenate 5 subarrays together? (ie the top
> "sandwich bread" of zeros, the middle "meat" consisting of zeros on
> either side of my original array, and bottom slice of zeros)?
>
> Embedding arrays seems to involve embedding a given 2D array strung-
out
> as a line vector within the destination array at the input index. Is
> there a 2D embed? Or perhaps I'm scared of For loops and arrays!
>
> Thanks in advance,
> Helen
>
> --
>
> Helen E. Kourous
> Research Engineer - Veridian ERIM International
> NO SPAM PLEASE
>
> ...and the Grinch with his Grinch feet ice cold in the snow, stood
> puzzling and puzzling - how could it be so? ... He puzzled and puzzed
> till his puzzler was sore. Then the Grinch thought of something he
> hadn�t before. Maybe Christmas, he thought, doesn�t come from a store.
> Maybe Christmas, perhaps, means a little bit more.
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 3 of 8
(5,183 Views)
Helen:

Another technique would be to append an initialized array of zeros to the
array of points you want to zero pad. Use a length N array of zeros where N
is the total number of zeros you want to pad (both sides of the sandwich).
You now have an array that has the original signal with N following zeros.
If you now use the Rotate 1D Array VI (on the array palette) to rotate the
array by the number of elements that you want to pad on the beginning of
the array.

Sam Shearman
Product Manager, Signal Processing & Analysis Software
National Instruments

greenman_11_11@my-deja.com wrote in <915d3v$dp8$1@nnrp1.deja.com>:

>Helen:
>
>If you know the total size of your array in advance, you can create an
>array of all zeros using the "intialize array" function, and then
>replace a portion of it using the "replace array element" function
>inside of a for loop. Use a shift register on the loop and intiialize
>it with the array of zeros. Index your array of "meat" at the boundary
>of the for loop and feed it into the "element data" input of the
>replace function. If your "meat" array is of indeterminate size, your
>probably better off using the "build array" function. If you have any
>more questions on using the Replace Array Element function, email me.
>
>Max
>
>
>
>In article <3A34E688.9C715F4B@erim-int.com>,
> "Helen E. Kourous" wrote:
>> Am I missing the easy way here? To zero pad a complex or float array,
>> do I really need to concatenate 5 subarrays together? (ie the top
>> "sandwich bread" of zeros, the middle "meat" consisting of zeros on
>> either side of my original array, and bottom slice of zeros)?
>>
>> Embedding arrays seems to involve embedding a given 2D array strung-
>out
>> as a line vector within the destination array at the input index. Is
>> there a 2D embed? Or perhaps I'm scared of For loops and arrays!
>>
>> Thanks in advance,
>> Helen
>>
>> --
>>
>> Helen E. Kourous
>> Research Engineer - Veridian ERIM International
>> NO SPAM PLEASE
>>
>> ...and the Grinch with his Grinch feet ice cold in the snow, stood
>> puzzling and puzzling - how could it be so? ... He puzzled and puzzed
>> till his puzzler was sore. Then the Grinch thought of something he
>> hadn�t before. Maybe Christmas, he thought, doesn�t come from a store.
>> Maybe Christmas, perhaps, means a little bit more.
>>
>>
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
Message 4 of 8
(5,183 Views)
Thanks to everyone - I should have specified I have a 2D array. Not only do I
have to pad on either side, but I have to add slices of "bread" zeros on top
and bottom. (in fact I found a ZeroPad vi in Signal Processing which appends
zeros to a 1D array to the next highest power of 2...).

Looks like I'll stick to my 5-step approach... althought I could do the "meat"
part with a for loop as you say.

Hmmm! A one-liner in matlab! Oh well...

Sam Shearman wrote:

> Helen:
>
> Another technique would be to append an initialized array of zeros to the
> array of points you want to zero pad. Use a length N array of zeros where N
> is the total number of zeros you want to pad (both sides of the sandwich).
> You now have an array that has the original signal with N following zeros.
> If you now use the Rotate 1D Array VI (on the array palette) to rotate the
> array by the number of elements that you want to pad on the beginning of
> the array.
>
> Sam Shearman
> Product Manager, Signal Processing & Analysis Software
> National Instruments
>
> greenman_11_11@my-deja.com wrote in <915d3v$dp8$1@nnrp1.deja.com>:
>
> >Helen:
> >
> >If you know the total size of your array in advance, you can create an
> >array of all zeros using the "intialize array" function, and then
> >replace a portion of it using the "replace array element" function
> >inside of a for loop. Use a shift register on the loop and intiialize
> >it with the array of zeros. Index your array of "meat" at the boundary
> >of the for loop and feed it into the "element data" input of the
> >replace function. If your "meat" array is of indeterminate size, your
> >probably better off using the "build array" function. If you have any
> >more questions on using the Replace Array Element function, email me.
> >
> >Max
> >
> >
> >
> >In article <3A34E688.9C715F4B@erim-int.com>,
> > "Helen E. Kourous" wrote:
> >> Am I missing the easy way here? To zero pad a complex or float array,
> >> do I really need to concatenate 5 subarrays together? (ie the top
> >> "sandwich bread" of zeros, the middle "meat" consisting of zeros on
> >> either side of my original array, and bottom slice of zeros)?
> >>
> >> Embedding arrays seems to involve embedding a given 2D array strung-
> >out
> >> as a line vector within the destination array at the input index. Is
> >> there a 2D embed? Or perhaps I'm scared of For loops and arrays!
> >>
> >> Thanks in advance,
> >> Helen
> >>
> >> --
> >>
> >> Helen E. Kourous
> >> Research Engineer - Veridian ERIM International
> >> NO SPAM PLEASE
> >>
> >> ...and the Grinch with his Grinch feet ice cold in the snow, stood
> >> puzzling and puzzling - how could it be so? ... He puzzled and puzzed
> >> till his puzzler was sore. Then the Grinch thought of something he
> >> hadn�t before. Maybe Christmas, he thought, doesn�t come from a store.
> >> Maybe Christmas, perhaps, means a little bit more.
> >>
> >>
> >
> >
> >Sent via Deja.com http://www.deja.com/
> >Before you buy.

--

Helen E. Kourous
Research Engineer - Veridian ERIM International


....and the Grinch with his Grinch feet ice cold in the snow, stood puzzling and
puzzling - how could it be so? ... He puzzled and puzzed till his puzzler was
sore. Then the Grinch thought of something he hadn�t before. Maybe Christmas,
he thought, doesn�t come from a store. Maybe Christmas, perhaps, means a little
bit more.
0 Kudos
Message 5 of 8
(5,181 Views)
Have a look at the new LV6i array primitives: Insert into array, and:
replace array subset.
They both will solve your problem, I think. Just insert/replace your array
into a 2D array of zeroes.
Have fun

Helen E. Kourous wrote in message
news:3A37824F.AB84A575@erim-int.com...
> Thanks to everyone - I should have specified I have a 2D array. Not only
do I
> have to pad on either side, but I have to add slices of "bread" zeros on
top
> and bottom. (in fact I found a ZeroPad vi in Signal Processing which
appends
> zeros to a 1D array to the next highest power of 2...).
>
> Looks like I'll stick to my 5-step approach... althought I could do the
"meat"
> part with a for loop as you say.
>
> Hmmm! A one-liner in matlab! Oh well...
>
> Sam Shearman wrote:
>
> > Helen:
> >
> > Another technique would be to append an initialized array of zeros to
the
> > array of points you want to zero pad. Use a length N array of zeros
where N
> > is the total number of zeros you want to pad (both sides of the
sandwich).
> > You now have an array that has the original signal with N following
zeros.
> > If you now use the Rotate 1D Array VI (on the array palette) to rotate
the
> > array by the number of elements that you want to pad on the beginning of
> > the array.
> >
> > Sam Shearman
> > Product Manager, Signal Processing & Analysis Software
> > National Instruments
> >
> > greenman_11_11@my-deja.com wrote in <915d3v$dp8$1@nnrp1.deja.com>:
> >
> > >Helen:
> > >
> > >If you know the total size of your array in advance, you can create an
> > >array of all zeros using the "intialize array" function, and then
> > >replace a portion of it using the "replace array element" function
> > >inside of a for loop. Use a shift register on the loop and intiialize
> > >it with the array of zeros. Index your array of "meat" at the boundary
> > >of the for loop and feed it into the "element data" input of the
> > >replace function. If your "meat" array is of indeterminate size, your
> > >probably better off using the "build array" function. If you have any
> > >more questions on using the Replace Array Element function, email me.
> > >
> > >Max
> > >
> > >
> > >
> > >In article <3A34E688.9C715F4B@erim-int.com>,
> > > "Helen E. Kourous" wrote:
> > >> Am I missing the easy way here? To zero pad a complex or float
array,
> > >> do I really need to concatenate 5 subarrays together? (ie the top
> > >> "sandwich bread" of zeros, the middle "meat" consisting of zeros on
> > >> either side of my original array, and bottom slice of zeros)?
> > >>
> > >> Embedding arrays seems to involve embedding a given 2D array strung-
> > >out
> > >> as a line vector within the destination array at the input index. Is
> > >> there a 2D embed? Or perhaps I'm scared of For loops and arrays!
> > >>
> > >> Thanks in advance,
> > >> Helen
> > >>
> > >> --
> > >>
> > >> Helen E. Kourous
> > >> Research Engineer - Veridian ERIM International
> > >> NO SPAM PLEASE
> > >>
> > >> ...and the Grinch with his Grinch feet ice cold in the snow, stood
> > >> puzzling and puzzling - how could it be so? ... He puzzled and puzzed
> > >> till his puzzler was sore. Then the Grinch thought of something he
> > >> hadn't before. Maybe Christmas, he thought, doesn't come from a
store.
> > >> Maybe Christmas, perhaps, means a little bit more.
> > >>
> > >>
> > >
> > >
> > >Sent via Deja.com http://www.deja.com/
> > >Before you buy.
>
> --
>
> Helen E. Kourous
> Research Engineer - Veridian ERIM International
>
>
> ...and the Grinch with his Grinch feet ice cold in the snow, stood
puzzling and
> puzzling - how could it be so? ... He puzzled and puzzed till his puzzler
was
> sore. Then the Grinch thought of something he hadn't before. Maybe
Christmas,
> he thought, doesn't come from a store. Maybe Christmas, perhaps, means a
little
> bit more.
>
>
0 Kudos
Message 6 of 8
(5,179 Views)
That's what I meant when I said the "insert into array" just strings my first
array out into a VECTOR then inserts at the specified index. Hmm. Maybe I'm
doing something wrong, or should try it within a FOR loop...
I'll look at it. Thanks!

henk hessel wrote:

> Have a look at the new LV6i array primitives: Insert into array, and:
> replace array subset.
> They both will solve your problem, I think. Just insert/replace your array
> into a 2D array of zeroes.
> Have fun
>
> Helen E. Kourous wrote in message
> news:3A37824F.AB84A575@erim-int.com...
> > Thanks to everyone - I should have specified I have a 2D array. Not only
> do I
> > have to pad on either side, but I have to add slices of "bread" zeros on
> top
> > and bottom. (in fact I found a ZeroPad vi in Signal Processing which
> appends
> > zeros to a 1D array to the next highest power of 2...).
> >
> > Looks like I'll stick to my 5-step approach... althought I could do the
> "meat"
> > part with a for loop as you say.
> >
> > Hmmm! A one-liner in matlab! Oh well...
> >
> > Sam Shearman wrote:
> >
> > > Helen:
> > >
> > > Another technique would be to append an initialized array of zeros to
> the
> > > array of points you want to zero pad. Use a length N array of zeros
> where N
> > > is the total number of zeros you want to pad (both sides of the
> sandwich).
> > > You now have an array that has the original signal with N following
> zeros.
> > > If you now use the Rotate 1D Array VI (on the array palette) to rotate
> the
> > > array by the number of elements that you want to pad on the beginning of
> > > the array.
> > >
> > > Sam Shearman
> > > Product Manager, Signal Processing & Analysis Software
> > > National Instruments
> > >
> > > greenman_11_11@my-deja.com wrote in <915d3v$dp8$1@nnrp1.deja.com>:
> > >
> > > >Helen:
> > > >
> > > >If you know the total size of your array in advance, you can create an
> > > >array of all zeros using the "intialize array" function, and then
> > > >replace a portion of it using the "replace array element" function
> > > >inside of a for loop. Use a shift register on the loop and intiialize
> > > >it with the array of zeros. Index your array of "meat" at the boundary
> > > >of the for loop and feed it into the "element data" input of the
> > > >replace function. If your "meat" array is of indeterminate size, your
> > > >probably better off using the "build array" function. If you have any
> > > >more questions on using the Replace Array Element function, email me.
> > > >
> > > >Max
> > > >
> > > >
> > > >
> > > >In article <3A34E688.9C715F4B@erim-int.com>,
> > > > "Helen E. Kourous" wrote:
> > > >> Am I missing the easy way here? To zero pad a complex or float
> array,
> > > >> do I really need to concatenate 5 subarrays together? (ie the top
> > > >> "sandwich bread" of zeros, the middle "meat" consisting of zeros on
> > > >> either side of my original array, and bottom slice of zeros)?
> > > >>
> > > >> Embedding arrays seems to involve embedding a given 2D array strung-
> > > >out
> > > >> as a line vector within the destination array at the input index. Is
> > > >> there a 2D embed? Or perhaps I'm scared of For loops and arrays!
> > > >>
> > > >> Thanks in advance,
> > > >> Helen
> > > >>
> > > >> --
> > > >>
> > > >> Helen E. Kourous
> > > >> Research Engineer - Veridian ERIM International
> > > >> NO SPAM PLEASE
> > > >>
> > > >> ...and the Grinch with his Grinch feet ice cold in the snow, stood
> > > >> puzzling and puzzling - how could it be so? ... He puzzled and puzzed
> > > >> till his puzzler was sore. Then the Grinch thought of something he
> > > >> hadn't before. Maybe Christmas, he thought, doesn't come from a
> store.
> > > >> Maybe Christmas, perhaps, means a little bit more.
> > > >>
> > > >>
> > > >
> > > >
> > > >Sent via Deja.com http://www.deja.com/
> > > >Before you buy.
> >
> > --
> >
> > Helen E. Kourous
> > Research Engineer - Veridian ERIM International
> >
> >
> > ...and the Grinch with his Grinch feet ice cold in the snow, stood
> puzzling and
> > puzzling - how could it be so? ... He puzzled and puzzed till his puzzler
> was
> > sore. Then the Grinch thought of something he hadn't before. Maybe
> Christmas,
> > he thought, doesn't come from a store. Maybe Christmas, perhaps, means a
> little
> > bit more.
> >
> >

--

Helen E. Kourous
Research Engineer - Veridian ERIM International
PH (734) 994 1200 x2941 (FAX 5124)
http://www.erim-int.com/

....and the Grinch with his Grinch feet ice cold in the snow, stood puzzling and
puzzling - how could it be so? ... He puzzled and puzzed till his puzzler was
sore. Then the Grinch thought of something he hadn�t before. Maybe Christmas, he
thought, doesn�t come from a store. Maybe Christmas, perhaps, means a little bit
more.
0 Kudos
Message 7 of 8
(5,175 Views)
Helen,

I think you may be using insert into array when you should be using replace
array subset. This second method will automatically resize it's inputs if
you wire a 2d array to it. then you just need to give it the size and offset
of both dimensions and it will insert your data into a zero initialized array
right where you want it. In one operation.

Jared

"Helen E. Kourous" wrote:
>That's what I meant when I said the "insert into array" just strings my
first>array out into a VECTOR then inserts at the specified index. Hmm. Maybe
I'm>doing something wrong, or should try it within a FOR loop...>I'll look
at it. Thanks!>>henk hessel wrote:>>> Have a look at the new LV6i array primitives:
Insert into array, and:>> replace array subset.>> They both will solve your
problem, I think. Just insert/replace your array>> into a 2D array of zeroes.>>
Have fun>>>> Helen E. Kourous wrote in message>>
news:3A37824F.AB84A575@erim-int.com...>> > Thanks to everyone - I should
have specified I have a 2D array. Not only>> do I>> > have to pad on either
side, but I have to add slices of "bread" zeros on>> top>> > and bottom.
(in fact I found a ZeroPad vi in Signal Processing which>> appends>> > zeros
to a 1D array to the next highest power of 2...).>> >>> > Looks like I'll
stick to my 5-step approach... althought I could do the>> "meat">> > part
with a for loop as you say.>> >>> > Hmmm! A one-liner in matlab! Oh well...>>
>>> > Sam Shearman wrote:>> >>> > > Helen:>> > >>> > > Another technique
would be to append an initialized array of zeros to>> the>> > > array of
points you want to zero pad. Use a length N array of zeros>> where N>> >
> is the total number of zeros you want to pad (both sides of the>> sandwich).>>
> > You now have an array that has the original signal with N following>>
zeros.>> > > If you now use the Rotate 1D Array VI (on the array palette)
to rotate>> the>> > > array by the number of elements that you want to pad
on the beginning of>> > > the array.>> > >>> > > Sam Shearman>> > > Product
Manager, Signal Processing & Analysis Software>> > > National Instruments>>
> >>> > > greenman_11_11@my-deja.com wrote in <915d3v$dp8$1@nnrp1.deja.com>:>>
> >>> > > >Helen:>> > > >>> > > >If you know the total size of your array
in advance, you can create an>> > > >array of all zeros using the "intialize
array" function, and then>> > > >replace a portion of it using the "replace
array element" function>> > > >inside of a for loop. Use a shift register
on the loop and intiialize>> > > >it with the array of zeros. Index your
array of "meat" at the boundary>> > > >of the for loop and feed it into the
"element data" input of the>> > > >replace function. If your "meat" array
is of indeterminate size, your>> > > >probably better off using the "build
array" function. If you have any>> > > >more questions on using the Replace
Array Element function, email me.>> > > >>> > > >Max>> > > >>> > > >>> >
> >>> > > >In article <3A34E688.9C715F4B@erim-int.com>,>> > > > "Helen E.
Kourous" wrote:>> > > >> Am I missing the easy way
here? To zero pad a complex or float>> array,>> > > >> do I really need
to concatenate 5 subarrays together? (ie the top>> > > >> "sandwich bread"
of zeros, the middle "meat" consisting of zeros on>> > > >> either side of
my original array, and bottom slice of zeros)?>> > > >>>> > > >> Embedding
arrays seems to involve embedding a given 2D array strung->> > > >out>> >
> >> as a line vector within the destination array at the input index. Is>>
> > >> there a 2D embed? Or perhaps I'm scared of For loops and arrays!>>
> > >>>> > > >> Thanks in advance,>> > > >> Helen>> > > >>>> > > >> -->>
> > >>>> > > >> Helen E. Kourous>> > > >> Research Engineer - Veridian ERIM
International>> > > >> NO SPAM PLEASE>> > > >>>> > > >> ...and the Grinch
with his Grinch feet ice cold in the snow, stood>> > > >> puzzling and puzzling
- how could it be so? ... He puzzled and puzzed>> > > >> till his puzzler
was sore. Then the Grinch thought of something he>> > > >> hadn't before.
Maybe Christmas, he thought, doesn't come from a>> store.>> > > >> Maybe
Christmas, perhaps, means a little bit more.>> > > >>>> > > >>>> > > >>>
> > >>> > > >Sent via Deja.com http://www.deja.com/>> > > >Before you buy.>>
>>> > -->> >>> > Helen E. Kourous>> > Research Engineer - Veridian ERIM
International>> >>> >>> > ...and the Grinch with his Grinch feet ice cold
in the snow, stood>> puzzling and>> > puzzling - how could it be so? ...
He puzzled and puzzed till his puzzler>> was>> > sore. Then the Grinch thought
of something he hadn't before. Maybe>> Christmas,>> > he thought, doesn't
come from a store. Maybe Christmas, perhaps, means a>> little>> > bit more.>>
>>> >>>-->>Helen E. Kourous>Research Engineer - Veridian ERIM International>PH
(734) 994 1200 x2941 (FAX 5124)>http://www.erim-int.com/>>....and the Grinch
with his Grinch feet ice cold in the snow, stood puzzling and>puzzling -
how could it be so? ... He puzzled and puzzed till his puzzler was>sore.
Then the Grinch thought of something he hadn�t before. Maybe Christmas, he>thought,
doesn�t come from a store. Maybe Christmas, perhaps, means a little bit>more.>>
0 Kudos
Message 8 of 8
(5,172 Views)