LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

Different results between psd_welch in labview and pwelch in matlab

Hi,

 

I want to calculate power spectral density in Labview using y=psd_welch(x,hann(256),128,256,10000);

The result is different from doing y=pwelch(x,hann(256),128,256,10000) in Matlab. What is that problem?

 

And if I want to do the same job as y=pwelch(x) in Matlab, what code should I use in Labview MathScript structure?

Thank you.

0 Kudos
Message 1 of 17
(11,648 Views)

Hi,

 

What's the input signal? Could you please attach a snapshot to show the difference? Thanks!

0 Kudos
Message 2 of 17
(11,643 Views)

Hi ttrr,

 

The input signal is sawtooth signal generated by simulate signal, with frequency 100.1hz and sampling rate 10khz.

The first image attached is doing pwelch(x,hann(256),128,256,10000); in matlab, the second one is done by labview.

 

I want to use labview computing psd for signal showed as picture 3 attached, I already did in Matlab with function pwelch(x).

Now I tried to get the same result in labview, but I failed to find correct codes. 

 

Thanks.

Download All
0 Kudos
Message 3 of 17
(11,637 Views)

Hello pem,

 

I have a couple questions to clarify your exact situation:

 

1. What versions of MATLAB and LabVIEW are you working with?

2. Are you intending to run this code on a Real-Time target or a machine that does not have MATLAB installed?

 

With the second question, a MATLAB script node would call directly into MATLAB from LabVIEW. This would ensure you have exactly the same results. However, you cannot use the MATLAB script node on Real-Time targets and MATLAB needs to be installed on the computer.

 

Regards,

 

Andrew Brown

 

MATLAB® is a registered trademark of The MathWorks, Inc.

Software Engineer
National Instruments
0 Kudos
Message 4 of 17
(11,624 Views)

Hello Andrew,

 

matlab version is 2011a and labview is 2010. I did run matlab script node without matlab.

If i have matlab installed, may i use it for real time psd calculating?

If not, how to set fft power spectrum and psd vi to get the same result? Thanks.

0 Kudos
Message 5 of 17
(11,622 Views)

Hey pem,

 

You can't use the MATLAB Script Node if you plan to deploy your VI to one of our Real-Time targets, like a cRIO or a PXI system. If you are planning to do the calculations on your computer, you'll be fine using the MATLAB Script Node and you can do the calculations on the fly. Can you post your VI for us to look at?

 

MATLAB® is a registered trademark of The MathWorks, Inc.

John B.
Embedded Networks R&D
National Instruments
Certified LabVIEW Developer
0 Kudos
Message 6 of 17
(11,606 Views)

Hi JtotheB,

 

VI is attached. What I want to do is to get signal from NI 6220 (or something else), computing power spectral density. Taking some points from psd and calculating.

What I did before is to take signal, and calculate psd in matlab using pwelch. Now I want do all in Labview, any suggestions? Thank you. 

0 Kudos
Message 7 of 17
(11,601 Views)

I use matlab to get psd using pwelch (x); Now I want to get the same result using labview, maybe fft power spectrum and psd vi, how to set it? Thanks

0 Kudos
Message 8 of 17
(11,566 Views)

Hey pem,

 

I've been playing with this, and I've got pretty similar results from MathScript to LabVIEW. 

 

Capture.PNG

 

welch.png

 

I haven't figured out why they're off by that scaling factor (probably units returned by psd_welch), but using the TSA Welch VI from the Advanced Signal Processing Toolkit will allow you to use Welch's method for PSD calculation.

John B.
Embedded Networks R&D
National Instruments
Certified LabVIEW Developer
0 Kudos
Message 9 of 17
(11,548 Views)

Thank you JtotheB, I tried TSA Welch and it did give out the same result as mathscript node, but the both results only gave 103 data of PSD.

When I conputed in matlab, it ran out 129 data. They still cannot match each other. What I want is to get the same PSD value as matlab. Thanks.

0 Kudos
Message 10 of 17
(11,538 Views)