LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

changing array values with the same array

Hi,

I'm very new to vabview, and I'm trying to implement the following,
and I just cant seem to get it to work, any ideas?
Thanks,
Barry.

for (i = 0; i < FL-1; i++)
filter[i] = filter[i+1];
0 Kudos
Message 1 of 8
(3,125 Views)
Hi,
as far as I understand this code is equal to the next 2 operations:
1. delete first element in array
2. add last element of array to the end of array (if FL is the size of array)

to do it you can use such functions from array palette as "Delete from array", and "Build array"

Example is attached.

Good luck.

Oleg Chutko.
0 Kudos
Message 2 of 8
(3,125 Views)
If you don't want to repeat the last element twice you don't have to add this element to the end of array.

In this case you just need to delete the first element.

Oleg Chutko.
0 Kudos
Message 3 of 8
(3,125 Views)
To support the ealier response, implementing your code as it is right now will replace all filter array elements with the 0th element. I'm sure this is not what you want.
0 Kudos
Message 4 of 8
(3,125 Views)
I'm not sure I understand what you want. What is 'FL'? It looks like you
are trying to move each element down one index value. What do you intend to
do with the first and last elements? If you are dropping the first element
then you could use 'delete from array' on the first element and that might
be what you want. If you are intending to put the first element into the
last element you could use rotate array with n=-1. If I've totally
misunderstood your intent please explain further and I'll try to help.

"Barry" wrote in message
news:731cea69.0301130757.2af4061f@posting.google.com...
> Hi,
>
> I'm very new to vabview, and I'm trying to implement the following,
> and I just cant seem to get it to work, any ideas?
> Thanks,
> Barry.
>
> for
(i = 0; i < FL-1; i++)
> filter[i] = filter[i+1];
0 Kudos
Message 5 of 8
(3,125 Views)
Thanks for the reply everyone. I now have that working. I'm still
having some trouble though.

Basically, what I'm trying to do, is implement a filter in labview,
which I have currently working in C.

This is the code I'm trying to implement -

/////////////////////////////////////////////////////////////////

filterInit(1200,filter2,b);
for(i=0;i mix2[i] = filterLP(mix2[i], filter2, b);


// filterLP
double filterLP(double x, double *filter, double *b)
{
double sum= 0.0; int i;
for (i = 0; i < FL-1; i++)
*(filter+i) = *(filter+i+1);
*(filter+FL-1) = x;

for (i = 0; i < FL; i++)
sum += ((*(b+i)) * (*(filter+i)));

return sum;
}
/////////////////////////////////////////////////////////////////

In labview, I now have a filterInit subVI which creates and
initializes the filter array to all zeros, and populates the b array.

I also have a second subVI called filterLP, which implements the
filterLP function coded above in C.

Now my problem is with respect to the these lines of code -

for(i=0;i mix2[i] = filterLP(mix2[i], filter2, b);


For the first iteration of this for loop, I want to use the
initialised filter array (all zeros), i.e. the one coming from my
filterInit subVI. But for all other iterations, I want to use the new
filter array values as they are updated by the filterLP subVI.

To do this, I had the filterLP subVI having an input called filterIn
and an output called filterOut (filter array in and out respectively).
I then thought I could call the filterLP subVI from within a for loop
- feeding the filterOut back into the filterIN. But this isn't
allowed, its a chain.

How might I implement this?

Thanks, and I appreciate your help,

Barry.











Aderogba wrote in message news:<5065000000050000009EC30000-1042324653000@exchange.ni.com>...
> To support the ealier response, implementing your code as it is right
> now will replace all filter array elements with the 0th element. I'm
> sure this is not what you want.
0 Kudos
Message 6 of 8
(3,125 Views)

One way to achieve what you want to do is with control reference. You can read more about this topic here [broken link removed], additional information can be obtained by performing a search for this topic at NI website.

0 Kudos
Message 7 of 8
(3,125 Views)
Barry,

If you want to feed data from one iteration of a loop to the next iteration, then shift registers are your answer. I would suggest reading up on them in the online help for LabVIEW as well as searching for shift registers in the shipping examples. Shift registers are a key to implementing many LabVIEW VIs. If you want more of a strait tutorial, see the LabVIEW tutorial and check out our online training at http://sine.ni.com/apps/ja/niot.ni and look at the Displaying data in charts and graphs topic. It is $95 for 20 days of access. It is a great deal.

Randy Hoskin
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 8 of 8
(3,125 Views)