SignalExpress

cancel
Showing results for 
Search instead for 
Did you mean: 

Sth about FFT Spectrum (Mag and Phase)

Hi,
 
I am using the FFT Spectrum (Mag and Phase) to get the magnitude and phase infos but the help file says that " Note  The single-channel version of this VI is intended primarily for continuous processing of a single channel. Do not generalize this behavior to the multichannel case and use the single-channel version in a For Loop to continuously process multiple channels by indexing an array of waveforms." I do not why?  If I wanna do some series signal, I mean I wanna do FFT M times for M series of the signal with the same length, what I should do?
 
The attach file is my vi. 3x.
 
Huihui
 
 
0 Kudos
Message 1 of 13
(8,486 Views)
Hi Huihui,
 
I took a look at your VI but it is incomplete as you are missing an input signal.  It looks like you are trying to get the magnitude and phase of a signal.  Have you considered using the Spectral Measurements Express VI?  From the looks of your VI, you want to take individual points and manipulate them mathematically.  One thing you will run into is the issue of indexing an array into a formula node.  See this knowledge base article on how to do this.
 
I hope this helps,


Message Edited by Ima U on 03-26-2008 03:43 PM
Regards,

Ima
Applications Engineer
National Instruments
LabVIEW Introduction Course - Six Hours
Getting Started with NI-DAQmx
0 Kudos
Message 2 of 13
(8,464 Views)
Hi,
 
Thanks for your reply.  I wanna do some mathematical calculations about the magnitude and phase so I can not use the Spectrum Express VI directly. Now, I am using the Mathscript and there is a conflict, see the attached vi. The output of FFT Spectrum (Mag-Phase) is an array from 0 to 1023, right? I am not sure about the index range of the output. But the index in Mathscript should be positive integer. So I will miss to get the first signal of the Phase output. Can you tell me if there is any other method?  Does the formula node require that the index of the array should be positive one.  Thanks.
 
 
0 Kudos
Message 3 of 13
(8,445 Views)
Hello Huihui,

The magnitude and phase outputs from the FFT Spectrum (Mag-Phase) VI should be arrays containing 1024 elements.  When you bring the arrays into MathScript, they still contain 1024 elements.  The only difference is, as you note, indexing the array in LabVIEW begins at 0 and in MathScript at 1.  This should not cause you to miss any elements of either array.

From briefly looking at your code, there is a problem with indexing angleP(k-1) and absP(k-1).  This is because k is the loop index variable and has values from 1 to 1024.  However, when you subtract 1 from it, it is no longer a valid array index.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 4 of 13
(8,430 Views)
Hi,
 
Thanks for your reply.
 
I am confused now. As you said, the labview begins with 0, so the angleP is from 0-1023, however, in the Mathscript the index begins with 1. So I should use index k not k-1. But when I use angleP(k) in the Mathscript, the errors says the indexs are out of bounds for the variable you specified cause angleP is from 0-1023.  So that is the problem--how to deal with the different index range problem.
 
I tried to finish this mathematical problem in formula node but there is still error but I do not know where it is wrong. Can you help me to point out the problem in the formula node. Thanks.
 
Huihui 
0 Kudos
Message 5 of 13
(8,426 Views)
Hi,
 
Thanks for your reply.
 
I am not sure if I attached the right vi so I wanna attach it again.
 
I am confused now. As you said, the labview begins with 0, so the angleP is from 0-1023, however, in the Mathscript the index begins with 1. So I should use index k not k-1. But when I use angleP(k) in the Mathscript, the errors says the indexs are out of bounds for the variable you specified cause angleP is from 0-1023.  So that is the problem--how to deal with the different index range problem.
 
I tried to finish this mathematical problem in formula node but there is still error but I do not know where it is wrong. Can you help me to point out the problem in the formula node. Thanks.
 
Huihui
0 Kudos
Message 6 of 13
(8,423 Views)
Hello Huihui,

There are many problems here.  The 1D array representing the phase exists in LabVIEW.  If you were to index this array, the valid indices are 0-1023 as you mention.  However, there are 1024 elements.  When you wire this into a MathScript node, there are still 1024 elements, but now you index them from 1-1024.  Index 0 in LabVIEW will return the same element as index 1 in MathScript.  I am not sure about the out of bounds error if you have replaced index k-1 with k.  Since the example you posted is now using the formula node, let's investigate that instead.

The formula node uses a C-like syntax.  In LabVIEW MathScript, you generally can execute scripts written in the MATLAB® language syntax.  However, the MathScript engine executes the scripts, and the MathScript engine does not support some functions that the MATLAB software supports.  It looks like you are mixing the syntax between the two nodes.  Try viewing the LabVIEW help topic "Formula Node Syntax."  To view it, go to "Help >>  Search the LabVIEW Help..."  Click on the index tab and type "formula."  Under the "Formula Nodes" list, double-click "syntax."

Some things to note in the formula node:
  • Indexing begins at index 0, as with LabVIEW and C.
  • You need to declare variables to be an array using C-like syntax (e.g. int32 a[3][4];)
  • Array indexing uses square brackets in C-like syntax, not parentheses.
  • Multi-dimensional arrays are indexed using several sets of square brackets in C-like syntax, not separated by commas within parentheses.
After fixing these things, I don't see any other problems with the script you posted.

MATLAB® is a registered trademark of The MathWorks, Inc.

Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments
0 Kudos
Message 7 of 13
(8,387 Views)
Hi,
 
Thanks for your reply. Your help is useful. I should say that I attached the wrong vi last time so it seems that I did nothing. Sorry about that.
 
Now I have solved the problem in the formula node but there are some problems of connection between the formula node and Mathscript and the error says that the wire connects two different types. The output is a 2D array but I do know how to change the input of the Mathscript to 2D array. Is the default type of the input of the Mathscript scalar? In the Mathscript, I wanna do some signal processing with array.  Thanks.
 
Huihui
0 Kudos
Message 8 of 13
(8,372 Views)
Hello,

You have identified a bug with the MathScript node.  It is not possible to change the input type to the MathScript node.  It automatically adapts if the incoming data is compatible with a type that LabVIEW MathScript can work with.  The problem is that the formula node outputs a fixed-size array and MathScript doesn't understand it.  I have filed a bug report for this issue.

In the meantime, a workaround is to allocate the array outside of the formula node and simply pass it into and out of the formula node.  See the screenshot below.



Grant M.
Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments


Message Edited by GrantM on 04-04-2008 11:09 AM
0 Kudos
Message 9 of 13
(8,355 Views)
Hi,
 
Thanks for your help. Now I have other questions in the attached vi. Please forget other frame just focus on the Mathcript.
 
1. I wanna make sure that the output of FFT is from 0-2047 and I can read the data from 1 to 2048 in the Mathscript, right? I mean the beginning index 1 in the Mathscript responsed to 0 in the output of FFT, right?
 
2. The error says "Tunnel: missing assignment  to tunnel". I think it is related with the maxindex in the  Array Max&Min in the True frame.
 
Thanks.
 
Huihui
 
 
0 Kudos
Message 10 of 13
(8,272 Views)