You are on page 1of 6

Amber Cox

Introduction
Allrealrecordedsignalswillhavesomeformofnoisealongwiththedesiredsignal.In
ordertofilteroutthenoise,itisusefultoconvertthedatatoafrequencydomaininorderto
visualizethenoise.Inthislab,noisydataisalteredbysubtractingfrequenciesandoffsets,
zeroingoutunwantedfrequencies,andamplifyingandshiftingfiltereddata.
Methods/Results/Discussion
ForFigure1,agraphusingthe
ecg.txtdatawascreated.Sincethe
samplingfrequencyofthisdatais200
Hz,andthereare2000datapoints,the
totaltimeofthesampleis10seconds.
Inthese10secondsthereareabout11R
peaks.Therefore,in60seconds,
therewouldbe66heartbeats.This
isaroundtheaveragerestingheart
rate,sothepersonwasmostlikely
atrest.Inthefigure,the5thECG
periodishighlightedinred.
InFigure2,thereare5plots.
Thetopsubplotisagraphofthe
originalknownnoiseECG.Thenext
3graphshavedifferentfrequencies
subtractedfromthemtoremovethe
noiseinthesignal.Thesecondgraph
hasa60Hzsinewavesubtracted,the
thirda32Hzsinewave,andthelasta
4Hzsinewave.Thelastgraphshows
thesignalwithoutanoffset.Thisoffset
wasthemeanofthedata,whichwas
2.5mV.Althoughthefinalgraphdoes
nothavethelargewavespresentin
theoriginal,itdoesappearvery
noisy.TheQRScomplexis
recognizable,butonlyifyouknow
whatyourelookingfor.
Figure3showsacomparison
betweentheecgand
ecg_noise_unknowninthetimeand
frequencydomain.Thelargest
frequencyintheecggraphisalittle
over1Hz,becausethisisthefrequency
oftheheart.Itisdifficulttotellwhattheexacthighest
around35Hz.Inthenoisegraph,thehighestfrequencyis
around65HZ.Thisishigherbecauseitishigh

Figure 1

Figure 2

Figure 3

frequency,butitis
muchhigher,

Amber Cox
Lab 3
frequencynoisethatwascapturedwiththe
data.
Therearethreelargepeaks
inthenoisegraphthatdonot
appearintheecggraph,atabout
44Hz,60Hz,and65Hz.
Although,thepowerofthehigher
frequenciesisasmallconstant,the
magnitudeofitismuchgreaterinthe
noisegraph.Thelargestyvalueis
muchlargerinthenoisegraph.
Thelargesthasavalueof0.5,
whiletheecggraphisonly
0.09.Bothoftheselargepeaks
areatzero.Inthetimedomain,
thesevalueswouldbetheoffsetof
thedata.Inordertofindthisvalue,
youwouldtakethemeanofthedata,
whichiszerofortheecgdataandabout
5.5fortheunknownnoisedata.
Figure 4
Whendisplayingthefirstfive
numbersintheFFToftheecgand
theoftheunknownecgnoise,thefirst
complexnumberdoesnothavean
imaginarycomponent.Thisisbecause
thefirstnumbercorrelatestotheoffset.
Theimaginarycomponentcorresponds
tothephaseshift.Sincetheoffsetdoes
nothaveaphaseshift,thefirstnumberisallreal.Therealcomponentisthesameasthemeans
thatwerefoundearlier.
Thenexttwofigures,4and
5,
showacomparisonbetween
usingfftandrfftinMATLAB.
Bothgiveagraphthathasavery
largecomponentatzero
comparedtotherestofthegraph.
However,theffthasmanymore
peaksathigherfrequencies.The
noisewasremovedfromthe
Figure 5
unknownnoiseecgbyreplacingthe
highfrequencieswithzeros.

Amber Cox
Lab 3
InFigure6youcanseethe
timedomain.Althoughitisnot
completelyfreeofnoise,itis
obviouslyanECGandismuch
clearertoseethanthefinalfiltered
ECGwithsubtractedfrequenciesin
thetimedomain.
Inorderforittobe
overlaidwiththeoriginalecg.txt
signalin,itneededtobeamplified
by1700andshifteddown4.6.The
QRScomplexisdistinguishable
althoughthereisstillnoisesothefiner
pointsoftheECG,suchasthePwave
andTwavearemoredifficulttosee.

filtereddatainthe

Figure 6

Summary
Removingnoiseinthe
frequencydomainwasamuchbetter
filterthanremovingthefrequenciesin
thetimedomainbecauseitcreateda
muchclearerfilteredgraph.However,
filteringinthetimedomainpreservedthe
amplitudeandoffsetofthedata,while
filteringinthefrequencydomaindrasticallyaltered

Figure7
both.

Amber Cox
Lab 3

Appendix
ecg=dlmread('ecg.txt');
ecg_noise_known=dlmread('ecg_noise_known.txt');
ecg_noise_unknown=dlmread('ecg_noise_unknown.txt');
T='Time(s)'%forfuturexlabels
V='Voltage(mV)'%forfutureylabels
t=((1/200):(1/200):10);%timecorrespondingtodatapoints
figure(1);%cleanecggraph
plot(t,ecg);
set(gca,'FontSize',12)
title('OriginalECGData')
xlabel(T)
ylabel(V)
holdon
plot(t(920:1120),ecg(920:1120),'r');%highlighting5thperiod
holdoff

%creatingfrequencies
sine1=sin(120*pi*t);
sine2=sin(64*pi*t);
sine3=sin(8*pi*t);

%addingandsubtractingnoise
removedsine1=(ecg_noise_knownsine1');
removedsine2=(removedsine1sine2');
removedsine3=(removedsine2sine3');

ave=mean(ecg_noise_known);%findingoffset
removedoffset=removedsine3ave;%removingoffset

figure(2);
subplot(5,1,1);
plot(t,ecg_noise_known);%originalknownnoisesignal
set(gca,'FontSize',12)
title('AlteredECGNoiseKnownData');
subplot(5,1,2);
plot(t,removedsine1);%removed60Hzsinewave
subplot(5,1,3);
plot(t,removedsine2);%removed32Hzsinewave
set(gca,'FontSize',12)
ylabel(V);
subplot(5,1,4);
plot(t,removedsine3);%added4Hzsinewave
subplot(5,1,5);
plot(t,removedoffset);%removedoffsetof2.5
set(gca,'FontSize',12)
xlabel(T);

Amber Cox
Lab 3

%comparisonofecgandecg_noise_unknown
figure(3);
subplot(2,2,1);
plot(t,ecg);
set(gca,'FontSize',12)
title('OriginalECGData');
xlabel(T);
ylabel(V)
subplot(2,2,2);
plot(t,ecg_noise_unknown);
set(gca,'FontSize',12)
title('NoiseUnknownECGData');
xlabel(T);
ylabel(V)
subplot(2,2,3);
[freq,pow]=rfft(ecg,200);
set(gca,'FontSize',12)
title('FrequenciesofOriginalECG');
ylim([00.01]);
subplot(2,2,4);
[freq1,freq2]=rfft(ecg_noise_unknown,200);
set(gca,'FontSize',12)
title('FrequenciesofNoiseUknownECGData');
%recducingylimittomatchtheothergraph

offset_unknown_noise=mean(ecg_noise_unknown);

%fouriertransformofecgandecg_noise_unknown
complex_data_ecg=fft(ecg,2048)/2000;
complex_data_ecg_nu=fft(ecg_noise_unknown,2048)/2000;

%first5complexnumbers
complex_data_ecg(1:5);
complex_data_ecg_nu(1:5);

%comparisonoffftandrfft
%closeall;
figure(4);plot(abs(complex_data_ecg_nu));
set(gca,'FontSize',12)
title('FFTofUnknownNoiseECG');
xlabel('Frequency')
ylabel('Power(dB)')
figure(5);rfft(ecg_noise_unknown,200);
set(gca,'FontSize',12)
title('RFFTofUnknownNoiseECG');

%removingthehighfrequencypeaks
complex_data_ecg_nu_half=complex_data_ecg_nu(1:1024);
figure(6);plot(abs(complex_data_ecg_nu_half));
set(gca,'FontSize',12)
title('UnfilteredUnknownNoiseECG');
xlabel('Frequency')

Amber Cox
Lab 3
ylabel('Power(dB)')
complex_data_ecg_nu_half(439:443)=0;
complex_data_ecg_nu_half(613:617)=0;
complex_data_ecg_nu_half(665:669)=0;
figure(7);%checkingforpeakremoval
plot(abs(complex_data_ecg_nu_half));
set(gca,'FontSize',12)
title('FilteredUnknownNoiseECG');
xlabel('Frequency')
ylabel('Power(dB)')

%bringingsignalbackintotimedomain
ecg_noise_unknown_prefiltered=ifft(complex_data_ecg_nu_half,2048,'symmetric')
ecg_noise_unknown_filtered=ecg_noise_unknown_prefiltered(1:length(t));
figure(8);plot(t,ecg_noise_unknown_filtered);
set(gca,'FontSize',12)
title('FilteredUnknownNoiseECG');
xlabel(T);
ylabel(V);

%adjustingfiltereddata
ecg_noise_unknown_filtered_adj=(1700*ecg_noise_unknown_filtered)4.6;

%orignalecgwithfilteredecgcomparison
figure(9);
plot(t(920:1120),ecg(920:1120))
holdon
plot(t(920:1120),ecg_noise_unknown_filtered_adj(920:1120),'r');
title('FilteredUnknownNoiseECG','fontsize',12);
xlabel(T,'fontsize',12);
ylabel(V,'fontsize',12);

You might also like