LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Attached VI's Mathscript runs too slow!

I am using LMS algorithm for noise canellation. Input is any wave file. LMS algorithm is written in Mathscript node. I ran this for 10 minutes but didn't get output. How can we increase the speed of code written in Mathscript node?
 
Thanks in advance.
0 Kudos
Message 1 of 6
(3,364 Views)

 

The program and the wave file is taken from NI's tutorial examples on Mathscript. noise cancellation algorithm is modified which is more computational expensive than the one which is mentioned in the tutorial. The website referenced is the following:-

http://zone.ni.com/devzone/cda/epd/p/id/4183

While running the VI that I have attached in earlier post, please select the input wave as 'SaveFile' and not 'WindowsStartup'. Both of these files are in the above website.

Thanks for any help.

0 Kudos
Message 2 of 6
(3,361 Views)
Hi Gaurav,
 
I think the problem comes with the for loops in your mathscript node.  Either its in an infinite loop or it just takes too long to process the entire file.  I saw that you had waited 10 minutes, but did you EVER get any outputs?  I took out the two for loops and although I did not play around with it enough, the data ran through the rest of the code and I did get output graphs.  If you had gotten an output before, then you should realize that right now you have a nested for loop and that may not be the most efficient design.  If you have never been able to get an output, then you have an infinite loop and you may want to look over the conditional statement for your for loops.
0 Kudos
Message 3 of 6
(3,320 Views)
Hi Tolga,

Thanks for your message. Yesterday I did get a chance to speak with one of NI application engineer on phone. She has checked the text code inside mathscript node. There is no infinite loop. I tested this code in Matlab, it works fine. The problem then would be more computational time spent in for loops. I have a wave file which has 66000 samples (the outer for loop) and the inner for loop runs for filter-length (32). The engineer suggested me to take VI approach instead of math-script. Do you think that mathscript node will not be able to handle above computation?

Please let me know as I believe that there could be something else going on...

Thanks in advance.

Gaurav
0 Kudos
Message 4 of 6
(3,309 Views)

I wouldn't say that the Mathscript would not be able to handle the operation, but more that it is harder to debug than LabView code.  As you can see, once the program runs, you really can't tell where the code is getting held up.  LabView can handle the operations that I see in your code, so I do suggest, as the other applications engineer you have spoken with, that you try writing this in LabView instead. 

After writing the code in LabView, let me know.  If it works, and the code in LabView matches the MatLab code, then perhaps there's a bug in the Mathscript translation.  If it does not work, then perhaps more debugging is needed.

0 Kudos
Message 5 of 6
(3,290 Views)
Hi Gaurav,

There is a small bug with the code in your MathScript Node which is causing some of the performance problem. On line 17, the script says
   outputs(n) = weights * input';
But it should probably say
   output(n) = weights * input';  %remove the 's' from 'outputs'

The result of the bug is that the array 'outputs' was being grown by one element on every iteration of the outer for loop. This memory allocation can dramatically slow performance.

Unfortunately, the script still takes a while to execute even with this fix. On my machine it takes about 2 minutes to filter the first 6600 samples so it would probably take about 10 times longer to filter the entire signal. I think that the others' suggestion of rewriting these loops in LabVIEW will help with performance a lot.

The MathScript development team is aware of this type of performance issue and we are working to improve it in future releases of LabVIEW. Keep the feedback coming!

Thanks,
jattas
LabVIEW Math & Signal Processing
0 Kudos
Message 6 of 6
(3,276 Views)