LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reset averaging the Power Spectrum Density without first call

Solved!
Go to solution

Hello, I am using the Power spectrum Density function to average 100 signals from a DAQ. This works well when I run it once then exit program.

Now, I would like to repeat this averaging without exit the program.

For this purpose, I simply created a while loop, with an event case on "start" button. When I press "start", then the 100 signals are averaged. When averaging is finished, it turns "start" button to OFF, then wait an event.

Now If I push again on "start", this should average 100 new signals etc ...

But this does not happen.

1- there is a possibility to restart averaging on the PSD vi. If I turn it to T (true), then it should restart averaging as expected. But it will never work in a while loop because the sub vi of PSD is embedding a "first call" function to restart averaging only if it is the first event. But in my case, at the 2nd turn of averaging, the first call is False. So I cannot use this function

2- I found that if I change the averaging parameter, especially if the number of average is modified, then the PSD averaging can restart !

For example *

1st run , the averaging number is set to 100. I get average PSD.

2nd run, if I set averaging number to 100, there is no average PSD.

But if I set averaging number to 101, then I get a new average PSD.

 

So what I need is to keep the averaging number to 100 for any run and this seems not possible for unknown reason. So is it a bug ? or is there any way to reset the averaging PSD without using the "first call" function in the sub vi of PSD ( that I cannot access to modify it). ?

 

* I call "run" the case when I push "start" on.

 

0 Kudos
Message 1 of 5
(2,330 Views)

Sorry, I will answer myself ...

I found that the PSD sub vi can be edited : in Operate -> change to edit mode.

Then I copy-paste the sub-vi, renamed it, and I deleted the "first call" function.

Now everything is OK.

 

But I have another problem that is how to retrieve the PSD plot data (I have 4 plots on this PSD graph) ? OK, with an invoke node, I can save plot data to excel. But this method generated an new excel file for every loop. I would like to append data (frequency and amplitude of PSD for each plot) in excel or text but in 1 file.

 

any idea about how to get access to the data X,Y of the PSD grpah for each of the 4 plots (X=freq, Y1, Y2, Y3, Y4) ?

 

0 Kudos
Message 2 of 5
(2,314 Views)

Hi arienai,

 

What you're trying to do is certainly possible (and perhaps in easier ways than you have used so far) but unfortunately (or fortunately? but not for this question) there are many PSD functions in LabVIEW (some via toolkits like the Sound and Vibration toolkit, for example).

 

Can you upload your VI then I and others can see what you're doing and help you a little more accurately?

 

With regards to writing a spreadsheet, you might find something like Write Delimited Spreadsheet useful (it has an append boolean), or you could more manually control your writes via Write to Text File and Open/Create/Replace File, Close File.

A guide to some options can be found here: http://zone.ni.com/reference/en-XX/help/371361R-01/lvhowto/writing_to_spreadsheet_fil/


GCentral
0 Kudos
Message 3 of 5
(2,273 Views)

Dear all, I took the labview library examples for Ai and Ao.

I supply continuous Ao voltage on demand, and I read continuously Ai with acceptable rate on 2 inputs. I added PSD (power spectral density) and I let the case "auto start" unplugged. Whatever I put T of F, the PSD cannot be displayed. 

The Ai is displayed correctly. I can read Ao with the oscilloscope and confirm that it is working. 

However, I don't understand why the PSD is not working since I took Labview PSD function from the Waveform Measurement Palette. 

 

0 Kudos
Message 4 of 5
(2,246 Views)
Solution
Accepted by topic author arienai

Ok, thank you for attaching the code. Now it's easier to give some advice:

  • To the left of your While loop, you have a cluster of parameters for the PSD. The third (right click on the cluster edge, go to autosizing and set to e.g. "Arrange Vertically") is "number of averages". Yours is set to 0. Change this to the number you want
  • You have a 10ms wait in the loop - this doesn't do anything useful for you - the DAQmx Timing should control the loop rate (for the Analog Input task)
  • The "reset averaging" input to the PSD should work as advertised. As you said, inside the VI is a "first call?" node, but this is passed to an "Or" node. So it means that it will restart if either the input (your control) is true, or the VI is being called for the first time. If you put it in a while loop like you have, it will be controllable using a control:

psd.png

Here I also connected the extra outputs to indicators to check the error and demonstrate the averaging behaviour. Try it out and it might give you some more information.


GCentral
0 Kudos
Message 5 of 5
(2,232 Views)