Matlab script node for real time purpose

Hi!
We are trying to control in real time the frequency of a vibration motor with a voltage signal proportional to EMG activation.
Our EMG sends data to a LAN port and we read them in Labview using the UDP Read function.
We created a VI which reads data from UDP connection, parses the header and does the decoding (according to the data type of our EMG device, TMSi Porti).
Every sample read from UDP port is passed to the Matlab script node which implements a Bayesian filter which returns a value (MAP) used to control the vibration frequency.
The problem is that this operation is extremely slow...(about 15 seconds!!) and we need it to be real time!
We tried also a simple MA filter and the delay is reduced to around 2 sec, so we think that the major problem is in the Matlab script node.
We wonder if this delay is due to the call of an external code (Matlab) or to the complexity of the Matlab code itself.
Do you know how to improve the performance of this VI?
Thank you!
Serena
Attachments:
EMGreceiver+Bayes.vi ‏54 KB

Serena
I noticed that your code also have LabVIEW MathScript RT code. Have you tried to replace the Matlab scriptnode with it? The MathScript Node compiles the script natively into G function and avoid transfering information between programs.
If this does not speedup your application, please attach the subVIs and test data that allow us to reproduce the problem and performance. Also, what is the version of LabVIEW that you are using? If it is before LabVIEW 2009, then I would strong recommend update to that version.
Barp - Control and Simulation Group - LabVIEW R&D - National Instruments

Similar Messages

  • Pxi 1042 configuration for Real-Time

    I have purchased
    PXI-1042
    controller 8187
    one module for data capturing.
    I want to configure the said pxi for Real-Time purposes,
    so what steps should I follow?
    thanks
    Abbas
    Solved!
    Go to Solution.

    The Real-Time Deployment License is different from the LabVIEW RT module.
    When you purchase a PXI controller, part of what you are buying is the operating system that is installed on it.  If you purchased the controller with Windows on it then you purchased the copy of Windows that came with it.  Now that you want to put the real-time operating system on it, you need to purchase the license for it.
    But that's all legal stuff.
    And you are correct that there is a copy of the RTOS on the controller.  But if your controller has its disk formatted as NTFS you will not be able to use it.   The RTOS requires that the hard drive be FAT32. 
    If your controller is FAT32 then you can boot into BIOS (hit delete while booting), and select Real-Time in the Boot Configuration to make your controller boot into Real-Time.
    If you controller is not FAT32 then you will need to format the controller first, using the disks I have previously mentioned.
    Please let me know if you have any questions.
    Justin Parker
    National Instruments
    Product Support Engineer

  • When I use Call Library Function Node in real time, is the DLL loaded once for all or load every time it is called?

    When I use Call Library Function Node in real time, is the DLL loaded once for all or load every time when it is called?
    I have a time critical real time application, in which I use a piece of DLL function developed by C++.  It is OK?  Could any senior developer assure me?
    Thank you in advance.
    Solved!
    Go to Solution.

    qing_shan61 wrote:
    When I use Call Library Function Node in real time, is the DLL loaded once for all or load every time when it is called?
    Once
    qing_shan61 wrote:
    I have a time critical real time application, in which I use a piece of DLL function developed by C++.  It is OK?
    OK
    Be sure that all DLL calls are thread safe (do not perform calls in UI thread).
    Also for real-time application you need real-time OS.
    Andrey.

  • I have some software problems of running matlab script node in the LabVIEW program.

    Hi there,
    I wrote a simple matlab code, like x= 1, y = x*2. Then I tried to put them into matlab script node in LabVIEW.
    However, when I ran the program, I couldn't run and Labiew show some error. 
    Then I tried the method talked before on this forum. Please see the following link.
    http://forums.ni.com/ni/board/message?board.id=Mat​hScript&thread.id=571
    I followed the instruction and open the "command prompt," type some commands then I could run the program, and simultaneously, the LabVIEW program open "Matlab command line window" and run my labview code. However, if I didn't use the command prompt, the  "matlab command window" will not be opened by running the labview program. It would just show some error. And even if I turn on the matlab program in advance, I still couldn't run the labview program.
    Is there any effecient way to deal with this problem without using "command prompt?" Because I try another PC with both matlab and labview installed on it, I "can" run my simple matlab script node on it, and it will open the matlab command line window automatically by running my code. Therefore, I thought there might be some software linking problems in the previous PC I used . Do you have any ideas?
    Thanks in advacne.  

    This board is for Mathscript, but you seem to have a matlab problem. You should probably post in the LabVIEW forum instead.
    What is your LabVIEW version? What is you matlab version?
    LabVIEW Champion . Do more with less code and in less time .

  • Calling user defined functions in Matlab Script Node

    Greetings!
    I am not successful in calling a user defined function inside a Matlab Script Node.
    The path has been added to Matlab, but the Matlab script node is not calling my function.
    I am calling it as follows:
    a= fcd(b,c);
    and the fcd.m file is calculating the 'first central difference' - works in Matlab, but not in LabVIEW:
    function MtxOut=fcd(MtxIn,dt)
    %MtxOut=fcd(MtxIn,dt)
    %first central difference method of finding instantaneous
    %first derivatives
    %MtxIn = MxN matrix of inputs
    %dt = time change between inputs
    %MtxOut = MxN matrix of first derivatives of inputs
    r=size(MtxIn,1);
    c=size(MtxIn,2);
    MtxOut(1,=(MtxIn(2,-MtxIn(1,)/dt;
    MtxOut(r,=(MtxIn(r,-MtxIn(r-1,)/dt;
    for i=2:r-1
        for j=1:c
            MtxOut(i,j)=(MtxIn(i+1,j)-MtxIn(i-1,j))/(2*dt);
        end
    end

    Matthew:
    What version of MatLab, LabVIEW are you using?. Also, what type of errors are you running into?.
    Thanks,
    Rudi N.

  • How to insert data from file into matlab script node

    I have interfaced input data from file to be processed using matlab script node. But the problem is that I could not capture the multiple data into matlab script node and to convert it into matrix. Further to this I need to process the data by plotting graphs from it. Thank you in advance for the advice

    Zarina,
    To clarify your problem, you have a script node contaning your Matlab code. Are you then using the standard LV functions to load in your data from a file and pass it into the script node?
    Regards
    Tristan

  • Input data type of Matlab script node

    Hi,
    I have 1D array of complex number in single precision.
    Matlab script node is used to import data into Matlab and do some data processing, and then export.
    Data type of input is currently double precision.
    How to re-define this input data type of the Matlab script node?
    Thanks,

    Right, arrays of singles are not supported. See Comparison of MathScript RT Module and the MATLAB® Software Data Types in LabVIEW
    As for memory usage, Profiling the VI should let you know how much memory Labview uses when running your code. Communication with MATLAB® is done through ActiveX, and I'm actually not 100% sure whether it will reflect memory usage from script execution. I think it'll be simple enough to profile your VI with and without the MATLAB Script node and note the memory usage difference...
    Misha

  • IMAQ FFT multiplication and MATLAB Script Nodes/Compact Rio

    I would like to automatically generate a frequency kernel to multiply with the FFT of my IMAQ image. I was wondering if there was a way for LabVIEW to automatically set up 2D arrays (with a lower bound, a step size and a higher bound) like what is done in MATLAB.
    I was wondering also, if someone could give me some insight as to what restrictions I face, when uploading code from MATLAB script nodes into the Compact RiO (I have a cRiO-9025).

    Hi Bilaln,
    I think you confused about a MATLAB script node and a Mathscript node.
    A MATLAB script nodes uses ActiveX to call into MATLAB, where as a Mathscript node runs in a NI built environment. The MATLAB script node requires both that MATLAB be installed and the host supports ActiveX. Since cRIO does not do either, you should use the MATHSCRIPT RT module.
    Joe Daily
    National Instruments
    Applications Engineer
    may the G be with you ....

  • PL/SQL scripts to capture real time performance usage

    Looking for a PL/SQL script to gather real time accurate information on memory, CPU, I/O stats for users accessing tables in Oracle 10g database on Red Hat Linux.

    Google Search - DBA Scripts
    1) http://www.oracle-base.com/dba/DBACategories.php
    2) http://www.dbazine.com/oracle/or-articles/liu2
    3) http://www.pro-dba.com/oracle_scripts.html

  • Matlab syntax errors are not caught and reported when code is executed in a LabVIEW Matlab script node

    I want to be able to catch errors that occur during the execution of Matlab code in a LabVIEW Matlab script node. According to my understanding of the documentation, errors of this type should be available at the "error out" signal point on the Matlab script node. I have noticed that even deliberately generating matlab syntax errors will not produce an error output. See the attached vi for an example.
    Attachments:
    matlab.vi ‏13 KB

    I ran your example VI and the is what I got in the Error Out cluster:
    "Code 1050
    Error occured while executing script. Error message from server: ??? This is an error
    . in matlab[1].vi"
    If you are generating custom error messages in Matlab I would suggest passing them back to LabVIEW through output variables in the script node.
    Chris_Mitchell
    Product Development Engineer
    Certified LabVIEW Architect

  • I cannot run the matlab script node in the labview

    Hi there,
    My LabVIEW version is 8.5, and matlab version is R2008a.
    I wrote a simple matlab code, like x= 1, y = x*2. Then I tried to put them into matlab script node in LabVIEW.
    However, when I ran the program, I couldn't run and Labiew show some error. 
    Then I tried the method talked before on this forum. Please see the following link.
    http://forums.ni.com/ni/board/message?board.id=MathScript&thread.id=571
    I followed the instruction and open the "command prompt," type some commands then I could run the program, and simultaneously, the LabVIEW program open "Matlab command line window" and run my labview code. However, if I didn't use the command prompt, the  "matlab command window" will not be opened by running the labview program. It would just show some error. And even if I turn on the matlab program in advance, I still couldn't run the labview program.
    Is there any effecient way to deal with this problem without using "command prompt?" Because I try another PC with both matlab and labview installed on it, I "can" run my simple matlab script node on it, and it will open the matlab command line window automatically by running my code. Therefore, I thought there might be some software linking problems in the previous PC I used . Do you have any ideas?
    Thanks in advacne.  

    Hi, and thanks for the post! I hope your well today.
    This may help,
    MATLAB® version 2006b (7.3) and version 2008a do work with LabVIEW
    8.20. This problem can occur if a new version of the MATLAB® software
    is installed along with a previous installation, which is then
    uninstalled. The uninstallation of the older MATLAB® software results
    in removing the ActiveX/COM components LabVIEW uses. This can cause the
    MATLAB® script node in LabVIEW to stop working. There are three
    solutions to this problem.
    Uninstall the MATLAB® software and reinstall it. This should install the necessary ActiveX component.
    Restore the MATLAB® automation server. Browse to the \bin directory (e.g. MATLAB\R2006b\bin) and type matlab -regserver ,
    which will reset the registry settings and start the server. The server
    can then be closed and the MATLAB® script node will work properly again
    in LabVIEW. LabVIEW may need to be restarted if VIs are open that
    contain MATLAB® script nodes.
    Leave both versions of the MATLAB® software installed.
    MATLAB® is a registered trademark of The MathWorks, Inc. Other
    product and company names listed are trademarks and trade names of
    their respective companies.
    Did you have an older version of MATLAB before 2008a?
    Kind Regards,
    James.
    Kind Regards
    James Hillman
    Applications Engineer 2008 to 2009 National Instruments UK & Ireland
    Loughborough University UK - 2006 to 2011
    Remember Kudos those who help!

  • "Waiting for real-time target (RT PXI target) to respond" error when the program waits interrupts

    Hi there,
    I have developed an application to detect interrupts generated by a electronic card and act in consequence. The program has been developed in labview but it calls a dll; that was created with labwindows. The dll is programmed to open the visa communication, enable events and install the interrupt handler and when an interrupt is detected, it reads the value of the different registers of the card and returns it to labview to visualize them. 
    The problem is that when the program waits for an interrupt, a prompt appears with the message "Waiting for real-time target (RT PXI target) to respond" and the only option I have is to click on the button to disconnect from the pxi or just wait. If I wait and I generate an interrupt, the prompt disappears and the application visualize the data like it was expected. 
    To wait for the interrupt the following code has been programmed in the function:
                    while (flag == 0)
                                    Sleep (1000);
    When an interrupt occurs, the value of flag changes to 1 and the function continue without any problem. I am not really sure, but probably here is the problem and probably this is not the best way to wait for an interrupt because the sleep function suspends the thread for the configured time, but at least the computing load in the PXI is between 0% and 1%. I was wondering if somebody knows how to wait for an interrupt without "lost" the communication with the PXI and if there is a better way to do it. 
    Any answer will be welcome and thanks for them,
    Jaime
    Solved!
    Go to Solution.

    Hello Naity,
    First of all, in which thread runs the waiting process? Is it scheduled in another thread than the function setting the flag?
    It scheduled in the same thread that I use to configure the communications and configure the card. Anyway, here is the pseudo code of the function interrupt that I programmed under labwindows,.
    char* interrupt(void)
    1. Open visa communications
    2.Install handler interrupt --> status = viInstallHandler (instr, VI_EVENT_PXI_INTR, IntrHandler, VI_NULL);   // the function IntrHandler will be called when an interrupt occurs
    3. Enable event PXI interrupt
    4. Wait
    while (flag == 0)
                  Sleep (1000);
    5. Visualize the data coming from the interrupt (registers and values measured with the card)
    6. Uninstall handler interrupt
    7. Close visa session
    The interrupt handler function IntrHandler is called immediately when an interrupt occurs and the pseudo code is like this
    ViStatus _VI_FUNCH IntrHandler(ViSession instr, ViEventType etype, ViEvent event, ViAddr userhandle)
    1. Disable some functions of the card to avoid damages. 
    2. Read registers and put them in a buffer
    3. Change the value of flag ---> flag = 1;
    In labview, I call the function interrupt with a call library function node (see the capture attached) and the program reads and saves the data from returned from the function.
    Secondly, I am not sure this method is the most elegant. You could for example register an event with the function and, insteand of setting a flag to 1, trigger the event and schedule it in another thread (if the function is thread safe). This could reduce your CPU Load even more and seem a bit cleaner to me.
    I've never used events before in labwindows but I will try to do it in this way. But anyway, I suppose that I should; somehow, wait the event to occurs in labview while the waiting for the event is programmed inside the dll...and probably the same prompt that i am trying to avoid is going to appear again, because I am not returning the "control" to labview (I mean, labview executes the dll and waits for the event to occur. Then the execution of the labview program is stopped in the call library function node executing the dll)
    Third point, which environment of development are you using?
    I am working with LV 2010 sp1 and Labwindows cv 10.0.1 and with the real time module.
    I did also another test, I divided the program in different functions, one to initialize the communication, another to wait until a interrupt has been detected and the other to obtain the data from the interrupt and close communications. With labview I call first with the call library function node the function to initialize, later I call inside a while loop the wait function like this
    int waitAseconds (double seconds, short stop_waiting)
    if(flag==1 || stop_waiting == 1)
    flag = 1; //to detect the stop_waiting button
    printf("flagAA =1 stop waiting = %d time = %d\n", stop_waiting, clock());
    return flag;
    else
    SleepUS(seconds*1000000);
    //a++;
    printf("flag a= %d stop waiting = %d time = %d\n", flag, stop_waiting, clock());
    return flag;
     and when the program detects an interrupt, the function returns to labview the flag and stops the loop. Finally, it reads the values and close communications. 
    In this way, the prompt appears but after running the application for 10 or 20 minutes and also i checked that there is a time gap between the executions in the loop.
    Thanks for your reply and your help,
    Jaime
    Attachments:
    capture.png ‏40 KB

  • Error 1050 by trying to use load'filename' in matlab script node

    Hi
    I keep getting error 1050 when Labview tries to load a text file through the matlab script node.
    I've all ready checked for it on google and this forum but found nothing. I've also done this: http://digital.ni.com/public.nsf/allkb/2B3FF46C8512C4F786256CF30071BE53 and tried to use dlmread and more. 
    The thing is that  I need the matlab script node to read a txt file that Labview made from a chart with only 1 array, plot it and export a jpg image. I can't really use the 'export image' or 'get image' function in Labview cause I need the whole plotted chart (these functions only take a snap shot of it when they're run).
    This is my code that I'm using:
     data=load('file') ;
    Vpp=(data(1:2000,1));
    xsize = (1/2000);
    plot(0.0005:0.0005:1,Vpp);
    axis([0 1 -5 5]);
    print('-djpeg', 'graph.jpg');
    The usual load in matlab to load txt files and print to print the jpeg. The code works in matlab but not in labview
    And yeah, I'm using windows 7 and legal versions of matlab r2009b and Labview 2009  
    Solved!
    Go to Solution.
    Attachments:
    matlab.jpg ‏213 KB

    Yes I forgot, this is my error...  It looks like it can't read the file path, but the 'file' path is actually just a path to my c:\user\*\*\*\*.txt 
    Error 1050 occurred at LabVIEW:  Error occurred while executing script. Error message from server: ??? Error using ==> load
    Unable to read file file: No such file or directory.

  • I can't find the MATLAB script node in labview

    We are using a MAC G4 with OS 9. We also have labview 5.1. I have looked under Mathematic>>Fomula in the tools palette and I cannot find the MATLAB script node.
    Is there an extra download that I need to get this MATLAB script node?

    The HIQ and MATLAB script nodes are only available in the full and professional development systems. If you have one of these versions, these nodes should be under the Mathematics>>Formula palette.
    If you have the base package of LabVIEW, you will not have access to these script nodes. Details about which options are included in which development packages can be found at:
    http://www.ni.com/labview/devchart.htm

  • MAX support of SNTP for Real-time controller​s

    Hey everyone,
    I have some PXI systems that allow me to enter a Time Server IP address directly into the MAX setup for the device but I have some other PXI chassis that don't. Does this have to do with the version of Real-time they are running? Can anyone tell me what version of RT and MAX started supporting Time Servers natively through MAX for real-time controllers?
    Thanks,
    Craig

    Hi craige,
    It looks like SNTP synchronization is not fully supported for PXI systems:
    http://forums.ni.com/t5/LabVIEW/Configuring-PXI-81​84-controller-to-synchronize-to-SNTP-server/td-p/1​...
    However, for CompactRIO, synchronization with SNTP servers began with LabVIEW Real-Time 8.6:
    http://digital.ni.com/public.nsf/allkb/F2B057C72B5​37EA2862572D100646D43
    The forum post I linked above does have some links to customer created examples relating to NTP and SNTP Time Servers.
    Please note that those examples are both unsupported and a little bit on the older side.
    Regards,
    Joel I.
    Applications Engineer
    National Instruments

Maybe you are looking for

  • MacBook Pro no longer boots Yosemite

    I have had Yosemite installed for about a week and everything seemed to be working fine. For some reason my laptop (MacBook Pro Early 2011) no longer boots. I have managed to install a new copy of OSX, but that didn't fix it. I also ran Disk Utility,

  • Quantity of SQL History shrinking

    I've noticed since about Dec. 2006 or Jan. 2007 that the quantity of SQL History kept has varied greatly and generally shrunk. In the last five days it has shrunk from 21 days to 10 days. I currently only have 47 entries in SQL History. I estimate th

  • Help with data merge from Excel

    I think it's easiest to first explain the project... I am working on a print project that has an excel file containing specific data per person. The data gives FirstName, LastName, Picture, About, Phone, etc. per person (over 100 people) I am making

  • Unknow issue - please help- Failed logs state failed attemps by unknown user for async??

    Hi all, I seem to be getting lots of failed attemps in my logs that look below.. We have checked the particular device and theirs nothing plugged into it? Any help would be great.. i have checked this post but there was no valid answer.. https://supp

  • JPopupMenu SelectionManager error!

    The following little test program results in both Exception, and or VM crash!!!! import javax.swing.*; import java.awt.event.*; class Pop{ JDialog m_dialog; JPopupMenu m_menu; public static void main(String[] args){ new Pop(); public Pop(){ m_dialog