Presentation on theme: "Removing 60 Hz from EKG signal William Rose, May 2009 Original EKG signal looked good on paient monitor but had very small amplitude (+- 4 bits) at the."— Presentation transcript:
Removing 60 Hz from EKG signal William Rose, May 2009 Original EKG signal looked good on paient monitor but had very small amplitude (+- 4 bits) at the A-to-D board, due to partial short in connecting cable (discovered later). Problem was not recognized at the time because EKG recorded by A-to-D board was not displayed. Now EKG recorded on computer is displayed in real time, so that in the future a similar problem will likely be noticed and corrected.
bandstopfilt.vi, aecg_10sec.txt EKG for 10 sec, unfiltered. Noise is large compared to the R waves, preventing triggering. EKG for 0.5 sec, unfiltered. Notice periodic signal and level quantization due to small amplitude.
Presence of a distinct frequency in the data suggests that a band stop (notch) filter may be useful. Band stop filters characterized by Center frequency (Hz) Bandwidth (Hz) (half width) Number of poles Labview and Matlab filter functions want high and low frequencies instead of center frequency and half width.
bandstopfilt.vi Most code inside a while loop. Before entering loop: Get file name, read in data, get sampling rate. Inside the loop, program continually re-filters, re-plots, and checks to see if f co, f halfwidth, or number of poles have changed. When while loop is done, program writes data to a file if requested. Filtering Butterworth Coefficients.vi Cascade to Direct Coefficients.vi Zero Phase Filter.vi Instead of (Butterworth Filter.vi, Reverse 1D Array.vi) two times
bandstopfilt.vi Butterworth Coefficients.vi gives filter coefficients in cascade form (2 nd order sections for low- and high-pass filters; 4 th order sections for band pass and band stop filters). High order filters generally perform better if implemented in cascade form than if implemented in direct form, because they are less sensitive to quantization errors in the coefficients. However, Zero Phase Filter.vi needs direct form. Direct form looks like this: Y k = b 0 X k + b 1 X k-1 + b 2 X k-2 + b 3 X k-3 + b 4 X k-4 + … - a 1 Y k-1 –a 2 Y k-2 –a 3 Y k-3 –a 4 Y k-4 – … a’s are the reverse coefficients b’s are the forward coefficients
Block diagram of bandstopfilt.vi
Front panel of bandstopfilt.vi aecg_10sec.txt Top: black dots=original, red line=filtered Middle: Power spectrum of original signal. Note logarithmic Y-axis scale and power at 60, 120, 180… Hz. (The 60 Hz noise is not a pure sinusoid, so it has power at harmonics of 60.) Bottom: Power spectrum of filtered signal. Note notch at 60 Hz.
bandstopfilt.vi. Tests done with input = aecg_10sec.txt; f cutoff =60 Hz Change filter width while keeping number of poles fixed: (f halfwidth, # poles) = (1 Hz, 4); (5 Hz, 4); (10 Hz, 4). Change number of poles while keeping width fixed: (f halfwidth, # poles) = (10 Hz, 1); (10 Hz, 4); (10 Hz, 8). Results: “Signal to noise” (size of QRS /size of background noise) changes little, even though power spectrum notches change. Tests done with white noise input: uniformrandoms.txt; f co =60 Hz (f halfwidth, # poles) = (1Hz, 4); (5 Hz, 4); (10 Hz, 4); (10 Hz, 8). Results: Some combinations resulted in unstable filters, manifested as an output signal which was orders of magnitude too large: (f halfwidth, # poles) = (5 Hz, 7); (5 Hz, 8); (10 Hz, 8); (10 Hz, 9).
bandstopfilt+harmonics.vi. Add filters at the harmonics: multiples of center frequency. Test with a white noise signal: input=uniformrandoms.txt; f cutoff =60Hz. (f halfwidth, # poles) = (3 Hz, 1); (5 Hz, 4); (10 Hz, 8). Input = aecg_10sec.txt; f cutoff =60 Hz. (f halfwidth, # poles) = (3 Hz, 1); (5 Hz, 4); (10 Hz, 8). “Signal to noise” (size of QRS /size of background noise) is somewhat better with filtering at 60 Hz and its harmonics than with filtering at 60 Hz only.
Block diagram of bandstopfilt+harmonics.vi
sample_compare.jpg Comparison of raw signal with output from bandstopfilt.vi and bandstopfilt+harmonics.vi Top: aecg.txt unfiltered. Middle: bandstopfilt, f co =60 Hz, f hw =5 Hz, order=4 (each way). Bottom: bandstopfilt+harmonics, f co =60 Hz, f hw =5 Hz, order=4 (each way).
bandstopfilt+harmonics+lowpass.vi. Add an optional 4 th order Butterworth lowpass filter (forward plus backward to give zero phase) to the bandpass filters. Input = aecg_10sec.txt f co = 60 Hz, f hw = 20 Hz, order (each way) = 4. f lp = 200 Hz “Signal to noise” (size of QRS /size of background noise) is somewhat better with than without the lowpass filter at 200 Hz.
Front panel of bandstopfilt+harmonics +lowpass.vi
Block diagram of bandstopfilt+harmonics +lowpass.vi