Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Use of arrays as buffers

Hi there,
 
I am just writing to this forum to see if anyone can help me out here.
 
I am trying to implement the following algorithm,
 
The input waveform say is a 4Hz sine wave, then I want to sample this at 32 times a second and write the first 128 samples to array0 then the second 128 samples to array1 then the third lot of samples to array0 and so on. In this way I can keep the last 128 samples of the incoming signal in memory. Finally whilst sampling and writing the data to the array I want to output the current reading minus the old reading, That is whilst reading in sample 1 to array 0 I want to output array0 sample 1 - array1 sample1 and so on until all 128 samples are done. So to summarize only the incoming sine signal is ever written to the buffers the difference signal is output.
 
1. Write signal to array0, output array0 - array1  
2. Write signal to array1, output array1 - array0, (currentreading -oldreading)
3. Write signal to array0, output array0 - array1, (currentreading -oldreading)
4. Write signal to array1, output array1 - array0, (currentreading -oldreading)
and so on
 
Anybody done anything similar like this before in Labview 8.2, or any advice greatly appreciated.
 
Best regards
 
Javed
 
0 Kudos
Message 1 of 4
(3,052 Views)

This sounds like a good place for a simple functional global that uses an uninitialized shift register.  Search the site for those terms and you should find lots of info and some examples.

A shift register works like a local variable for a loop.  The one on the left holds the value prior to a loop iteration and the one on the right should be wired with the value to be held at the end of an iteration.  Whatever you wire to the right on one iteration is what will come out from the left on the next iteration.  An "unitialized" shift register is one where no value is wired from outside the loop to the left-side shift register.  Such a beast will remember its shift register values from one function call to the next.  This is the LabVIEW method for creating the equivalent of a C static variable.

Your main program would call this functional global and pass in the most recent 128 samples.  Inside the functional global, the input array will be wired to a right-hand-side shift register.  Also inside the functional global, the value coming out of the left-hand-side shift register (which is the array you passed in on the previous call) will be subtracted from your input array.  Pass the difference out to an output terminal.  Voila!

Here's an extremely simple example.  I would recommend you consider adding some logic to verify that the arrays are equally-sized before subtracting them.  You may have other checks you'd like to do too, but this illustrates the bare-bones of the solution.

-Kevin P.

 

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Download All
Message 2 of 4
(3,039 Views)

Ok,

I managed to implement the algorthim in Labview using the Subtract routine mentioned and using local variables.

 

All was working well for a while I was charting both the raw signal and the subtracted signal fine, from a USB-6009 device the sampling rate was 64 and the number of samples was 256. The arrays I have defined and the for loop I have indexed run from 0 to 255 BUT now I am suddenly having performance issues in running this VI. On completion of the For loop the VI stops freezes for a few seconds before continuing on the next For loop run. I am at a loss as to why the VI has suddenly started behaving this way.

Any help greatly appreciated.

 

Best regards

 

Javed

0 Kudos
Message 3 of 4
(3,010 Views)
Would you want something like the attached?  The old values are kept in a shift register so they can be subtracted from the new values next time through the loop.
Randall Pursley
0 Kudos
Message 4 of 4
(3,000 Views)