NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member pem
Member
pem
Posts: 11
0 Kudos

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.

Active Participant
ttrr
Posts: 225
0 Kudos

回复: Different results between psd_welch in labview and pwelch in matlab

Hi,

 

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

Member pem
Member
pem
Posts: 11
0 Kudos

RE: Different results between psd_welch in labview and pwelch in matlab

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.

Member
Andrew_B
Posts: 94
0 Kudos

Re: Different results between psd_welch in labview and pwelch in matlab

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.

Applications Engineer
National Instruments
Member pem
Member
pem
Posts: 11
0 Kudos

Re: Different results between psd_welch in labview and pwelch in matlab

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.

Member
JtotheB
Posts: 194
0 Kudos

Re: Different results between psd_welch in labview and pwelch in matlab

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
Member pem
Member
pem
Posts: 11
0 Kudos

Re: Different results between psd_welch in labview and pwelch in matlab

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. 

Member pem
Member
pem
Posts: 11
0 Kudos

Re: Different results between psd_welch in labview and pwelch in matlab

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

Member
JtotheB
Posts: 194
0 Kudos

Re: Different results between psd_welch in labview and pwelch in matlab

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
Member pem
Member
pem
Posts: 11
0 Kudos

Re: Different results between psd_welch in labview and pwelch in matlab

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.

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page