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 MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

Mathscript node

I implemented the  music algorithm by mathscript.

Then I tried to implement the music algorithm by VI with mathscript node but it doesn't work.


Actually, it works when I imported the .m file in mathscript node.

However, it doesn't work when I declare variable outside mathscript node.

The following code is the music algorithm and some function has already been defined, for example, spv, music, pattern, plot2d3d.

 

array=[-2 0 0;-1 0 0;0 0 0;1 0 0;2 0 0]
direction=[30,0;35,0;90,0]

S=spv(array,direction);
Rmm_coh=[1 1 0; 1 1 0; 0 0 1];
sigma2=0.0001;
Rxx_spatial=0;

for k=1:3
    D=diag(S(k,:));
    Rxx_coh=S*D^(k-1)*Rmm_coh*D'^(k-1)*S' + sigma2*eye(5);
    Rxx_spatial= Rxx_spatial + Rxx_coh;
end

eig_Rxx_spatial=eig(Rxx_spatial);

m=0;
for i=1:length(eig_Rxx_spatial)
if eig_Rxx_spatial(i)>=m*0.0001
m=m+1;
end
end
Z=music(array, Rxx_spatial, m);
plot2d3d(Z,[0:180],0,'dB','MuSIC spectrum');

 

I tired to declare the variable(array, direction) outside mathscript node.

Then these variables become the input of mathscript node.

 

Then I run it, but it has error.

MathScript Node (spv): User-defined function contains an error

MathScript Node (music): User-defined function contains an error

 

I don't know why I have this error. The code should be correct.

 

 

I have one more question. I tried to read .mat file in mathscript, but it doesn't work.

I found a previous Forum and download VI to read .mat file.

However, this file is not valid on my .mat file. Could anyone tell me how to read .mat file in mathscript, please?

 

Many thanks.

0 Kudos
Message 1 of 11
(8,117 Views)

Hi,

 

Can you attach a snapshot of how you define the variable and pass them into the MathScript Node?

 

Which version of MathScript do you use? Probably, your .mat file is compressed one. Then, MathScript can not read from it.

0 Kudos
Message 2 of 11
(8,113 Views)

Thank you for your help.

I attached the snapshot which shows how to define variables adn pass them into Mathscript node.

 

And...I used LabView 2010 evalution version.

I found "Read Level 4 MAT File" from previous forum, but it says the memory is full when I run it.

I think it would work if I modify this file.

However I am a beginner of LabView...so I have no idea how to modify it.

 

I attached Read Level 4 MAT File and .mat file as well.

 

Many thanks.

Download All
0 Kudos
Message 3 of 11
(8,106 Views)

Hi,

 

I do not see any problem from the snapshot. If you use the same input for the variables, the behavior should be the same between MathScript Node and Window.

 

Your .mat file is compressed one. Currently, MathScript can not read data from it. However, the next release of MathScript will support the compressed .mat file. Another workaround is to use -v6 option when you create this .mat file. -v6 option generates the un-compressed .mat file.

0 Kudos
Message 4 of 11
(8,101 Views)

Thank you for your helps.

I also expected the behaviour should be the same between MathScript Node and Window.

If you have more time, could you check the snapshot of frontpanel as well please? I attached it with this post.

 

My mat file is not generated by me. It was given to me from my tutor. There are four variables in mat file.

I can define 3 variables in mathscript seperately, because they are small size.

However one varialbe is <5*7471 double> size.

Could you pleaes advise me how to figure this problem out?

 

I again appreciate your helps and efforts.

 

0 Kudos
Message 5 of 11
(8,098 Views)

Finally I figured out the problem of reading mat file but I still have a problem with MathScript Node.

 

Could anyone check the snapshot of front panel please? I'm not sure whether I put elements of variable correctly.

 

I've got another problem in eig function. I have a matrix S with size of 310*310 double.

I got eigenvector and eigenvalue of the matrix S by both Matlab and Labview mathscript.

However, their eigenvector and eigenvalue are different. I don't know why they are different.

Is there anyone who know this problem?

Please help me.

 

Many thanks!!!!

 

0 Kudos
Message 6 of 11
(8,083 Views)

Hi,

 

Since the error returned from spv, is it possible to attach this user-defined function?

 

Also, could you send a copy of matrix S and the eigenvalue and eigenvector returned from Matlab? I can take a look.

0 Kudos
Message 7 of 11
(8,080 Views)

Hi,

 

Since the error returned from spv, is it possible to attach this user-defined function?

 

Also, could you send a copy of matrix S and the eigenvalue and eigenvector returned from Matlab? I can take a look.

0 Kudos
Message 8 of 11
(8,079 Views)

Thank you for your help.

I attaced .zip file containing spv function and S matrix( called Rxx in Eigen zip file).

 

In AM1 zip file, there are all defined functions (spv, music, pattern,...etc.)

You can try to run it 'Music Algorithm'

 

In Eigen zip file, there are 3 matrices. First one is Rxx matrix.

x and y matrix is result of [x,y]=eig(Rxx).

 

Many Thanks.

Download All
0 Kudos
Message 9 of 11
(8,072 Views)

Hi,

 

The user-defined function spv invokes another non-existed function repc at line 19. If you comment or remove it, the VI can run. I guess that MathScript Window performs check at run-time. Since repc is not invoked actually, the script can run in MathScript Window. However, MathScript Node perform a compile time check, then it returns error. Moreover, you should not call clear at the beginning of MathScript Node. It will clean up all the input variable.

 

The Rxx matrix is an ill-conditioned one. Its condition number is as large as 3.3E+19. Also, it appears that many eigenvalues of Rxx are close to zero. Then, I think both LabVIEW and Matlab can not calculate eigenvalues and eigenvectors accurately for such kind of matrix. Moreover, y.mat is empty.

 

0 Kudos
Message 10 of 11
(8,067 Views)