Showing posts with label scilab. Show all posts
Showing posts with label scilab. Show all posts

Monday, May 25, 2009

Filter Design using Scilab

Scilab is an open source software for numerical computation. The software could be download freely from scilab website. AS open source software, we could participate to develop the library of this software. In this article i would like to explain how to design filter using signal processing tool in Scilab. As we know that base on frequency respon filter could be classified into:

- Low Pass Filter (LPF): allow signal which as lower frequency than the cut off frequency.
- Band Pass FIlter (BPF): pass signal from cut off frequency fc1 to cut of frequency fc2
- High Pass Filter (HPF): admit the signal over the cut of frequency
- Band Rejection: reject signal starting from cut off frequency 1 to cut of frequency 2.

Filter coud be used to get the desired signal for example when EKG signal is disturbed by noise wich has lower frequensi signal.

The following will be simulated noise cancellation using generated signal. Original signal is sinusoidal signal 5 Hz for 4 seconds. The noise is sinusoidal signal 50 Hz which also has 4 seconds time.

t = 0:0.001:4
signal = sin(2*%pi*5*t);
noise = sin(2*%pi*50*t);
compound = signal + noise

To seperate the signal from noise, we could use low pass filter. The important note is how to decide the cutt off frequency of the system. Using Scilab, we can use available technique to design the filter such as Butterworth, Chebisev and elliptic.

Deciding the cut of frequency is very easy by looking at freuency of signal and noise. In this case we select the frequency beetween signal and noise. The normalization of 5Hz is 0.005 and 50 Hz is 0.05.

myfilter = iir(15,’lp’,'butt’,[0.025 0],[0 0]);

- The first parameter is filter order. We could use higher order filter but please remberber taht higher order filter increase the number of calculation iterations.
- Second parameter is filter type which lp= lowpass, hp=highpass, bp=bandpass.
- Third parameter is technique which is used to design. This example use Butterworth. It is also availabe other methods such as cheb1, chep2 dan ellip.
- Fourth parameter is cut of frequency in normalization form
- Fifth parameter is error vector whic is used only in chebisev and elliptic technique

To apply filltering to the signal, we could write the following code:

output = flts(compound,myfilter);

Let we plot the input and output of this filter.

xsetech([0,0,1,1/2])
plot2d(t,compound)
xtitle(’input signal’)
xsetech([0,1/2,1,1/2])
plot2d(t,output)
xtitle(’output signal’)

The script will show input signal and output signal of LPF which just been implemented.

written by: Dhidik Prastiyanto
reference:

1. Lecture Note by Dhidik Prastiyanto
2. Introduction to signal Processing (Roman Kuc)

3. http://dhidik.wordpress.com/2009/05/18/filter-design-dengan-scilab/
4. www.scilab.org