DSP Report 1230969
DSP Report 1230969
2019
Introduction to Digital
Processing
ECR305
Project Report
It has two parts: an autoregressive (AR) part (LHS of equation) and a moving average (MA) part (RHS of
equation). Such an IIR filter is called an autoregressive moving average (ARMA) filter.
IIR filters have infinite-duration impulse responses, hence they can be matched to analog filters, all of
which generally have infinitely long impulse responses. Therefore, the basic technique of IIR filter design
is to transform analog filters into digital filters using complex-valued mappings, which is called the
analog-to-digital (A/D) filter transformation. We need to apply frequency-band transformations to low
pass filters in order to design other frequency-selective filters (high pass, band pass, band stop, etc.).
Butterworth filters
Chebyshev filters-
Chebyshev type-I
Chebychev type-II
Elliptic filters.
Butterworth filter:
The Butterworth filter is a type of filter for signal processing designed to have a flat frequency response
in the passband. It is also referred to as a maximally flat magnitude filter. It was first described in 1930
by the British engineer and physicist Stephen Butterworth in his paper entitled "On the Theory of Filter
Amplifiers".
butterworth does not have any ripples in the passband and even in the stopband .They have a more
linear phase response in the pass-band than Chebyshev Type I/Type II Filters. The gain of an n-order
Butterworth low pass filter is given in terms of the transfer function H(s) as
Matlab code:
load('ECG_raw.mat');
load('ECG_clean.mat');
figure(1)
subplot(3,1,1)
plot(ECG_raw)
title('Noisy ECG signal');
[b,a] = butter(4,[0.0005 0.08],'bandpass'); %fc1/(fs/2)\=0.0005 &
fc2/(fs/2)=0.08
filtered_signal=filter(b,a,ECG_raw);
subplot(3,1,2)
plot(filtered_signal)
title('Filtered signal')
subplot(3,1,3)
plot(ECG_clean);
title('Clean ECG signal')
%Single-sided amplitude spectrum
Fs=5000;
L=length(ECG_raw);
P2=abs(ECG_raw/L);
P1=P2(1:L/2+1);
P1(2:end-1)=2*P1(2:end-1);
f=Fs*(0:(L/2))/L;
% hold on
figure(2)
subplot(3,1,1)
plot(f,P1)
title('Single-sided amplitude spectrum of ECG_raw')
xlabel('f(Hz)')
ylabel('|P1(f)|')
L1=length(ECG_clean);
P22=abs(ECG_clean/L1);
P11=P22(1:L1/2+1);
P11(2:end-1)=2*P11(2:end-1);
f=Fs*(0:(L1/2))/L1;
subplot(3,1,2)
plot(f,P11)
title('Single-sided amplitude spectrum of ECG_clean')
xlabel('f(Hz)')
ylabel('|P11(f)|')
L2=length(filtered_signal);
P23=abs(filtered_signal/L);
P13=P23(1:L2/2+1);
P13(2:end-1)=2*P13(2:end-1);
f=Fs*(0:(L2/2))/L2;
subplot(3,1,3)
plot(f,P13)
title('Single-sided amplitude spectrum of filtered_signal')
xlabel('f(Hz)')
ylabel('|P13(f)|')
%time domain plot
t=[0:L-1]/Fs;
figure (3)
subplot(3,1,1)
plot(t(1:50),ECG_raw(1:50))
title('Time domain plot of ECG_raw')
xlabel('Time(s)')
ylabel('Amplitude')
t1=[0:L1-1]/Fs;
subplot(3,1,2)
plot(t(1:50),ECG_clean(1:50))
title('Time domain plot of ECG_clean')
xlabel('Time(s)')
ylabel('Amplitude')
t2=[0:L2-1]/Fs;
subplot(3,1,3)
plot(t2(1:50),filtered_signal(1:50))
title('Time domain plot of filtered_signal')
xlabel('Time(s)')
ylabel('Amplitude')
freqz(b,a)
Error:
>> r=rmse(ECG_clean,filtered_signal)
r=
0.5430
>> corrcoef(ECG_clean,filtered_signal)
ans =
1.0000 0.2006
0.2006 1.0000
Graphs
|P1(f)| 1
0
0 500 1000 1500 2000 2500
f(Hz)
-4 Single-sided amplitude spectrum of ECG c lean
x 10
4
|P11(f)|
0
0 500 1000 1500 2000 2500
f(Hz)
-4 Single-sided amplitude spectrum of filtereds ignal
x 10
5
|P13(f)|
0
0 500 1000 1500 2000 2500
f(Hz)
-100
-200
-300
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
-300
-400
Phase (degrees)
-500
-600
-700
-800
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
'HalfPowerFrequency1',0.05,'HalfPowerFrequency2',80, ...
'SampleRate',2000);
>> legend(fvt,'butter','designfilt')
Its magnitude response is same as the low pass filter. From the 3 signal graph we can observe that the
filtered signal is almost like the clean signal but it oscillates like sine wave. The error is measured by
rmse(Root Mean Square Error) of clean signal and filtered signal. The error is 0.5430. so we can
say that the raw signal is not fully clean there is still noises. To find the similarity between clean and
filtered signal we use corrcoef (correlation coefficient). The correlation coefficient of two random
variables is a measure of their linear dependence. If each variable has N scalar observations, then the
Pearson correlation coefficient is defined as
where μA and σA are the mean and standard deviation of A, respectively, and μB and σB
are the mean and standard deviation of B. Alternatively, you can define the correlation coefficient in
terms of the covariance of A and B:
The correlation coefficient matrix of two random variables is the matrix of correlation coefficients
for each pairwise variable combination.
Since A and B are always directly correlated to themselves, the diagonal entries are just 1, that is,
Conclusion:
Butterworth had a reputation for solving "impossible" mathematical problems. We get maximally flat
magnitude filter. And it does not have any ripples in the passband and even in the stopband. And for
FRI filter we need to design standard window. So it is efficient to use IIR Butterworth filter.
References:
1. “Butterworth filter”
https://www.mathworks.com/help/signal/ref/butter.html#buct3_m
https://www.mathworks.com/help/matlab/ref/fft.html?searchHighlight=Single-
sided%20Amplitude%20Spectrum&s_tid=doc_srchtitle
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.642.3710&rep=rep1&type=pdf
4. https://en.wikipedia.org/wiki/Butterworth_filter
https://www.mathworks.com/help/matlab/ref/corrcoef.html