LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

determining sampling rate and saving frequency waveform data

Solved!
Go to solution

Hi,

 

I am writing a simple program which would collect data from a triaxial accelerometer input, convert it to a frequency spectrum, and then save the time domain and frequency waveforms to a separate external file.  I don't quite understand how to set the sampling rate, though.  On the DAQ Assistant, I set the acquisition mode to "Continuous Samples" and the samples to read is 2k, which is the total number of data points that are collected.  How do I program it collect samples for a certain length of time, 30 seconds, for instance?  Would it be better to set up a trigger, such that it will continue to collect data until I tell it to stop?

 

I would also like to save the waveform data to a separate file which could be easily viewed by other computers that would not have Labview installed.  I currently have the program set up to convert the time domain waveform to a text string and then save it to a text file or spreadsheet.  This works fine, but I also would like to save the frequency waveform, which is a different data type.  How do I do this or is there a better way?

 

My program is attached.  Thanks for your help!

0 Kudos
Message 1 of 7
(11,219 Views)

Hi JMJ09,

 

In Continuous Samples acquisition mode the Samples to Read actually specifies the size of the memory buffer.  In your program, the buffer size is set to 2k samples and you are reading at 20k.  This means you need to read the entire buffer at least every 100 ms in order for previously taken data not to be overwritten.  With the DAQ Assistant VI the DAQmx Acceleration Task is created, ran, and destroyed every iteration of the while loop, which drastically slows down you program.  You will be much better using the DAQmx functions provided in the LabVIEW functions palette in Measurement I/O>>NI-DAQmx.  A great example to get you started is in Help>>Find Examples>>Instrument Input and Output>>DAQmx>>Analog Measurements>>Acceleration>>Cont Acq Accel Samples-Int Clk-Analog Start.vi.  In your case you will need three input channels and probably not the analog start trigger.  Here you can use an Elapsed Time VI wired to the stop terminal to run the acquisition for any amount of time you would like.

 

As far as writing the frequency domain data to a file along with the waveform data, this will be a bit more tricky.  I would continue to write waveform data as you are, then append the frequency data to the file afterwards.  The frequency data can be appended by converting the cluster to a 2d array and writing it with the write to spreadsheet.vi.

 

https://decibel.ni.com/content/docs/DOC-9981

 

I hope this helps!

 

 

Brian

 


Brian G.
Message 2 of 7
(11,199 Views)

Hi Brian,

 

Thanks very much.  Your advice was a tremendous help.  One thing I'm having trouble understanding, though, is timing the loop execution rate with the sampling rate.  I programmed the sample clock to collect continuous samples and I'm using a "Wait until next ms Multiple" VI to control the while loop.  If I set the sampling rate to collect 1000 S/s and set the loop to execute every 100 ms, then I should get 100 samples, roughly, every second.  This is what is being recorded in my external file.  What I don't understand is that I have the program running for 10 seconds, which is indicated by the Elapsed Time VI. So shouldn't the total number of samples be 10x what is being recorded?

 

Also, I seem to be getting an error message with the FFT spectrum vi whenever I run the program more than once without changing any parameters.  The error reads:

 

Warning 1905 occurred at SVT FFT Spectrum (Mag-Phase) (N Ch).vi:1

Possible reason(s):

Sound and Vibration Toolset:  VI automatically was reset because number of samples in the input signal changed.

 

I'm guessing the samples are saved each time the program is run and it doesn't like having to change them each additional time I run it.  Is this hurting anthing?  How can I fix this?

 

My revised program is attached.  Thanks again for your help.

0 Kudos
Message 3 of 7
(11,184 Views)

Hello again,

 

Your program looks very good, but there is one mistake that is only allowing a small part of your data to be written to the output file.  If you are collecting at a rate of 1000 S/s and your while loop is running every 100 ms, you will obtain roughly 100 samples per iteration of your while loop.  This means that you will get roughly 1000 S in one second and 10,000 samples in 10 seconds.  The reason you are only seeing 100 points per channel written to the output file is because the export waveform to spreadsheet file.vi is located outside of the while loop.  Since LabVIEW will only take data from the while loop tunnel after it is completely done executing, you are only getting one iteration's worth of data to be output.  This can be fixed easily by one of two ways:

 

1.  Move the export waveform to spreadsheet.vi inside of the while loop so it writes data to file every iteration.

2.  Right click the loop tunnel and choose replace with shift register.  Drop the box to the other side of the loop, right click the input and select create constant.  Then use an insert into array function to add each iteration's waveform data to this array.  Then when the while loop has finished running all of the data you have acquired will be in this built array and ready to output to file.

 

As far as Warning 1905 goes, it looks like this probably has to do with the way the VI is doing averaging.  You can run your main VI in highlight execution mode and watch the block diagram of the SVT FFT Spectrum VI to see exactly where the Warning is coming up.  If you want to resolve the problem the easy way I would simply get rid of the wait VI in the while loop and set the samples to read to exactly 100.  This way the read function will delay the while loop execution until it has exactly 100 samples to pull of the buffer.  This should also eliminate the warning because the number of samples you are feeding in will be the same each time.

 

 

Brian 

Brian G.
0 Kudos
Message 4 of 7
(11,157 Views)

Ok, I understand now how to determine the number of samples and why it was only collecting data from one iteration of the loop.  I implemented the changes you suggested, but am still not getting correct results.  I tried moving the export to spreadsheet vi to the interior of the loop, but all that did was prompt me to save the file over and over following each loop iteration.  I then moved back to the original position and implemented shift registers to store the data into an array (This is shown in the attachment).  This worked the same way as before, in that it would only save the data collected from the final iteration of the loop (Not completely sure if I wired it correctly.  I tried placing the array function both inside and outside of the loop and got the same result either way.). 

 

Running the vi as is continues to bring up the "Warning 1905" message as before.  I tried running it in highlight execution mode to follow the path, but that stopped the program prematurely and gave me the following error message (this error only occurred when running in highlight execution mode):

 

Error -200279 occurred at Vibration.vi

Possible reason(s):

Attempted to read samples that are no longer available. The requested sample was previously available, but has since been overwritten.

Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem.

Property: RelativeTo
Corresponding Value: Current Read Position
Property: Offset
Corresponding Value: 0

Task Name: _unnamedTask<4D>

 

I also attempted to run the vi using a finite number of samples instead of employing the wait function, but doing that brought up another error message which read:

 

Error -200278 occurred at Vibration.vi

Possible reason(s):

Attempted to read a sample beyond the final sample acquired. The acquisition has stopped, therefore the sample specified by the combination of position and offset will never be available.

Specify a position and offset which selects a sample up to, but not beyond, the final sample acquired. The final sample acquired can be determined by querying the total samples acquired after an acquisition has stopped.

Attempted to Read Sample: 100
Property: RelativeTo
Corresponding Value: Current Read Position
Property: Offset
Corresponding Value: 0

Task Name: _unnamedTask<4F>

 

These errors are coming through the Read function, and I'm not sure how to interpret them.  Thanks again for your help.  It has been very informative thus far.

 

Thanks,

Jason

0 Kudos
Message 5 of 7
(11,144 Views)
Solution
Accepted by topic author JMJ09

This is how you can use the shift register to build the array, and also where you can choose to read exactly 100 samples per while loop iteration.

 

Vibration with built array.png

 

 

Brian

Brian G.
0 Kudos
Message 6 of 7
(11,131 Views)

Thanks for the help!

0 Kudos
Message 7 of 7
(11,123 Views)