instrumentation lab 3

8
Amber Cox Introduction All real recorded signals will have some form of noise along with the desired signal. In order to filter out the noise, it is useful to convert the data to a frequency domain in order to visualize the noise. In this lab, noisy data is altered by subtracting frequencies and offsets, zeroing out unwanted frequencies, and amplifying and shifting filtered data. Methods/Results/ Discussion For Figure 1, a graph using the “ecg.txt” data was created. Since the sampling frequency of this data is 200 Hz, and there are 2000 data points, the total time of the sample is 10 seconds. In these 10 seconds there are about 11 R- peaks. Therefore, in 60 seconds, there would be 66 heartbeats. This is around the average resting heart rate, so the person was most likely at rest. In the figure, the 5 th ECG period is highlighted in red. In Figure 2, there are 5 plots. The top subplot is a graph of the original known noise ECG. The next 3 graphs have different frequencies subtracted from them Figure 1

Upload: amber-cox

Post on 12-Apr-2016

212 views

Category:

Documents


0 download

DESCRIPTION

None

TRANSCRIPT

Page 1: Instrumentation Lab 3

Amber Cox

IntroductionAll real recorded signals will have some form of noise along with the desired signal. In

order to filter out the noise, it is useful to convert the data to a frequency domain in order to visualize the noise. In this lab, noisy data is altered by subtracting frequencies and offsets, zeroing out unwanted frequencies, and amplifying and shifting filtered data.

Methods/Results/DiscussionFor Figure 1, a graph

using the “ecg.txt” data was created. Since the sampling frequency of this data is 200 Hz, and there are 2000 data points, the total time of the sample is 10 seconds. In these 10 seconds there are about 11 R-peaks. Therefore, in 60 seconds, there would be 66 heartbeats. This is around the average resting heart rate, so the person was most likely at rest. In the figure, the 5th ECG period is highlighted in red.

In Figure 2, there are 5 plots. The top subplot is a graph of the original known noise ECG. The next 3 graphs have different frequencies subtracted from them to remove the noise in the signal. The second graph has a 60 Hz sine wave subtracted, the third a 32 Hz sine wave, and the last a 4 Hz sine wave. The last graph shows the signal without an offset. This offset was the mean of the data, which was 2.5 mV. Although the final graph does not have the large waves present in the original, it does appear very noisy. The QRS complex is recognizable, but only if you know what you’re looking for.

Figure 3 shows a comparison between the

Figure 1

Figure 2

Page 2: Instrumentation Lab 3

Amber CoxLab 3

“ecg” and “ecg_noise_unknown” in the time and frequency domain. The largest frequency in the “ecg” graph is a little over 1 Hz, because this is the frequency of the heart. It is difficult to tell what the exact highest frequency, but it is around 35 Hz. In the noise graph, the highest frequency is much higher, around 65 HZ. This is higher because it is highfrequency noise that was captured with the data.

There are three large peaks in the noise graph that do not appear in the “ecg” graph, at about 44 Hz, 60 Hz, and 65 Hz. Although, the power of the higher frequencies is a small constant, the magnitude of it is much greater in the noise graph. The largest y-value is much larger in the noise graph. The largest has a value of 0.5, while the “ecg” graph is only 0.09. Both of these large peaks are at zero. In the time domain, these values would be the offset of the data. In order to find this value, you would take the mean of the data, which is zero for the “ecg” data and about 5.5 for the unknown noise data.

When displaying the first five numbers in the FFT of the “ecg” and the of the unknown ecg noise, the first complex number does not have an imaginary component. This is because the first number correlates to the offset. The imaginary component corresponds to the phase shift. Since the offset does not have a phase shift, the first number is all real. The real component is the same as the means that were found earlier.

The next two figures, 4 and 5, show a comparison between using fft and rfft in MATLAB. Both give a graph that has a very large component at zero compared to the rest of the graph.

Figure 4

Figure 52

Page 3: Instrumentation Lab 3

Amber CoxLab 3

However, the fft has many more peaks at higher frequencies. The noise was removed from the unknown noise ecg by replacing the high frequencies with zeros.

In Figure 6 you can see the filtered data in the time domain. Although it is not completely free of noise, it is obviously an ECG and is much clearer to see than the final filtered ECG with subtracted frequencies in the time domain.

In order for it to be overlaid with the original ecg.txt signal in , it needed to be amplified by 1700 and shifted down 4.6. The QRS complex is distinguishable although there is still noise so the finer points of the ECG, such as the P-wave and T-wave are more difficult to see.

Summary Removing noise in the

frequency domain was a much better filter than removing the frequencies in the time domain because it created a much clearer filtered graph. However, filtering in the time domain preserved the amplitude and offset of the data, while filtering in the frequency domain drastically altered both.

Appendixecg=dlmread('ecg.txt');

ecg_noise_known=dlmread('ecg_noise_known.txt');

Figure 6

Figure 7

3

Page 4: Instrumentation Lab 3

Amber CoxLab 3

ecg_noise_unknown=dlmread('ecg_noise_unknown.txt');T='Time (s)' %for future xlabelsV='Voltage(mV)' %for future ylabelst=((1/200):(1/200):10); %time corresponding to data pointsfigure (1);%clean ecg graphplot(t,ecg);set(gca,'FontSize',12)title('Original ECG Data')xlabel(T)ylabel(V)hold on plot(t(920:1120),ecg(920:1120),'r'); %highlighting 5th periodhold off %creating frequenciessine1=sin(120*pi*t);sine2=sin(64*pi*t);sine3=sin(8*pi*t); %adding and subtracting noiseremovedsine1=(ecg_noise_known-sine1');removedsine2=(removedsine1-sine2');removedsine3=(removedsine2-sine3'); ave=mean(ecg_noise_known);%finding offsetremovedoffset=removedsine3-ave;%removing offset figure(2);subplot(5,1,1);plot(t,ecg_noise_known); %original known noise signalset(gca,'FontSize',12)title('Altered ECG Noise Known Data');subplot(5,1,2);plot(t,removedsine1); %removed 60 Hz sine wavesubplot(5,1,3);plot(t,removedsine2); %removed 32 Hz sine waveset(gca,'FontSize',12)ylabel(V);subplot(5,1,4);plot(t,removedsine3); %added 4 Hz sine wavesubplot(5,1,5);plot(t,removedoffset); %removed offset of 2.5set(gca,'FontSize',12)xlabel(T); %comparison of ecg and ecg_noise_unknownfigure (3);subplot(2,2,1);plot(t,ecg);set(gca,'FontSize',12)title('Original ECG Data');xlabel(T);ylabel(V)subplot(2,2,2);plot(t,ecg_noise_unknown);

4

Page 5: Instrumentation Lab 3

Amber CoxLab 3

set(gca,'FontSize',12)title('Noise Unknown ECG Data');xlabel(T);ylabel(V)subplot(2,2,3);[freq,pow]=rfft(ecg,200);set(gca,'FontSize',12)title('Frequencies of Original ECG');ylim([0 0.01]);subplot(2,2,4);[freq1,freq2]=rfft(ecg_noise_unknown,200);set(gca,'FontSize',12)title('Frequencies of Noise Uknown ECG Data'); %recducing y-limit to match the other graph offset_unknown_noise=mean(ecg_noise_unknown); %fourier transform of ecg and ecg_noise_unknowncomplex_data_ecg=fft(ecg,2048)/2000;complex_data_ecg_nu=fft(ecg_noise_unknown,2048)/2000; %first 5 complex numberscomplex_data_ecg(1:5);complex_data_ecg_nu(1:5); %comparison of fft and rfft%close all;figure(4); plot(abs(complex_data_ecg_nu));set(gca,'FontSize',12)title('FFT of Unknown Noise ECG');xlabel('Frequency')ylabel('Power (dB)')figure(5); rfft(ecg_noise_unknown,200);set(gca,'FontSize',12)title('RFFT of Unknown Noise ECG'); %removing the high frequency peakscomplex_data_ecg_nu_half=complex_data_ecg_nu(1:1024);figure(6); plot(abs(complex_data_ecg_nu_half));set(gca,'FontSize',12)title('Unfiltered Unknown Noise ECG');xlabel('Frequency')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);%checking for peak removalplot(abs(complex_data_ecg_nu_half));set(gca,'FontSize',12)title('Filtered Unknown Noise ECG');xlabel('Frequency')ylabel('Power (dB)') %bringing signal back into time domainecg_noise_unknown_prefiltered=ifft(complex_data_ecg_nu_half,2048,'symmetric')

5

Page 6: Instrumentation Lab 3

Amber CoxLab 3

ecg_noise_unknown_filtered=ecg_noise_unknown_prefiltered(1:length(t));figure(8); plot(t,ecg_noise_unknown_filtered);set(gca,'FontSize',12)title('Filtered Unknown Noise ECG');xlabel(T);ylabel(V); %adjusting filtered dataecg_noise_unknown_filtered_adj=(1700*ecg_noise_unknown_filtered)-4.6; %orignal ecg with filtered ecg comparisonfigure(9);plot(t(920:1120),ecg(920:1120))hold onplot(t(920:1120),ecg_noise_unknown_filtered_adj(920:1120),'r');title('Filtered Unknown Noise ECG', 'fontsize',12);xlabel(T,'fontsize',12);ylabel(V,'fontsize',12);

6