1) Computing of The Maximum and Minimum Values of The Clean and Noisy ECG Signals
1) Computing of The Maximum and Minimum Values of The Clean and Noisy ECG Signals
1) Computing of The Maximum and Minimum Values of The Clean and Noisy ECG Signals
To calculate those values: I have read before the clean ecg signal then noisy signal and we
get their maximum and minimum. I take the ecg_004 signal as noisy singnal.
clear
max_ecgclean = max(x1);
min_ecgclean = min(x1);
fprintf('max_ecgclean = %d\n',max_ecgclean);
max_ecgclean = 5.947876e-01
fprintf('min_ecgclean = %d\n',min_ecgclean);
min_ecgclean = 2.940063e-01
max_ecg_004 = max(x2);
min_ecg_004 = min(x2);
fprintf('max_ecg_004 = %d\n',max_ecg_004);
max_ecg_004 = 6.325989e-01
fprintf('min_ecg_004 = %d\n',min_ecg_004);
min_ecg_004 = -1.878662e-01
xc = x1(1:1000);
xn = x2(1:1000);
subplot(4,1,1)
plot(xn), title('noisy ecg signal befor DC components'), grid on
subplot(4,1,2)
plot(xc), title('clean ecg signal befor DC components'), grid on
%Question 2
[C, L] = wavedec(xc,9,'bior3.7');
a19 = wrcoef('a',C,L,'bior3.7',9);
d19 = wrcoef('d',C,L,'bior3.7',9);
d18 = wrcoef('d',C,L,'bior3.7',8);
d17 = wrcoef('d',C,L,'bior3.7',7);
d16 = wrcoef('d',C,L,'bior3.7',6);
1
d15 = wrcoef('d',C,L,'bior3.7',5);
d14 = wrcoef('d',C,L,'bior3.7',4);
d13 = wrcoef('d',C,L,'bior3.7',3);
d12 = wrcoef('d',C,L,'bior3.7',2);
d11 = wrcoef('d',C,L,'bior3.7',1);
subplot(4,1,4)
y11 = d19+d18+d17+d16+d15+d14+d13+d12+d11;
plot(y11)
title('clean ecg signal after DC components'), grid on
-Noisy ecg
[C, L] = wavedec(xn,9,'bior3.7');
a29 = wrcoef('a',C,L,'bior3.7',9);
d29 = wrcoef('d',C,L,'bior3.7',9);
d28 = wrcoef('d',C,L,'bior3.7',8);
d27 = wrcoef('d',C,L,'bior3.7',7);
d26 = wrcoef('d',C,L,'bior3.7',6);
d25 = wrcoef('d',C,L,'bior3.7',5);
d24 = wrcoef('d',C,L,'bior3.7',4);
d23 = wrcoef('d',C,L,'bior3.7',3);
d22 = wrcoef('d',C,L,'bior3.7',2);
d21 = wrcoef('d',C,L,'bior3.7',1);
subplot(4,1,3)
y22 = d29+d28+d27+d26+d25+d24+d23+d22+d21;
plot(y22)
title('noisy ecg signal after DC components'), grid on
2
3) Compute a 1024 point FFT from the initial 1024 samples segment of the noisy ECG
without DC component.
To calculate the fast fourier transform (FFT) of the noisy signal with the first 1024 points of x2
I caclulate the frequency of x-axis betwen - and all times where N is the size
figure(2)
%Question 3
x2 = x2(1:1024);
N = size(x2, 1);
dx2 = Fs2 / N;
w = (-(N/2):(N/2)-1)*dx2;
y2 = fft(x2) / N; % For normalizing
y3 = fftshift(y2);
plot(w, abs(y3));
title('Amplitude Spectrum');
xlabel('Frequency(Hz)');
3
4) Remorving of unwanted noise based on the frequency spectrum obtained in (3
%Question 4
filtering f1
n = 2;
beginFreq = 45 / (Fs2/2);
[b,a] = butter(n, beginFreq,'s');
fOut = filter(b, a, x2);
% extract f1
[b,a] = butter(n, beginFreq,'low');
4
f1 = filter(b, a, x2);
filtering f2
beginFreq = 80 / (Fs2/2);
[b,a] = butter(n, beginFreq, 's');
fOut = filter(b, a, fOut);
% extract f2
[b,a] = butter(n, beginFreq, 'high');
f2 = filter(b, a, x2);
% For normalizing
Ym = max(max(max(fOut)),max(abs(min(fOut))));
fOut = fOut ./ Ym;
After processing
plot(w,abs(fftshift(fft(fOut)/N)));
title('After processing: Amplitude Spectrum'); xlabel('Frequency(Hz)');
Here to plot the signal in time domaine, I firstly calulate the period given by;
where Fs2 is the frequency of the noisy signal then I compute the times values
5
which are the multiples of the period T in second between 0 and L-1 with L the length of the signal.
figure;
x2 = x2(1:1000);
T = 1 / Fs2; % Sampling period
L = length(x2); % Length of signal
t = (0:L-1) * T; % Time vector
N = size(x2, 1);
stem(t, fOut(1:1000));
title('After processing: Time-domain'); xlabel('time(seconds)');