Vibration measurement sample rate | LabJack
 

Vibration measurement sample rate

6 posts / 0 new
Last post
Nabil
nabilh's picture
Vibration measurement sample rate

Hey,

I want to measure the signal of an accelorometer at a sample rate of 5000 Hz. Afterwards I need to do a frequency analysis so I need both the timestamp at each measurement point as well as the value.

It would be ideal if I could set the labjack to measure for 2 seconds, than wait for an hour or so and measure again for a second. It should be written to one csv file with two new columns or rows for each of the measurements.

The program needs to be in Python. I tried to use the ljm.stream_sequential_ain.py, but there I do not get a time stamp for each voltage value. Any suggestions?

LabJack Support
labjack support's picture
Stream is hardware-timed, so

Stream is hardware-timed, so at 5kHz each scan is 0.2 milliseconds apart according to the clock on the LabJack. You can use that and STREAM_START_TIME_STAMP to calculate the timestamp of each scan according to the LabJack's clock:

http://labjack.com/support/datasheets/t-series/communication/stream-mode...

If you need the timestamp according to the computer's clock, see the next section:

http://labjack.com/support/datasheets/t-series/communication/stream-mode...

 

Each programming language has it's own language-specific way of logging to file. Python's csv.writer looks like what you need:

https://docs.python.org/3/library/csv.html#csv.writer

Nabil
nabilh's picture
Hey,

Hey,

thanks for the hint. So I tried the code attached. I got this printed output and I was wondering if the timed sampe rate is the acctual sample rate. Than the difference between the set sample rate and the actual sample rate would be quite significant.

"Total scans = 5000
Time taken = 1.065242 seconds
LJM Scan Rate = 5000.000000 scans/second
Timed Scan Rate = 4693.769115 scans/second
Timed Sample Rate = 4693.769115 samples/second
Skipped scans = 0"

Is there an ljm fuction to run STREAM_START_TIME_STAMP in python?

I am by the way using the Labjack T4 if that makes any relavent difference.

 

 

File Attachment: 
LabJack Support
labjack support's picture
Some scans will be gathered

Some scans will be gathered between when eStreamStart is called and when it returns. If I set the MAX_REQUESTS to 100, I see:

Total scans = 500000
Time taken = 99.969999 seconds
LJM Scan Rate = 5000.000000 scans/second
Timed Scan Rate = 5001.500500 scans/second
Timed Sample Rate = 5001.500500 samples/second
Skipped scans = 0

You can read STREAM_START_TIME_STAMP like any other register, which is a beneficial thing. As the 3.0 Communication page points out:

A T-series device is a Modbus server—all configurations and data are read from or written to Modbus registers. Thus, the process for reading the serial number, an analog input, or a waveform is functionally the same, you simply access a different address.

For example:

print(ljm.eReadName(handle, "STREAM_START_TIME_STAMP"))

Might print something like:

3952339968.0

Nabil
nabilh's picture
Thanks for your help so far.

Thanks for your help so far. There is only one thing I do not quite understand: When I set MAX_REQUESTS to 2 for example it says that Total scans = 10000. But I only get out 5000 samples. How is the sampling rate than calculated and which of the results is shown?

Is the sample rate the mean over rate through the 10000 scans and are only the last 5000 samples shown? If I wanted to get an accurate sample rate would I need to read out the 10000 samples?

LabJack Support
labjack support's picture
What do you mean that you

What do you mean that you only get out 5000 samples? eStreamRead returns scansPerRead scans every time it's called. Please see the description of aData here:

https://labjack.com/support/software/api/ljm/function-reference/ljmestre...

If you need to keep all the scans around, you can save them from aData to another list,  or you can use stream burst:

https://labjack.com/support/software/api/ljm/function-reference/ljmstrea...