LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FFT - Sample rate and samples to read - can i go faster?

Solved!
Go to solution

Hello, 

 

I've built a vibration measurement VI that uses an n channel FFT module and then an SVL integration module to output the displacement waveform into a graph , I then do another set of things to output that into a file but my problem is that the refresh on the DAQ itself is every two seconds, so whenever i need to record a measurement ve got to restart averaging... then wait a bit (like 6 seconds), then record, and on a test where I'm taking like 50 readings this seems needlesly tedious.

 

I'm using a DAQmx virtual channel configured for IEPE accelerometers and i need to measure from 10Hz up to 1000Hz with a preferred resolution of 0.5 Hz so, to get to that I've set up my task to 4096 samples at a 2048Hz rate (i do understand that the math says ill get my samples every 2 seconds and not sooner than that)

 

however... I have to ask, is there any way to get the measurement faster without breaking the laws of physics? or reducing my resolution (0.5Hz)?

0 Kudos
Message 1 of 11
(794 Views)

Suppose you sample continuously at 2 kHz for 2 seconds (I'm "rounding" to decimal).  You have a While Loop that has a DAQmx Read of 4000 points.  How much "free time" do you think there is in that loop?  I'm going to guess the answer is at least 1.9 seconds.  Why not put this time to good use, say, doing an FFT?  You don't do this inside the DAQ Loop, however -- you "export" the data out of the loop into another processing loop running in parallel, so while the DAQ loop, which "produces" data, is waiting for the samples to finish, the second loop, which is "consuming" the previous data for processing, is writing to disk, or doing an FFT, or other things.  This "split the job into two parallel loops" is called the Producer/Consumer Design Pattern.  The "trick" is that the data are pass from the Producer to the Consumer by a Queue, or a Stream Channel Wire, a process that takes essentially 0 time, and also provides a little bit of leeway in the timing (Queues and Channel Wires can hold several "instances" of data in memory, so if one loop iteration is a little slow, because you are, say, opening a file, as long as the other iterations can "make up the time", everything gets processed, and nothing gets lost.

 

You've only "described" what you are trying to do.  Without looking at LabVIEW code (not "pictures of code"), I can't say that a Producer/Consumer design will help, but if you are doing all of your data acquisition and processing inside a single While Loop, it should help a lot.  Look up Producer/Consumer in the LabVIEW Help, or on the Web for more details and explanations.

 

Bob Schor

0 Kudos
Message 2 of 11
(765 Views)

@G.Suarez wrote:

Hello, 

 

I've built a vibration measurement VI that uses an n channel FFT module and then an SVL integration module to output the displacement waveform into a graph , I then do another set of things to output that into a file but my problem is that the refresh on the DAQ itself is every two seconds, so whenever i need to record a measurement ve got to restart averaging... then wait a bit (like 6 seconds), then record, and on a test where I'm taking like 50 readings this seems needlesly tedious.

 

I'm using a DAQmx virtual channel configured for IEPE accelerometers and i need to measure from 10Hz up to 1000Hz with a preferred resolution of 0.5 Hz so, to get to that I've set up my task to 4096 samples at a 2048Hz rate (i do understand that the math says ill get my samples every 2 seconds and not sooner than that)

 

however... I have to ask, is there any way to get the measurement faster without breaking the laws of physics? or reducing my resolution (0.5Hz)?


Do you really need 0.5Hz resolution?

You need a fine resolution when there are two signals close in frequency, do you need to resolve the amplitude of two signals that are just 0.5Hz apart?

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 3 of 11
(736 Views)

Well, since you asked for code...

 

i did look into producer / consumer structures but i think that since my main goal is to get the "restart average" to take effect faster so i can record my data (and it would be nice to see the waveform graph update faster than every 2 seconds) i don't understand how i would go about separating that part into another while loop and getting samples faster than that

0 Kudos
Message 4 of 11
(700 Views)

A quick lesson in Signal Analysis.  If the highest frequency you want to sample is S (for "sampling") Hz, you must sample at a minimum of 2*S, so to go up to 1 kHz, you need to sample at at least 2 kHz.  On the other hand, if you sample for a time T, the lowest frequency you can resolve is 1/T, so if you want to measure down to 10 Hz, you need to sample for at least 0.1 sec.  So here's how to "Have your Cake and Eat It, Too".

 

Set up your A/D to acquire data at 2 KHz continuously, using a sample size of 50 points.  This means that your A/D "Producer" loop will run at 40 Hz, and can deliver these data to the Consumer that can simultaneously stream them to disk and plot the average of these data (which shows you the low frequency behavior of your signal, while preserving the high frequencies intact on the disk file).  If you want to be fancy, you can also stream these data through a point-by-point FFT and look at a time-varying Bode Plot of the data (hmm, I wonder if that would work, but don't see why not -- I think PCs are fast enough ...).

 

Bob Schor

Message 5 of 11
(686 Views)

I see what you mean by the first paragraph of your response, but i think i want a "fancier cake"

 

My A/D is a continuous task running at 2k and taking in 4k samples

 

if i understood correctly the first step is to reduce the sample size on my A/D task from 4k to a mere 50?, so instead of the waveform being plotted at 0.5,1,1.5...999.5Hz I would effectively plot at 0,40,80,120..960Hz? I really need the 0.5Hz resolution, I would be willing to reduce sample size in the task  down to 2k but any less than that, the data obtained will not be useful., at that point I've experienced that a reduction in the amount of samples drastically improves performance regardless of everything staying inside one loop, at the cost of course of resolution.

 

I apologize if I sound like I'm not wanting to take your advice, I'm not (it does help me to better understand why i ended up with that sample rate), I really appreciate all the information you've shared, I've been learning this by using labview examples, going through the help page for the modules learning about all the different types of signals that can be processed and there isn't much there to teach you about performance tips and best practices, i probably misunderstood what you meant, but from my calculations with my current setup that does mean that my loop is running at 0.5Hz right?

 

I guess what I'm asking is for confirmation, if I need all samples between 10Hz and 1kHz every 0.5Hz then there is no way to get a higher loop frequency, is there?

0 Kudos
Message 6 of 11
(657 Views)

I don't follow why you think you need 4k samples. Resolution is determined by your sample rate, not the number of samples, so if you want a maximum resolved frequency of 1 kHz, then you need to run at 2 kHz minimum. You're doing that now.

 

The slowest signal determines how long you have to run your system. My signal theory is a little rusty, but I'm pretty sure you would want a minimum of one period of your signal to get a good measurement of it. So, since your minimum period is 10 Hz, you'd see a complete signal in 1/10th of a second. 2 kHz * 0.1 seconds = 200 points. (I didn't follow how Bob got to 50 points, but I'd bet his signal theory is better than mine!).

 

Could you explain why you think you need 4000 samples to get the resolution you're looking for?

 

Edit: Did some quick reading and now I'm following you. I got a couple things confused. I think I'm tracking now though. The number of bins in your result is equal to the number of samples in your input. So, if you need 0.5 Hz resolution up to 1000 Hz, I'd think you'd need 2000 samples, not 4096 samples. Did I get my math right there?

 

To answer your other questions, it sounds like "I have to wait 6 seconds" is the longest delay. Why are you having to wait 6 seconds? Is it because of initialization stuff happening?

 

If so, you could do what Bob said, and just take continual data, but instead of running each 50 samples through the FFT you could buffer it into an array. Each time you add 50 points to the array, you drop the oldest 50 samples. Run the whole array through the FFT, and now you get "instant" data. You basically do your initialization just once at the start. You'd still need to wait 2 seconds after your "test" starts, but going from 8 seconds per test to 2 seconds per test seems like a decent start.

Message 7 of 11
(650 Views)

Well, I sometimes "hang out" with engineers who tell me "Yes, Nyquist (of "Nyquist frequency" fame) says you need to sample at least twice the highest frequency in your signal to prevent "aliasing", and that assumes that you have a really good low-pass filter that kills all frequency components above the Niquist frequency.  They advices me for better fidelity of a "signal" where I'm interested in data below 100 Hz, I should sample at not 2 X, but 4-10 X's (since "sampling" is often cheap), have a Low Pass Filter at, say, 200 Hz (so there will be less phase distortion at 100 Hz).

 

At the other (low) end of the spectrum, you need to have enough samples to constitute one period of the lowest frequency you want, so if you want 0.1 Hz as the low frequency, you need 10 seconds of samples.  You can take them 4000 at a time, but if you are interested in plotting the evolving spectrum as a function of time, you get one spectrum every 10 seconds:  Flash, (wait), Flash, (wait), Flash ...

 

So you "cheat" a little.  Collect 50 samples at a time until you get 4000.  Take the spectrum.  Add 50 more points (discarding the 50 oldest, so you have the 4000-most-recent).  Take another spectrum.  These two spectra represent the signal 0.1 sec later, so if you plot the spectra, you'll have a new plot that updates at 10 Hz.

 

This is a kind of "advanced" thing called (I think) Time-Frequency Analysis.  Not sure if this is what you want to do, but I think LabVIEW has some VIs that can do this.  It is sometimes used in speech analysis, or plotting Bird and Whale songs ...

 

Bob Schor

Message 8 of 11
(634 Views)

Brief summary:

 

1. Nyquist - The highest frequency that can be resolved in the frequency domain is 1/2 the sample rate.  To include 1000 Hz phenomena, you *DO* need to sample at >= 2000 Hz.

 

2. Resolution - frequency resolution is determined by the total time represented by the data set.   Resolution = 1/time.  For 0.5 Hz resolution, you *DO* need to analyze 2 seconds worth of data.

 

3. Update Speed - as both Bert and Bob recently described, by carefully using a 2-second "sliding window" buffer, you can analyze 2 seconds worth of data to get 0.5 Hz resolution *without* having to wait 2 seconds between updates.   Just realize that you'll be trading off update speed vs. the influence of new fresh data.  The faster you update, the bigger the portion of data that stays the same since the previous update.

 

If you do *NOT* need to store a continuous lossless stream of your original data, you can actually implement this "sliding window" using features already built into DAQmx and the way it handles task buffers.  I've written about this several times on the forums, here's one place, and here's another.

 

If you *DO* need to store a lossless stream of original data, I'm pretty sure you'd need to write your own code to implement the sliding buffer Bert & Bob talked about.  (Although it's conceivable I think it's also unlikely you could use the technique linked above in conjunction with the TDMS logging feature.  I doubt DAQmx would support both at the same time, but I haven't actually ever tested it to say for sure.)

 

 

-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.
Message 9 of 11
(613 Views)

@BertMcMahan  ha escrito:

 

Could you explain why you think you need 4000 samples to get the resolution you're looking for?

 

Edit: Did some quick reading and now I'm following you. I got a couple things confused. I think I'm tracking now though. The number of bins in your result is equal to the number of samples in your input. So, if you need 0.5 Hz resolution up to 1000 Hz, I'd think you'd need 2000 samples, not 4096 samples. Did I get my math right there?




 

Well, an image says more than a thousand words so:

this waveform:

GSuarez_4-1720191996940.png

 

 

at 4k / 2k (0.5Hz Resolution)

GSuarez_1-1720191705978.png

 

at 2k/2k (1Hz resolution)

GSuarez_2-1720191813091.png

 

the DAQmx read data signal out has 4k samples, once that exits the FFT i have 2k samples which works with your math.

 

the comment on 6 seconds is because the overall rms values I'm reading get averaged over some time and the device under test conditions are being changed between readings so I'll change those conditions, then reset the averaging and waiting for 3 updates to actually commit the measurement  

0 Kudos
Message 10 of 11
(599 Views)