Matlab specgram in labview

Hello,
I am trying to implement the function specgram of matlab in Labview.
In matlab I enter a sound signal  sig1 (50.000 x 2 array) with a sampling rate Fs1 =  22050.
I also define a window size of 512.
I execute b1 = specgram(sig1(:,1),windowsize,Fs1);
The result  is a 2D complex double array.
Now i am trying to implement the same function in Labview.
I have already tried to use the STFT function  or the FFT function in labview but I don't get close to the results I get from matlab.
Attached:
An ASCII file with the input signal: sig1.txt
Two ASCII files with the output of the matlab code:
b1real.txt --> The real part of the output
b1imag.txt --> The imaginary part of the output.
The matlab code: Matlab.txt
Thanks in advance for any kind of help
P-J
Solved!
Go to Solution.
Attachments:
Specgram.zip ‏1140 KB

Hello P-J,
I don't completely get your logic.
It seems that I'm missing something in your explanation.
In your original matlab-code you're performing the specgram function on the 1D array sig(:,1).
Therefor in LabVIEW it would be logic that you want to perform a similar function on the same 1D array.
Otherwise any comparison results will not make alot of sense.
Please also note that it's very dangerous to say that audio signals are the same on the left and the right side of a stereo-signal.
This often is not the case and could lead to incorrect interpretations of correct measurements.
Are you using the specgram function from the Signal Processing Toolbox?
http://www.engmath.dal.ca/courses/engm6610/notes/specgram.html
Or are you using another version of the specgram function?
If you're using this version of the specgram function, then the special length of the matlab-function can be explained by this line on the website above:
If a is real, specgram computes the discrete-time Fourier transform at positive frequencies only. If n is even, specgram returns nfft/2+1 rows (including the zero and Nyquist frequency terms). If n is odd, specgram returns nfft/2 rows. The number of columns in B is
k = fix((n-numoverlap)/(length(window)-numoverlap))
This completely explains the number of rows you get over here.
On the other side the STFT function will calculate a short time Fourrier transform (http://en.wikipedia.org/wiki/Short-time_Fourier_transform)
This is different from the DTFT (http://en.wikipedia.org/wiki/Discrete-time_Fourier_transform) used in your original specgram function.
I think you might have overlooked these differences.
A short summary of different kinds of FT's can be found over here:
http://narnia.cs.ttu.edu/drupal/node/46
Is there a specific reason why you need to have exactly the same calculation?
Coming back to what is going wrong in your VI I can explain this quite easily.
First take a look at this page:
http://zone.ni.com/reference/en-XX/help/371361H-01/lvanls/stft_spectrogram_core/
Over here you see that they give the following definition:
time steps specifies the number of samples to shift the sliding window.
This should not be -1 if you want to have a similar calculation. It should be equal to the numoverlap parameter used in the specgram function.
After a short calculation you can find that in your original specgram calculation this was 256.
Please also redo this calculation at your side and check if you get a similar result.
One last word about the comparison is the following:
-       In LabVIEW the STFT function returns the actual magnitude of the spectrogram.
-       The specgram function returns the windowed discrete-time Fourier transform of a signal using a sliding window. The actual spectrogram is the magnitude of this function.
In your last e-mail you note that you are not allowed to install/use MathScript.
Are you sure you’re not confusing Matlab (non-NI software) with Mathscript (NI software: http://sine.ni.com/nips/cds/view/p/lang/nl/nid/207300) ?
Most likely the MathScript RT Module is already installed with your LabVIEW installation.
If it’s not, then most likely you should be allowed to use it with your license.
Can you share your serial number privately with me?
That way I can check if you should be allowed to use the MathScript RT Module.
Kind Regards,
Thierry C - Applications Engineering Specialist Northern European Region - National Instruments
CLD, CTA
If someone helped you, let them know. Mark as solved and/or give a kudo.
Attachments:
STFT - adapted.vi ‏15 KB

Similar Messages

  • How to use matlab function with labview?

    Hello,
    I just want to use some matlab functions like floor(),ones()... in my labview code, who can tell me how to do it?
     I want to only install MCR in my PC, so MATLAB script node can not work because it need matlab installed. 
    Thanks
    Solved!
    Go to Solution.

    floor() exists on the standard labview pallet already and the ones() function would be fairly simple to reproduce. If you only need a few basic functions repost asking for direction on recreating those specific methods. However, you're right - there is not a direct way to use compiled matlab code in labview without full matlab and the math script nodes. If you're really desparate to reuse some some exisiting IP there are C++ alternatives that implement many of the same methods and syntax as matlab (http://arma.sourceforge.net/faq.html). I'm fairly sure there are other tools that attempt to translate matlab code into pure c functions, both of which can be called via a DLL from within labview: https://decibel.ni.com/content/docs/DOC-9076
    Alternatively, here is an all NI linear algebra solution: http://sine.ni.com/nips/cds/view/p/lang/en/nid/210525

  • Same code gives different results in Matlab Script in Labview and Matlab

    I am implemeting a Matlab code into a LabVIEW application using Matlab script. When I import the exactly same code to the Matlab Script in LabVIEW it gives a different result than it is in Matlab. This code is a simulation code including first kind bessel functions. Using LabVIEW 7.1 and Matlab R14 service pack 3.

    Labview 8.5
    Matlab R2009b
    Attached are the graphs produced by matlab script in labview and in matlab.
    The minimum of graph produced by matlab code is below 1 and that in labview is above 1.
    Thanks a lot for your reply.
    Sorry, I haven't quantified the "sometimes" yet. 
    Attachments:
    matlabsResult.jpg ‏29 KB
    LV.png ‏84 KB

  • How to use a Matlab Program within Labview

    Hi
    I saw in this forum that many users are using some matlab program
    executed in Labview program. I have actually Labview 7.1 and would like
    to use some of my matlab program in Labview. Is there an easy way to do
    it ?
    Thanks
    Thomas

    The MATLAB Script function is kinda buried in the function palette, and
    can be found under Functions >> Analyze >> Mathematics
    >> Formula.  Unfortunately this feature is not available in
    the LabVIEW Base package.  Hope this helps!
    Andy F.
    National Instruments

  • Using Matlab code in LabVIEW

    Hi,
    I have never used LabVIEW and I am wondering if there is a way to run Matlab code in LabVIEW. If so, how would I do it and are there any special instructions or tips I should know about?

    What is your LabVIEW version?
    Do you have matlab installed on your computer?
    In older LabVIEW versions, you can only use the matlab script node, which requires that you have a copy of matlab installed.
    In newer versions, you have two more alternatives that don't require the purchase of Matlab:
    Use a mathscript node.
    Use a scilab script node.
    Information on mathscript: http://zone.ni.com/devzone/cda/tut/p/id/3502
    Information on scilab: http://zone.ni.com/devzone/cda/epd/p/id/657
    There is even a mathscript forum here: http://forums.ni.com/ni/board?board.id=MathScript
    LabVIEW Champion . Do more with less code and in less time .

  • Using Matlab script in Labview

    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.
    Solved!
    Go to Solution.
    Attachments:
    Labview&Matlab.vi ‏55 KB

    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.
    Attachments:
    Script_Error.JPG ‏133 KB

  • How to use matlab code in Labview without having MATLAB software. I tried to convert .m files into .dll files. But i could not do. Please help me out..

    Please help me out...
    Solved!
    Go to Solution.

    bombay wrote:
    Yes. It can be done. But Math script can not evaluate all functions in .m files (There are some exceptions).
    And those can perhaps easily be ported to LabVIEW/MathScript?
    It is not sufficient to disregard running your Matlab code in LabVIEW based on a few exceptions without first thoroughly evaluating the impact they have.
    If you want to stick with Matlab in your implementation, then there are other avenues than hypotethizing about the limited portability issues of using MathScript in your project?
    Br,
    /Roger

  • Problems of integrating Matlab functions in Labview

    Hi,
    Does anyone know how to completely integrate Matlab functions into Labview program without a copy of Matlab in the system when I run the entire program?
    Initially I used 'Mathscrip' node but I heard that it doesn't support Matlab toolbox.  Thus, I tried out the other option 'Matlab script' node. This node works well in implementing Matlab functions but it indeed requires Matlab installed in the system. 
    So in other words, how could I realize the full integration(as what Matlab script node achieves.)  without Matlab installed in the system?   
    Cheers,
    Nicholas 

    hi smercurio,
    So you mean that the Matlab script is no longer necessary in my case right?
    Could I just ask my colleague to compile his codes to matlab dll and I use the Call Library Function Node  instead of Matlab script to call it?
    About MCR, is it the correct source at the following link  http://www.mathworks.com/matlabcentral/fileexchange/5268 ?
    Sorry for those basic queries in Matlab as I have very little experience in it. lol... thanks a lot.
    Cheers,
    Nicholas 

  • Matlab script in Labview

    Hi there,
    I want to integrate my Matlab script in Labview,
    the input variable should be a Matrix like
    the following A = [ 0 256 ; 1 256 ;1.5 100 ; 1.55 110; 1.59 55; 1.6 56 ; 9 256; 14 256 ;15 100 ]
    How do I do this in Labview, I tried an array but
    no succes...
    Bye for now

    hi chris .. thanks for the reply ...
    here's the results from 'ver
    MATLAB Version 7.0.1.24704 (R14) Service Pack 1
    MATLAB License Number: 227039
    Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 2)
    Java VM Version: Java 1.4.2_04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM
    MATLAB                                               
    Version 7.0.1      (R14SP1)
    Simulink                                             
    Version 6.1        (R14SP1)
    Aerospace
    Blockset                                   
    Version 1.6.1      (R14SP1)
    Bioinformatics
    Toolbox                               
    Version 1.1.1      (R14SP1)
    CDMA Reference
    Blockset                              
    Version 1.1        (R14SP1)
    Communications
    Blockset                              
    Version 3.0.1      (R14SP1)
    Communications
    Toolbox                               
    Version 3.0.1      (R14SP1)
    Control System
    Toolbox                               
    Version 6.1        (R14SP1)
    Curve Fitting
    Toolbox                                
    Version 1.1.2      (R14SP1)
    Data Acquisition
    Toolbox                             
    Version 2.5.1      (R14SP1)
    Database
    Toolbox                                     
    Version 3.0.1      (R14SP1)
    Datafeed
    Toolbox                                     
    Version 1.6        (R14SP1)
    Embedded Target for Infineon C166 Microcontrollers    Version 1.1.1      (R14SP1)
    Embedded Target for Motorola
    HC12                    
    Version 1.1.1      (R14SP1)
    Embedded Target for Motorola
    MPC555                  
    Version 2.0.1      (R14SP1)
    Embedded Target for OSEK
    VDX                         
    Version 1.1.1      (R14SP1)
    Embedded Target for TI C2000
    DSP(tm)                 
    Version 1.1.1      (R14SP1)
    Embedded Target for TI C6000
    DSP(tm)                 
    Version 2.2.1      (R14SP1)
    Excel
    Link                                           
    Version 2.2.1      (R14SP1)
    Extended Symbolic
    Math                               
    Version 3.1.1      (R14SP1)
    Filter Design HDL
    Coder                              
    Version 1.1        (R14SP1)
    Filter Design
    Toolbox                                
    Version 3.1        (R14SP1)
    Financial Derivatives
    Toolbox                        
    Version 3.0.1      (R14SP1)
    Financial Time Series
    Toolbox                        
    Version 2.1.1      (R14SP1)
    Financial
    Toolbox                                    
    Version 2.4.2      (R14SP1)
    Fixed-Income
    Toolbox                                 
    Version 1.1        (R14SP1)
    Fixed-Point
    Toolbox                                  
    Version 1.1        (R14SP1)
    Fuzzy Logic
    Toolbox                                  
    Version 2.2        (R14SP1)

  • Relations between Matlab structures and LabVIEW clusters

    I have a DLL created with Mathworks COM Builder, used as an ActiveX component in LabVIEW. Thus, I am able to have my Matlab functions inside LabVIEW. However, I have a problem regarding the pass of parameters between Matlab and LabVIEW.
    When the Matlab functions parameters are simple -DBL, DBL arrays, strings-, there is no problem. LabVIEW does the right translation. But I have not been able to pass a Matlab structure to LabVIEW, which counterpart I think it would have to be a cluster. To solve this situation I need to split the structure components and pass them separately.
    Does anyone know how to do it without the workaround?
    Thanks in advance and have a good day,
    spj

    Hello Tishu,
    1)       Can we use nested for loop in Mathscript node?
    1) Yes you can. Remember that loops should be avoided as much as possible in m-scrips. Most of the times you can use vectorization to represent same task.
    2)       Which one of these is feasible: 1) Matlab script node
                                                              2) Mathscript node
    2) What exactly is the "Feasable" question? Real time (see below) or nested loops (see above)
          3)  Is there any other way to interface between matlab and LV for real time signal processing?
    3) Real time is different depending the application. Some applications need ns or ps real time (RF appls) others need seconds delay. Real time means "determinism". That a task will execute in a know time with little jitter. Windows is not a real time OS therefore nothing in it will operate in real time. Can you tell us something about the signal your are processing (Audio, Image fps, Radar)?
          4)  Suppose X is 1D array (DBL) in Labview. And Mathscript code is as below:
    For i=1:inf,  4) Is this vector a valid one? inf = Inf which is different from 1/eps.
    Y= X-1;
    end
    Here X is input and Y is output.
    Such code does not produce output (Y variable) in real time processing.
    Does it wait till the FOR LOOP ends?  Is there any solution to such problem? 5) What is this suppose to produce?
    Let me know,
    yardov
    Gerardo O.
    RF Systems Engineering
    National Instruments

  • Calling a VB Script and Matlab code from LabVIEW GUI.

    Hi,
    Can anyone help me out in Calling a VB Script and Matlab code from LabVIEW GUI? GUI will be developed in Labview and currently we have some scripts written in VB and Matlab and we need to incorporate the same through LabVIEW. Can anyone let me know how this can be implemented? 
    Regards,
    Sharmash

    For VBScript you can call the Windows Scripting Host application using the System Exec function, or you can use IScriptControl, which is an ActiveX control. Be aware that with the IScriptControl there's a small bug. You can read more about it in this post.
    For Matlab, there's a Matlab node that you can use. You can either copy and past your Matlab script in the node, or just write a function call statement. The node simply calls Matlab. Or, you can do as suggested and use the MathScript node, which is basically an alternative to Matlab. The MatchScript node doesn't support everything that Matlab does, so you will need to check it against your script.
    Or, you can do as suggested, and rewrite it all in LabVIEW, unless you can't because these scripts are used by other applications.

  • Matlab routine within labview cannot get input after a few hours of use. What can be the trouble?

    I have a Matlab-within-Labview application that needs to run 30-40 times in a row. However after let's say 10 runs I get error 1047, that is, there is no communication between Matlab and Labview. I have to reset the computer to start re-running the application without problem. Note that Matlab is open on this computer all the time.

    Hello,
    The only information I could find on this from NI or MWorks is that MATLab must be running in order for LabVIEW to access the Matlab server. I would check to see if there is anything specific happening inbetween the 10 and 11th runs that causes the link between the Matlab server and LabVIEW to break, isolate where this happens and try to work from there.
    Doug

  • Creating .mat files with Matlab dataplugin in LabVIEW

    I am trying to create a .mat file in LabVIEW using the Matlab dataplugin. It appears to create a group called "Vector" without being told to, and it also concatenates group and channel names together. I have made an example to demonstrate this behaviour. I am trying to create a group called "Group" and inside it a channel called "Channel". What I get looks like a group called "Vector" and inside it a channel called "GroupChannel". What am I doing wrong?
    Best Regards,
    John Sackett
    Solved!
    Go to Solution.
    Attachments:
    write mat example.zip ‏54 KB

    Hello John
    Thank you for getting in touch regarding your issue. I am an applications engineer here at National Instruments, as I understand you are using the data plugin for Matlab within LabVIEW, but as shown with your code when you label the channel or group you get an outcome which you don't expect.
    I have opened and had a look at your code and can see where the issue is arising. The functions you are using are normally used with TDM files, .MAT files are compatible but there are a few differences between the file formats, which is why you are getting the outcome we have seen. A TDM file has headers named channelgroup and channel, but Matlab does not have the channelgroup header in the file type and therefore the functions in LabVIEW merge the 2 strings to the available header.
    I am not able to open your .MAT file so could you give me a brief description of what occurs inside Matlab?
    Have you looked into using the script node to allow for .MAT file types in LabVIEW? Here is the help file
    I have also found some resources which you may find useful.
    LabVIEW to MATLAB
    Convert file
    Open .MAT in LAbVIEW
    DataPlugin
    Let me know if you would like any further information
    Regards
    Stephanie L
    Applications Engineer
    National Instruments UK and Ireland

  • Running matlab mfile in labview 8.2

    Hi
    i am working in a project using basically labview 8.2 and i wrote a program in matlab R2008(m file)and i want to run this file in my labview program; i also load this program into mathscript window but it didn't work because the m file contains many functions; i was wondering if you can please help me in this manner.
    looking forward to recieving from you
    Solved!
    Go to Solution.

    worked ok, with me... attached image shows your script, copied and pasted into a mathlab formula node, and the program running asking for the xls file.
    did you get that far? if you did, send us the xls so we can go on testing more
    Do you not have the mathlab script formula node? should be in  Mathematics>>scripts and formula nodes>>mathlab script node.
    (if you don't have it please tell me) 
    Attachments:
    Dibujo.jpg ‏120 KB

  • Problem in creating the simulation dll using SIT 2.0.3,matlab 7.1,labview 7.1

    I am currently using SIT 2.0.3 ,using this toolkit i am trying to create the simulation DLL for labview.but i am getting the following error in matlab command window
    Error: File: C:\SimulationInterfaceToolkit\ModelInterface\basic.tlc Line: 117 Column: 7
    Undefined identifier ReleaseVersion
    Error: File: C:\SimulationInterfaceToolkit\ModelInterface\basic.tlc Line: 117 Column: 25
    The == and != operators can only be used to compare values of the same type
    Error: File: C:\SimulationInterfaceToolkit\ModelInterface\basic.tlc Line: 260 Column: 26
    Undefined identifier ReleaseVersion
    Error: File: C:\SimulationInterfaceToolkit\ModelInterface\basic.tlc Line: 260 Column: 44
    The == and != operators can only be used to compare values of the same type
    Is this a version problem?
    I am using
    Simulation interface toolkit 2.0.3
    Matlab 7.1.0.246(R14) Service pack
    Real time workshop V.6.3
    Labview 7.1
    Microsoft visual C++ 6.0
    Can anybody help me to solve this issue.

    Hi Jayasheela,
    Here are the Read Me files for different versions of Simulation Interface Toolkit. Usually, the toolkit will only work with the versions of software that are explicitly stated.
    Simulation Interface Toolkit 3.0 Readme
    The MathWorks, Inc. MATLAB® / Simulink® application software release 13.x or 14.0, 14.1, 14.2, 14.3
    The MathWorks, Inc. Real-Time Workshop® release 13.x or 14.0. 14.1, 14.2, 14.3
    Microsoft
    Visual C++ 6.0. You can use Microsoft Visual C++ .NET 2003 only if you
    installed the LabVIEW 7.1.1 maintenance release.
    National Instruments LabVIEW Real-Time Module 7.1.x for ETS Targets.
    (Optional) National Instruments LabVIEW FPGA Module 1.1.x, for customized FPGA VIs used in real-time simulations involving FPGA devices
    Simulation Interface Toolkit 3.0.1 Readme
    The Simulation Interface Toolkit (SIT) 3.0.1 updates SIT 3.0
    to support LabVIEW 8.0, the LabVIEW 8.0 Real-Time Module, and the
    LabVIEW 8.0 FPGA Module. You also can use SIT 3.0.1 with LabVIEW 7.1.x. However, you cannot install SIT 3.0.1 for both LabVIEW 8.0 and LabVIEW 7.1.x.
    Simulation Interface Toolkit 3.0.2 Readme
    The Simulation Interface Toolkit (SIT) 3.0.2 updates SIT 3.0.1
    to support LabVIEW 8.2, the LabVIEW 8.2 Real-Time Module, and the
    LabVIEW 8.2 FPGA Module. You also can use SIT 3.0.2 with LabVIEW 7.1.x or with LabVIEW 8.0.x. However, you cannot install SIT 3.0.2 for more than one version of LabVIEW on the same computer.
    This maintenance release also adds support for the following products:
    The MathWorks, Inc. MATLAB® / Simulink® application software R2006a.
    The MathWorks, Inc. Real-Time Workshop® R2006a.
    If you install SIT 3.0.2 for LabVIEW 7.1, you can use
    Microsoft Visual C++ 6.0 to convert models to model DLLs. If you
    install SIT 3.0.2 for LabVIEW 7.1.1, 8.0, 8.0.1, or 8.2, you can use
    either Visual C++ 6.0 or Visual C++ .NET 2003.
    Simulation Interface Toolkit 4.0 Readme
    The MathWorks, Inc. MATLAB® / Simulink® application software release 13.x, 14.x, or 2006a, 2006b, 2007a
    The MathWorks, Inc. Real-Time Workshop® release 13.x, 14.x or 2006a, 2006b, 2007a
    Microsoft Visual C++ 6.0 or .NET 2003
    You can also take a look at this KnowledgeBase article, which condenses some of the previous information.
    MATLAB®, Real-Time Workshop®, and Simulink® are the registered trademarks of The
    MathWorks, Inc. Further, other product and company names mentioned herein are
    trademarks, registered trademarks, or trade names of their respective companies.
    Amanda Howard
    Americas Services and Support Recruiting Manager
    National Instruments

Maybe you are looking for