You are on page 1of 2

clc;

clear all;
close all;
load('100m.mat');
ECGsignal= (val)/200;
Fs=360;
t=(0:length(ECGsignal)-1)/Fs;
figure(1)
plot(t,ECGsignal);
title('original ECG signal');
sampling_frequency = 360;
%mains_coeff = 0.1; %Amplitude of mains line to change. Depends on your
ECG signal.
time_step = 1/sampling_frequency;
max_time = 10; % Duration of your signal in seconds.
t = time_step:time_step:max_time; % This is our time vector.
mains_signal = 0.1*cos(2*pi*50*t); % 50Hz mains frequency. Depends.
figure(2)
plot(mains_signal);
title('noise signal');
ds = ECGsignal + mains_signal;
figure(3);
plot(ds);
title('corrupted signal');
dsf=fft(ds);
%plot(abs(dsf));
xf=linspace(0,360,length(ds));
figure(4)
plot(xf,abs(dsf));
title('frequency spectrum version of corrupted signal');
a=fir1(100,0.2,'low');
ds2=filter(a,1,ds);
figure(5)
plot(ds2);
title('filtered signal');
h=adaptfilt.lms(101,0.03);
[y,e]=filter(h,ECGsignal,ds2);
figure(6)
plot(y);
title('adaptive filter output y(t)');
xlabel('Time');
ylabel('Amplitude');
figure(7)
plot(e);
title('error signal e(t)');
xlabel('time');
ylabel('amplitude');
disp('ideal system coefficients');
disp([a]);
disp('derived system(adaptive filter)');
disp([h.coefficients]);
disp('difference between two systems');
disp([h.coefficients-a]);
E_db=20*log10(abs(e));
m=0;
N=3600;
for n=16:N
if(E_db(n)<=-100&&m==0)
m=1;
break;
end;
end;
Conv_Sample=n
figure(8);
plot(1:N,[ds2',y',e']);
title('system identification');
xlabel('time');
ylabel('amplitude');
legend('DESIRED','OUTPUT','ERROR');
figure(9);
subplot(2,1,1);
stem(a);
title('ACTUAL SYSTEM');
xlabel('step');
ylabel('h(k)');
subplot(2,1,2);
stem([h.coefficients]);
title('IDENTIFIED SYSTEM');
xlabel('step');
ylabel('h(k)');
%figure(10);
subplot(2,1,1);
%plot((abs(e)));
%title('error');
%ylabel('e(n)');
%xlabel('iteration number');
%subplot(2,1,2);
%plot(20*log10(abs(e)));
%title('Error(dB)');
%ylabel('20*log(e(n))');
%xlabel('iteration number');

%title('magnitude response of unknown system');


%title('magnitude response of adaptive system');

fvtool(a);
title('magnitude response of unknown system');
fvtool(h);
title('magnitude response of adaptive system');

You might also like