LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a filter using mathscript transfer function in labview

Solved!
Go to solution

Dear all,

 

I am currently designing a filter in labview using a Mathscript looping. The filter can be represented in transfer function. I have attachted the transfer function equation together with its value and the desire frequency vs. amplitude graph that I should obtained from it. Also, following are the transfer function written in Matlab.

 

B1= tf ([57.5221845],[1 51.017077 205.1868]);
B2 = tf ([1 0],[7.6991]);
B3 = tf ([1 0],[14.32433403]);
B4 = tf ([1 0],[137.6017]);

F = B1 * ( (1+B3)/((1+B2)*(1+B4)));

plot(F)

 

 

I have also modify the coding as Labview Mathscript does not support the Matlab coding "tf" as transfer function to "bilinear"

 

Problem I am facing are:

1) Unable to display the graph of the filter in labvie.

2) Unable to have sinewave as an input to the filter.

3) The output cannot be display in graph format. 

 

Hope to have the soonest reply from you guys. Many thanks in advance  Smiley Wink

 

Download All
0 Kudos
Message 1 of 9
(4,761 Views)

First a lot of clarification is needed. I have done similar things, and it is not that difficult.

 

1. If you have MATLAB installed on the same computer, why not use MATLAB node within LabVIEW instead of Mathscript node, that will ensure your syntax, and toolbox within MATLAB is accurately followed.

 

2. Your filter funtion will return a scalar, as I tried it in MATLAB, using FS of 1k, and x =1, because your x is a scalar in your VI, I guess your x should be a vector,and not a scalar.

 

3. a more technical way, and direct way is to use the filter object in MATLAB, then use the freqz funciton to plot the frequency response.

 

Perhaps if you can enumerate the steps you want to follow in writing, I can help you write the code.

0 Kudos
Message 2 of 9
(4,750 Views)

Thank you again for offering to help me in writing the code.


I suppose that I should do a frequency sweep on the transfer
function to prove that it behave as the sample graph. Example, if I have an input sine
wave with the frequency of 8.8Hz passing through the transfer function filter, the
output that I should be getting is 1 according to the transfer function graph
and of cause the frequency range of my input sine wave would only be between
the ranges of 0.5 Hz to 30 Hz.


 




0 Kudos
Message 3 of 9
(4,737 Views)

Hi ade77,


Thanks for the prompt response to my
thread.

About the Matlab node, I’ve

tried to have the output as graph and setting the FS to 1000 and input (X) as
sine wave with a frequency of 8.8 Hz. Realized that there is not plotting made
on the graph.

 

I cannot actually use the signal
analysis filter to represent my transfer function because I do not know the
type, number of order, and the cutoff frequency. Relized that the filter is not
exactly a perfect bandpass filter.



I am sorry that I might be asking
some very basic question as I am pretty new to Labview.Thank you again in
advance for your help.



 

 

0 Kudos
Message 4 of 9
(4,736 Views)

I have attached a slightly modified form of your LabVIEW code. 

 

1.  the simulate express VI will not work in this case, you need to generate an array of sine wave, so I used "sine wave vi"

 

2.  since you want a freq range of 0.5 to 8.8 Hz, I set the freq control knob to that range, you can do that by right clicking the control, under properties, then scale.

 

3. Your output c was initially set to 2D array, I changed it to 1D array, you might have a good reason for using a 2D

 

However, the output of the filter is kind of weird, this was also what I got when I run the code only in MATLAB, so I presume the problem might be your bilienar and convolution functions. You might want to play around with it, and see if you can improve the result.

 

Also, note that when you adjust the freq of the input sine wave, it might display someone on the graph, like a straight line sometimes, there is nothing wrong with the graph, it is just the scale and the freq.

 

Let me know of your suggestion, then I would add my commnets. Also, be aware that I have forgotten the mathematics of this subject

 

Ade

0 Kudos
Message 5 of 9
(4,717 Views)

Thanks again for the fast reply.

 

I'm currently using LabVIEW v8.5, unable to open your VI. I will go to my friend's place later as he is using LabVIEW v8.6

 

I suppose from your explaination, I need to generate an array of sine wave as the input instead of using simulate express VI. 

 

Thanks again and I'll get back once I have go through the modified VI.

0 Kudos
Message 6 of 9
(4,704 Views)
Solution
Accepted by topic author wengyew
I have attached the 8.5 version
0 Kudos
Message 7 of 9
(4,694 Views)

Hi there,

 

Sorry to only get back to you after so long. Yes! The method you introduced to me helps a lot in solving my problem. By the way, why is the sine wave generated does not behave like it should be. At times, it seems to appear like a modulated waveform.

 

Thank you very much! 

0 Kudos
Message 8 of 9
(4,602 Views)

The sine wave  is correctly generated. The problem is just the way the graph indicators displays the waveform. If the frequency is too low or high it will dispaly it weird.

 

You will need to adjust the scale, or manually increase the size of the graph indicators.

0 Kudos
Message 9 of 9
(4,578 Views)