From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generate power spectrum of a period of sample

Solved!
Go to solution

Hi All,

I would like to generate a power spectrum of some data, for example, I have some data collected from "DAQmx Create Virtual Channel (VI)" (AI Accelerometer) for 5 seconds, and I want to generate the power spectrum for the entire 5 seconds. However, the "FFT Power Spectrum VI" or "Spectral Measurements Express VI" seems only perform the power spectrum for a limited data sample or a extremely short period of time. Is there a way to alter this setting? 

 

Really appreciated for any suggestion.

Drake 

0 Kudos
Message 1 of 9
(2,585 Views)

Hi Drake,

 

do you mind to attach your VI? Best would be some typical data set to default in an indicator…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(2,564 Views)

Hi GerdW,

Please find attached VI (V17). Can you elaborate a little more about how to set the indicator to default?

 

Thank you,

Drake

0 Kudos
Message 3 of 9
(2,543 Views)

When you run your VI, Controls or Indicators may take on values (for example, you read a file and save the data in an Array), or you key in some values into controls, then run the VI with those values.  When your VI has values that you'd like to "save as Default" (so that you can send both the VI and "typical data" to the Forum, for example), simply click on the Edit menu, choose "Make Current Values Default", and save the VI (with the Current Values now being Default).  Now attach your VI to your Forum Post, and send the VI with data for us to examine.

 

Bob Schor

0 Kudos
Message 4 of 9
(2,540 Views)

Hi Bob,

This is a nice function. Please see attached VI with typical data. I also included a picture of the front panel and the data collected for the acceleration and FFT.

 

Thank you,

Drake

0 Kudos
Message 5 of 9
(2,514 Views)
Solution
Accepted by topic author Drakelau

Hi Drake,

 

the "FFT Power Spectrum VI" or "Spectral Measurements Express VI" seems only perform the power spectrum for a limited data sample or a extremely short period of time.

Those functions do EXACTLY what you have programmed them to do…

In the loop you are reading 1000 samples (10kS/s sample rate, divided by 10). With those 1000 samples you are calling the FFT functions. Why do you think the functions do work with limited set of data?

 

Is there a way to alter this setting? 

Sure!

Collect 50000 samples when you want to analyze data for a period of 5s.

Either read 50000 samples at once (might give a bad UX) or collect the data of 50 iteration of your current loop…

 

On your VI:

Your initialization loop is somewhat buggy:

- you can define the number of channels

- you autoindex an array of coefficients (ai0 to ai2) with just 3 entries!

- you autoindex an array of sensor lables with 8 entries, 4 of them being empty strings…

This combination of inputs will only work for a limited amount of sensors…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 9
(2,504 Views)

Thank you for your explanation, GerdW. It makes sense to me now.

 

I agree with you that my initialization loop is somewhat buggy. I was trying to limit to 3 sensors for now (add more if needed in the further). In the beginning, I was trying to hide/gray out other ai slots if the number of sensors is not entered (eg. if the number of sensor is entered "1", then ai1 and ai2 will be grayed out). Yet, this doesn't work because the user needs to run the VI in order to execute the action. Do you happen to have a suggestion for this?

 

Thank you,

Drake 

0 Kudos
Message 7 of 9
(2,480 Views)

Hi Drakelau,

 

Do you happen to have a suggestion for this?

Sure - almost all programs with a UI need to handle situations like this…

What about a (while) loop to handle UI actions before the initialization state?

What about a state machine handling each step/state in your program, from user input to init to measurement?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 9
(2,475 Views)

Thank you GerdW. That might actually work. I will look more into that.

 

Best,

Drake

0 Kudos
Message 9 of 9
(2,456 Views)