Please need help, in plotting figures 11 & 12.

조회 수: 1 (최근 30일)
Reham Wafaee
Reham Wafaee 2021년 2월 15일
댓글: Reham Wafaee 2021년 2월 15일
function [x,ecg]=complete()
x=1:3000;
%x=0:0.01:2;
default=input('Press 1 if u want default ecg signal else press 2:\n');
if(default==1)
li=30/72;
a_pwav=0.25;
d_pwav=0.09;
t_pwav=0.16;
a_qwav=0.025;
d_qwav=0.066;
t_qwav=0.166;
a_qrswav=1.6;
d_qrswav=0.11;
a_swav=0.25;
d_swav=0.066;
t_swav=0.09;
a_twav=0.35;
d_twav=0.142;
t_twav=0.2;
a_uwav=0.035;
d_uwav=0.0476;
t_uwav=0.433;
else
rate=input('\n\nenter the heart beat rate :');
li=30/rate;
%p wave specifications
fprintf('\n\np wave specifications\n');
d=input('Enter 1 for default specification else press 2: \n');
if(d==1)
a_pwav=0.25;
d_pwav=0.09;
t_pwav=0.16;
else
a_pwav=input('amplitude = ');
d_pwav=input('duration = ');
t_pwav=input('p-r interval = ');
d=0;
end
%q wave specifications
fprintf('\n\nq wave specifications\n');
d=input('Enter 1 for default specification else press 2: \n');
if(d==1)
a_qwav=0.025;
d_qwav=0.066;
t_qwav=0.166;
else
a_qwav=input('amplitude = ');
d_qwav=input('duration = ');
t_qwav=0.166;
d=0;
end
%qrs wave specifications
fprintf('\n\nqrs wave specifications\n');
d=input('Enter 1 for default specification else press 2: \n');
if(d==1)
a_qrswav=1.6;
d_qrswav=0.11;
else
a_qrswav=input('amplitude = ');
d_qrswav=input('duration = ');
d=0;
end
%s wave specifications
fprintf('\n\ns wave specifications\n');
d=input('Enter 1 for default specification else press 2: \n');
if(d==1)
a_swav=0.25;
d_swav=0.066;
t_swav=0.09;
else
a_swav=input('amplitude = ');
d_swav=input('duration = ');
t_swav=0.09;
d=0;
end
%t wave specifications
fprintf('\n\nt wave specifications\n');
d=input('Enter 1 for default specification else press 2: \n');
if(d==1)
a_twav=0.35;
d_twav=0.142;
t_twav=0.2;
else
a_twav=input('amplitude = ');
d_twav=input('duration = ');
t_twav=input('s-t interval = ');
d=0;
end
%u wave specifications
fprintf('\n\nu wave specifications\n');
d=input('Enter 1 for default specification else press 2: \n');
if(d==1)
a_uwav=0.035;
d_uwav=0.0476;
t_uwav=0.433;
else
a_uwav=input('amplitude = ');
d_uwav=input('duration = ');
t_uwav=0.433;
d=0;
end
end
pwav=p_wav(x,a_pwav,d_pwav,t_pwav,li);
figure(1)
plot(x,pwav,'k');
title('pwav output');
xlabel('Time');
ylabel('Amplitude');
%qwav output
qwav=q_wav(x,a_qwav,d_qwav,t_qwav,li);
figure(2)
plot(x,qwav,'k');
title('qwav output');
xlabel('Time');
ylabel('Amplitude');
%qrswav output
qrswav=qrs_wav(x,a_qrswav,d_qrswav,li);
figure(3)
plot(x,qrswav,'k');
title('qrswav output');
xlabel('Time');
ylabel('Amplitude');
%swav output
swav=s_wav(x,a_swav,d_swav,t_swav,li);
figure(4)
plot(x,swav,'k');
title('swav output');
xlabel('Time');
ylabel('Amplitude');
%twav output
twav=t_wav(x,a_twav,d_twav,t_twav,li);
figure(5)
plot(x,twav,'k');
title('twav output');
xlabel('Time');
ylabel('Amplitude');
%uwav output
uwav=u_wav(x,a_uwav,d_uwav,t_uwav,li);
figure(6)
plot(x,uwav,'k');
title('uwav output');
xlabel('Time');
ylabel('Amplitude');
%ecg output
ecg=pwav+qrswav+twav+swav+qwav+uwav;
figure(7)
plot(x,ecg);
title('Normal ECG output');
xlabel('Time');
ylabel('Amplitude');
%%
fs=1000;f1=40;f2=60; % sampling, lower and upper cutoff frequencies in Hz respectively;
w1=2*f1/fs; % computes normalized digital lower cutoff frequency;
w2=2*f2/fs; % computes normalized digital upper cutoff frequency;
L=100; % order of the filter; to re
Wn=[w1 w2]; % if the programmer desires to define the two cutoff frequencies by one symbol;
b=fir1(L,Wn,'stop',hamming(L+1)); % creates the object of the notch filter weighted with hamming window;
[h,w]=freqz(b,1,256); % returns 256 samples of the frequency response vector h and the corresponding frequency vector w, between 0 and ;
HdB=20*log10(abs(h)); % computes the magnitude vector in dB;
phaseangle=unwrap(angle(h)); % computes unwrap phase angle vector;
figure(8)
impz(b) % plots the impulse response of the filter;
figure(9)
plot(w/pi,HdB) % plots the magnitude response of the filter in dB;
figure(10)
plot(w/pi,phaseangle) % plots the phase response of the filter;
k=1:3000;
x1=0.1*sin(2*pi*50*(k-1)/fs); % sampled 0.1mV/ 50Hz powerline noise;
v=3.5*ecg(3000); % sampled 3.5mV ecg signal;
d=x1+v; % contaminated ecg signal;
si=zeros(1,L); % initializes all filter taps to zero;
y=filter(b,1,d,si); % filters the ecg signal;
figure(11)
plot(k-1,v) % plots samples the clean ecg sigal;
figure(12)
plot(k-1,d) % plots the contaminated ecg signal;
periodogram(d) % plots the frequency spectrum of the contaminated ecg signal;
figure(13)
plot(k-1,y) % plots the filtered ecg signal;
periodogram(y) % plots the frequency spectrum of the filtered ecg signal;
Why this code doesn't plot figure 11 & 12?, please help.
  댓글 수: 4
dpb
dpb 2021년 2월 15일
편집: dpb 2021년 2월 15일
Exactly that...
v=3.5*ecg(1:3000);
I'd suggest to not bury "magic numbers" like that in code, however, use a variable so can set in one place if indeed is a constant or use/calculate the size to match what else is going on.
For example, you defined
x=1:3000;
at the beginning of your function; that would imply what you really want is:
v=3.5*ecg(x);
Then, if you change that, related stuff will change automagically along with it.
Even there, it would be better to write
NX=3000;
x=1:NX;
or to pass NX to the function to be even more general.
If you do this, then you can simply write
v=3.5*ecg(1:NX);
instead.
Also, you then define
k=1:3000;
later on which is just a copy of x. Why have two copies of the same thing?
Reham Wafaee
Reham Wafaee 2021년 2월 15일
Oh, that's right..I really don't know why I made 2 copies of the same paramter, I think I've focused to run section by section and forget to delete the repeated parameter.Anyway thank you so much for your help.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by