LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

MathScript fir1 function vs. LabVIEW FIR VI

Hi, I'd like to convert some Matlab/LabVIEW Mathscript function into LabVIEW block functions, because it's faster.
One of the function I'm not sure is the FIR function: I have a Mathscrip function fir1(n,W), is "FIR windowed coefficients" its LabVIEW equivalent?  If yes, how should I match the parameters (e.g. is W the high or low curoff frequency? is Order n the same as the number of taps)? If no, which LabVIEW function should I use?
Thanks.
0 Kudos
Message 1 of 7
(8,556 Views)
Hi,
 
The corresponding VI in LabVIEW is FIR Windowed Coefficients VI. For the simple case b = fir1(n, w), you can use the way as the attached snapshot illustrates.
0 Kudos
Message 2 of 7
(8,531 Views)
This is great. Thanks!

Somehow I don't quite understand the reason behind some of the LabVIEW settings (e.g. why the sampling frequency needs to be 2 in order to match the MathScript function, why the number of taps is 1 higher than the order in the fir1, and how the scaling works), but it works!


0 Kudos
Message 3 of 7
(8,527 Views)
Hi,
 
Here are answer to your questions.
1. In most MathScript functions, the Nyquist frequency is supposed to be 1. That is to say, you need to set sampling frequency to 2 in LabVIEW VI.
2. In MathScript, n specifies the order of filter. However, in LabVIEW, taps determines the total number of filter coefficients. That is why you need to increment 1 to match n with tab.
3. By default, fir1 scales the filter coefficient according to its type. You can also direct MathScript not to scale the filter coefficient by specify option to be 'noscale'.
0 Kudos
Message 4 of 7
(8,524 Views)
Thank you very much for the explanation! It's very helpful.

Would you be able to help with "translating" another MathScript/Matlab function into LabVIEW VI? I cannot find a suitable block function for "freqz(b)". I tried it using 3 steps: firstly using "FIR filter" function to apply the filter coefficients b into a filter, then apply a constant signal and get its filtered signal using this filter, and thirdly use the original constant signal and the filtered signal in "Frequency Response Function (Mag-Phase)" to get its frequency response. However it doesn't work. Could you give me some suggestions? Thanks in advance.

PJI
0 Kudos
Message 5 of 7
(8,521 Views)

Hi,

freqz is a little complicated. I do not know any counterpart in LabVIEW. Maybe, you can find it in Digital Filter Design toolkit.

I think the possible way to do is to calculate the frequency response of a filter from its mathematical definition.

0 Kudos
Message 6 of 7
(8,516 Views)
Thanks for the reply and advice.
I guess I will just leave this part in a small MathScript window in my VI.
0 Kudos
Message 7 of 7
(8,514 Views)