LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Matlab script in Labview

Solved!
Go to solution

Hello,

I am trying to use matlab script in labview to post process the sampled signals from DAQ(attached is the vi I tried)

After every 10 seconds I want to the send the sampled voltage data to matlab scritp block which does 1) detection of peaks using peakdetection function and plots the obtained peaks on the sampled signal 2) calculates standard of 10 secs data and plots on chart.

 

But I am confused of 1) how to call the peakdetection function inside the matlabscript block

2) How to send the 10secs data of voltage and time values to the matlab script block

3) How to plot the signal and detected peaks on the same plot (which can be done in matlab using holdon as shown in the atached vi).

Can someone suggest for implementing these .

Thanks.

0 Kudos
Message 1 of 10
(5,042 Views)

@GoviRe wrote:

Hello,

I am trying to use matlab script in labview to post process the sampled signals from DAQ(attached is the vi I tried)

After every 10 seconds I want to the send the sampled voltage data to matlab scritp block which does 1) detection of peaks using peakdetection function and plots the obtained peaks on the sampled signal 2) calculates standard of 10 secs data and plots on chart.

 

But I am confused of 1) how to call the peakdetection function inside the matlabscript block

2) How to send the 10secs data of voltage and time values to the matlab script block

3) How to plot the signal and detected peaks on the same plot (which can be done in matlab using holdon as shown in the atached vi).

Can someone suggest for implementing these .

Thanks.


I am wondering why are you trying to do these things in Matlab script when LabVIEW already provides you handy. Did you try the Peak detection VI present in LabVIEW?

-----

The best solution is the one you find it by yourself
Message 2 of 10
(5,036 Views)

Hi 

Because I want to develope a matlab script that can be later used to process the realtime data sampled using microconroller( where I dont use DAQ to sample the analog signals).I want to make sure that the matlab script works fine.

Can someone help me out implementing the above metioned things.

thanks.

0 Kudos
Message 3 of 10
(5,028 Views)
Hello,
Can anyone help me out in fixing the above things with matlab in labview.
Thanks.
0 Kudos
Message 4 of 10
(4,985 Views)

Hi GovRi,

    You can try the attached vi to see if your Matlab script is working. You have to have the peakdet.m installed. If it works, then we can look at the best way to hook your DAQ up to the script node.

 

Good luck!

0 Kudos
Message 5 of 10
(4,963 Views)

Hi GabeG,

I tried to use the vi you posted but I am getting some error as shown in the attached image.I also set the path to the directory in which the peakdet.m files resides using this tools->paths(as shown in the attached image).BTW,I am using Matlab R2011.

Can I get some help in fixing this issue.

thanks.

Download All
0 Kudos
Message 6 of 10
(4,941 Views)
Solution
Accepted by topic author GoviRe

Hi GovRi,

   I just incorporated peakdet into the script node and it works for me. Go ahead and try it again. Also I made a first stab at the data aquisition try it. The Matlab window should open as soon as you open the vi, if it doesn't there is a problem with the COM connection to Matlab.

 

Good luck!

Download All
Message 7 of 10
(4,919 Views)

Thanks  GabeG,

Now, Labview&Matlab_TestNoAq.vi  is woking Good and for the second one  Labview&Matlab_TestAq.vi it is showing error as shown in the attached image when these ines of code are present in the matlab scrtip 

subplot(2,1,1),plot(maxtab(:,1),maxtab(:,2),'*r');
SDN=std(maxtab(:,1));

and SDN output of the Matlab script

but when I removed these it is working fine(but not showing the detected peaks).

Can you suggest me a solution for the above and also can I know the best method to add one more channel that samples another device signal which has to be processed in this same way(Signals sampled from 2 devices have to be porcessed in this same way).

Thanks.

0 Kudos
Message 8 of 10
(4,886 Views)
Solution
Accepted by topic author GoviRe

Hi,

   The error was being generated because peakdet didn't find any pulses in your signal which lead to Matlab trying to plot an empty array. I added in a check to see if the maxtab array is empty and if so, just put zero out of SDN and skip the peak locations plot. I also added a second channel.

 

Good luck!

0 Kudos
Message 9 of 10
(4,849 Views)

Hi GabeG,

Is there any smart way to write and make use of the matlab functions in the matlab script block because I have to use multiple functions for my requirement.

Thankyou.

0 Kudos
Message 10 of 10
(4,760 Views)