Professional Documents
Culture Documents
Exp7
Exp7
Exp7
Remarks
Objectives:
1. To be able to remove noises from a single tone sinusoidal signal using FIR and IIR lowpass
filters.
2. To be able to remove noises from the single tone sinusoidal signal using the Filter Designer
tool (FDATool).
3. To be able to design Low Pass Filter (LPF), High Pass Filter (HPF), Band Pass Filter (BP).
Necessary Software:
1. MATLAB
Task 01:
Write a MATLAB code to remove noises from a single tone sinusoidal signal using FIR and IIR
lowpass filters. Original signal frequency is 15Hz (last 2 digits of student ID = 1802015) and noise
frequency is (15+50) or 65Hz.
title('Original Signal')
xlabel('time')
ylabel('Amplitude')
plot(abs(fft(x,1028)))
xlim([0 100])
grid on
Generating the noise signal:
An=5;
fn=65;
y=An*sin(2*pi*fn*n);
plot(n,y)
title('Noise Signal')
xlabel('time')
ylabel('Amplitude')
plot(abs(fft(y,1028)))
xlim([0 100])
grid on
Output of noisy signal:
z=x+y;
plot(n,z)
grid on
Step 3: Filter
x_f_iir=filter(b,a,z);
plot(n,x_f_iir)
plot(abs(fft(x_f_iir,1028)))
xlim([0 100])
grid on
plot(abs(fft(x_f_iir_0,1028)))
xlim([0 100])
grid on
title('Frequency Response for Order 1')
xlabel('Frequency')
ylabel('Amplitude')
IIR Low Pass Filter(For Order - 15):
O_IIR = 15;
Wc=2*pi*f/fs;
[b,a]=butter(O_IIR, Wc, 'low');
x_f_iir_0=filter(b,a,z);
plot(n,x_f_iir_0)
plot(abs(fft(x_f_iir_0,1028)))
xlim([0 100])
plot(abs(fft(x_f_iir_0,1028)))
xlim([0 100])
grid on;
title('Frequency Response for Order 20')
xlabel('Frequency')
ylabel('Amplitude')
Comments:
First of all, a sinusoidal signal was generated and later a noise signal was added to generate a noisy
signal. To remove noise, I have used IIR Butterworth Low Pass Filter for different orders. Among
them, order 15 worked best. If order is lowered to much the noise signal returns and again if the
order is increased the 19 the noise signal was significant which also hinders the magnitude.
Filtering using FIR Filter(Order - 40):
Step 1: Filter Design Parameters
O_FIR = 40;
Wc=2*pi*f/fs;
Step 3: Filter
x_f_fir=filter(b,1,z);
plot(n,x_f_fir)
plot(abs(fft(x_f_fir,1028)))
xlim([0 100])
grid on
plot(abs(fft(x_f_fir,1028)))
xlim([0 100])
grid on
title('Frequency Response for Order 1')
xlabel('Frequency')
ylabel('Amplitude')
FIR Low Pass Filter(For Order - 100):
O_FIR = 100;
b = fir1(O_FIR,Wc,'low');
x_f_fir=filter(b,1,z);
plot(n,x_f_fir)
plot(abs(fft(x_f_fir,1028)))
xlim([0 100])
grid on
title('Frequency Response of FIR Filter Output')
xlabel('Frequency')
ylabel('Amplitude')
FIR Low Pass Filter(For Order - 230):
O_FIR = 230;
b = fir1(O_FIR,Wc,'low');
x_f_fir=filter(b,1,z);
plot(n,x_f_fir)
plot(abs(fft(x_f_fir,1028)))
xlim([0 100])
grid on
title('Frequency Response for Order 230')
xlabel('Frequency')
ylabel('Amplitude')
Comments:
Again here to remove noise, I have used FIR Butterworth Low Pass Filter for different orders. Higher
order values from 100 workes good till 230. If order is lowered to much the noise signal returns and
again noise signal was significant which also hinders the amplitude.
Task 02:
1. Generate white noise using rand function
2. Write a MATLAB code to remove white noise from the single tone sinusoidal signal of the
previous task using the filterDesigner tool (FDATool) by designing LPF, HPF and BF filters
(both FIR and IIR).
yw = 1×5001
4.4887 3.7435 4.7739 4.7826 4.4430 4.9600 1.4727 ⋯
plot(n,yw)
title('White Noise')
xlabel('Time')
ylabel('Amplitude')
plot(abs(fft(yw,1028)))
xlim([0 100])
grid on
title('Frequency Response of White Noinse')
xlabel('Frequency')
ylabel('Amplitude')
grid on
title('Frequency Response of Noisy Signal')
xlabel('Frequency')
ylabel('Amplitude')
Comments:
White noise is being generated using rand() function. To detect the effect of noise signal the rand()
function is multiplied by 5 which is then added with the sinusoidal signal to create a noisy signal.
Comments:
Filter Designer is a Graphical User Interface (GUI) that allows user to create filter function and
design or import, and analyze digital FIR and IIR filters by selecting desired filter parameters..
Designing Low Pass Filter(IIR):
Butterworth, Order 10:
filterpara=lpf_15hz_iir;
x1_f_iir=filter(filterpara,zw);
plot(n,x1_f_iir)
title('Butterworth, Order 10')
xlabel('Time')
ylabel('Amplitude')
plot(abs(fft(x1_f_iir,1028)))
xlim([0 100])
grid on
title('Frequency Resonse for Order 10')
xlabel('Frequency')
ylabel('Amplitude')
Butterworth, Order 50:
filterpara=lpf_15hz_iir_50;
x1_f_iir_50=filter(filterpara,zw);
plot(n,x1_f_iir_50)
grid on
title('Frequency Response for Order 50')
xlabel('Frequency')
ylabel('Amplitude')
Comments:
Butterworth filter for both order 10 and 50 is analyzed where order 10 filter outperforms the other.
The filter containing order 50 hinders original signal and have delay while the order 10 filter keeps
some noise before 15Hz because of low pass filter but does good for higher frequency noises.
filterpara=ch_lpf_15hz_iir;
x1_f_iir_50=filter(filterpara,zw);
plot(n,x1_f_iir_50)
grid on
title('Frequency Response for Order 10')
xlabel('Frequency')
ylabel('Amplitude')
Chebyshev, Order 50:
filterpara=ch_lpf_15hz_iir_50;
x1_f_iir_50=filter(filterpara,zw);
plot(n,x1_f_iir_50)
grid on
title('Frequency Response for Order 50')
xlabel('Frequency')
ylabel('Amplitude')
Comments:
Here Chebyshev filter of order 10 is better than order 50 becuase order 50 filter has delay and it
returns low amount of original signal which is very much poor in terms of performance. But Order 10
filter does quite well to remove higher frequency noises.
filterpara=lpf_15hz_fir;
x1_f_fir=filter(filterpara,zw);
plot(n,x1_f_fir)
plot(abs(fft(x1_f_fir,1028)))
xlim([0 100])
title('Frequency Response')
xlabel('Frequency')
ylabel('Amplitude')
Window(Kaiser), Order 50:
filterpara=lpf_15hz_fir_50;
x1_f_fir_50=filter(filterpara,zw);
plot(n,x1_f_fir_50)
title('Frequency Response')
xlabel('Time')
ylabel('Amplitude')
Window(Bartlett), Order 10:
filterpara=bart_lpf_15hz_fir;
x1_f_fir=filter(filterpara,zw);
plot(n,x1_f_fir)
title('Frequency Response')
xlabel('Frequency')
ylabel('Amplitude')
Window(Bartlett), Order 50:
filterpara=bart_lpf_15hz_fir_50;
x1_f_fir=filter(filterpara,zw);
plot(n,x1_f_fir)
title('Frequency Response')
xlabel('Frequency')
ylabel('Amplitude')
Comments:
In terms of FIR Low Pass Filter, Window-Kaiser and Window-Bartlett was used for both order 10 and
50. The conclusion that can be made from this is that higher order removes noise very good but it
sacrifices the amplitude of the signal. Moreover for same order(50) Bartlett was better than Kaiser.
filterpara=hpf_15hz_iir;
x2_f_iir = filter(filterpara, zw);
plot(n, x2_f_iir)
title('Frequency Response')
xlabel('Frequency')
ylabel('Amplitude')
Chebyshev, Order 10:
filterpara=ch_hpf_15hz_iir;
x2_f_iir = filter(filterpara, zw);
plot(n, x2_f_iir)
title('Frequency Response')
xlabel('Frequency')
ylabel('Amplitude')
Comments:
As high pass filter is used here, high frequency noise is remained. Two types of filter, i.e.,
Butterworth and Chebyshev is used for same order was used to remove noise where Butterworth
does decent job than Chebyshev. The spikes of noise signal is more significant for chebyshev filter
than butterworth filter.
filterpara=hpf_15hz_fir;
x2_f_fir = filter(filterpara, zw);
plot(n, x2_f_fir)
plot(abs(fft(x2_f_fir,1028)))
xlim([0 100])
title('Frequency Response')
xlabel('Frequency')
ylabel('Amplitude')
Window(Kaiser), Order 80:
filterpara=hpf_15hz_fir_80;
x2_f_fir_80 = filter(filterpara, zw);
plot(n, x2_f_fir_80)
title('Frequency Response')
xlabel('Frequency')
ylabel('Amplitude')
Window(Kaiser), Order 60, Cutoff Frequency = 10Hz:
filterpara = bpf_10_20hz_iir;
x4_f_iir = filter(filterpara, zw);
plot(n, x4_f_iir)
title('Butterworth Order 10')
xlabel('Time')
ylabel('Amplitude')
plot(abs(fft(x4_f_iir,1028)))
xlim([0 100])
title('Frequency Response')
xlabel('Frequency')
ylabel('Amplitude')
Chebyshev, Order 10:
filterpara = ch_bpf_10_20hz_iir;
x4_f_iir = filter(filterpara, zw);
plot(n, x4_f_iir)
title('Chebyshev Order 10')
xlabel('Time')
ylabel('Amplitude')
plot(abs(fft(x4_f_iir,1028)))
xlim([0 100])
title('Frequency Response')
xlabel('Frequency')
ylabel('Amplitude')
Comments:
Two types of IIR Band pass filter were used to remove noise here. Butterworth filter is the clear
winner here as chebyshev filter completely deteriorates the signal which does not output any desired
signal.
filterpara = bpf_10_20hz_fir;
x4_f_fir = filter(filterpara, zw);
plot(n, x4_f_fir)
title('Window(Kaiser), Order 10')
xlabel('Time')
ylabel('Amplitude')
plot(abs(fft(x4_f_fir,1028)))
xlim([0 100])
title('Frequency Response')
xlabel('Frequency')
ylabel('Amplitude')
Window(Kaiser), Order 100:
filterpara = bpf_10_20hz_fir_100;
x4_f_fir_2 = filter(filterpara, zw);
plot(n, x4_f_fir_2)
title('Window(Kaiser), Order 100')
xlabel('Time')
ylabel('Amplitude')
plot(abs(fft(x4_f_fir_2,1028)))
xlim([0 100])
grid on
title('Frequency Response')
xlabel('Frequency')
ylabel('Amplitude')
Comments:
For FIR band pass fitler, window-kaiser had trials for different orders. For lower order, such as 10,
leaves some noise signal spikes, But for higher order, for 100 show above, except for the beginning
spike noise signal is removed quite succesfully.
Discussion:
In this experiment, different types of FIR, IIR low pass, high pass & band pass filter was used to
remove noise signals. First part of the experiment, with help of 'code' filter function was generated
using required filter parameters. Later, rand() function was used to generate white noise which is
distributed all over the frequency domain. The it was added to the original signal. Here, Filter
Designer Tool of MATLAB was used to generate various suitable low pass, high pass, band pass
filters for IIR and FIR to compare and come to a conclusion which type of filter works better for
individual cases.