notch filter to remove 20Hz noise of ECG signal
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
notch filter to remove 20Hz noise of ECG signal

 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP
Author Message
ashcroft2006
Guest





Posted: Mon Dec 19, 2005 5:16 pm    Post subject: notch filter to remove 20Hz noise of ECG signal Reply with quote

Hey
Im a student and need help using matlab. im extremeley new to signa
processing so this is a pretty basic question, im hoping someone can hel
me.

im removing noise from an ecg signal and i need to remove this noise a
20hz using a notch filter, sampling rate is 200hz. the matlab code is:

Quote:
a=[x x x]
b=[x x x]
zfiltered=filter(a,d,z)

'z' is my noise corrupted signal, but how do i work out the coeffs neede
for 'a' and 'b'?
sorry for the "newbie" question but im in desperte need of help.

Any help is much appreciated,
Mark
Back to top
John Herman
Guest





Posted: Mon Dec 19, 2005 11:30 pm    Post subject: Re: notch filter to remove 20Hz noise of ECG signal Reply with quote

If this is a time limited chunk of data and the results are not required in
real time, you might convert the signal to the frequency domain using the
discrete Fourier transform (DFT), windowing the frequency domain data to
eliminate the offending noise, and then performing the inverse discrete
Fourier transform. This is as easy as it gets and works in Matlab.

If you have to do this in real time, junk Matlab. If you have to use Matlab
for some reason, investigate the remez function and FIR filters for your data.

In article <zdWdnaXfZfAweTveRVn-iA@giganews.com>, "ashcroft2006"
<mark_ashcroft@hotmail.com> wrote:
Quote:
Hey
Im a student and need help using matlab. im extremeley new to signal
processing so this is a pretty basic question, im hoping someone can help
me.

im removing noise from an ecg signal and i need to remove this noise at
20hz using a notch filter, sampling rate is 200hz. the matlab code is:

a=[x x x]
b=[x x x]
zfiltered=filter(a,d,z)

'z' is my noise corrupted signal, but how do i work out the coeffs needed
for 'a' and 'b'?
sorry for the "newbie" question but im in desperte need of help.

Any help is much appreciated,
Mark

Back to top
Bhaskar Thiagarajan
Guest





Posted: Mon Dec 19, 2005 11:31 pm    Post subject: Re: notch filter to remove 20Hz noise of ECG signal Reply with quote

"ashcroft2006" <mark_ashcroft@hotmail.com> wrote in message
news:zdWdnaXfZfAweTveRVn-iA@giganews.com...
Quote:
Hey
Im a student and need help using matlab. im extremeley new to signal
processing so this is a pretty basic question, im hoping someone can help
me.

im removing noise from an ecg signal and i need to remove this noise at
20hz using a notch filter, sampling rate is 200hz. the matlab code is:

a=[x x x]
b=[x x x]
zfiltered=filter(a,d,z)

'z' is my noise corrupted signal, but how do i work out the coeffs needed
for 'a' and 'b'?
sorry for the "newbie" question but im in desperte need of help.

Well...since you have matlab, there are several tools (from beginner to
advanced) to help you.
You can either use 'fdatool' or 'sptool' - both give you fairly simple
interfaces to design filters. I suggest you start with an FIR filter (this
will make one set of your coeffs = 1, so you'd use filter(b,1,z) when you
invoke the matlab command).
The help files for either filter design program will give you plenty of info
on how to set various parameters.
Also, you need to know how good your notch filter needs to be at 20 Hz. If
you don't know how good, then you have more reading to do (ask your
professor or TA).

Cheers
Bhaskar
Back to top
john
Guest





Posted: Mon Dec 19, 2005 11:33 pm    Post subject: Re: notch filter to remove 20Hz noise of ECG signal Reply with quote

ashcroft2006 wrote:
Quote:
Hey
Im a student and need help using matlab. im extremeley new to signal
processing so this is a pretty basic question, im hoping someone can help
me.

im removing noise from an ecg signal and i need to remove this noise at
20hz using a notch filter, sampling rate is 200hz. the matlab code is:

a=[x x x]
b=[x x x]
zfiltered=filter(a,d,z)

'z' is my noise corrupted signal, but how do i work out the coeffs needed
for 'a' and 'b'?
sorry for the "newbie" question but im in desperte need of help.

Any help is much appreciated,
Mark

Here is some sample code that you can modify:

Fs = 8000;
Fn = 1000;

r = 0.99;
wz = 2*pi*Fn/Fs;
c = cos(wz);
bnotch=[1, -2*c, 1];
anotch=[1, -2*r*c, r*r];
y = filter(bnotch, anotch, x);
Back to top
Richard Owlett
Guest





Posted: Tue Dec 20, 2005 1:16 am    Post subject: Re: notch filter to remove 20Hz noise of ECG signal Reply with quote

ashcroft2006 wrote:

Quote:
Hey
Im a student and need help using matlab. im extremeley new to signal
processing so this is a pretty basic question, im hoping someone can help
me.

im removing noise from an ecg signal and i need to remove this noise at
20hz using a notch filter, sampling rate is 200hz. the matlab code is:


a=[x x x]
b=[x x x]
zfiltered=filter(a,d,z)


'z' is my noise corrupted signal, but how do i work out the coeffs needed
for 'a' and 'b'?
sorry for the "newbie" question but im in desperte need of help.

Any help is much appreciated,
Mark



I don't really wish to "rain on your parade"
*BUT*
Is your interference *ONLY* at 20 Hz?
Could it also be at harmonics of 20 Hz?

I assume that by "ecg" you mean "electrocardiogram" aka EKG.
More than 40 years ago, as a student tech, I was involved in recording
Electroencephalograph (EEG) traces of individual neurons. Back then I
did not understand "common mode" vs "normal mode" interference. The EE's
on this forum can appreciate just how far I got trying to "filter" the
noise :{

I said all this to say -- give more info ;)
Back to top
Jack Ace
Guest





Posted: Tue Dec 20, 2005 3:26 pm    Post subject: Re: notch filter to remove 20Hz noise of ECG signal Reply with quote

ashcroft2006 wrote:

Quote:
Hey
Im a student and need help using matlab. im extremeley new to signal
processing so this is a pretty basic question, im hoping someone can help
me.

im removing noise from an ecg signal and i need to remove this noise at
20hz using a notch filter, sampling rate is 200hz. the matlab code is:

a=[x x x]
b=[x x x]
zfiltered=filter(a,d,z)

'z' is my noise corrupted signal, but how do i work out the coeffs needed
for 'a' and 'b'?
sorry for the "newbie" question but im in desperte need of help.

Any help is much appreciated,
Mark

%%%%%%%%%%%%%%%%%%%%% Notch Filter
Fs = 200; % sampling freq [Hz]
Fn = Fs/2; % Nyquist freq [Hz]

W0 = 20; % notch frequency [Hz]
w0 = W0*pi/Fn; % notch frequency normalized

BandWidth = 5; % -3dB BandWidth [Hz]
B = BandWidth*pi/Fn; % normalized bandwidth

k1 = -cos(w0); k2 = (1 - tan(B/2))/(1 + tan(B/2));

b = [1+k2 2*k1*(1+k2) 1+k2];
a = [2 2*k1*(1+k2) 2*k2];

figure(1); % look at the frequency response of your filter
freqz(b,a);
title('sampling frequency 200Hz, notch @ 20HzHz, notch bandwidth 5Hz');

% z : your signal
zfiltered=filter(b,a,z);

% use different bandwidth for having different transient responses
% narrowing the bandwidth-> increasing transient duration
% if you want to check it, filter a unit step signal.
%%%%%%%%%%%%%%%%%%%%%%%%%%


Hope this could help
Bye

Jack
Back to top
Jerry Avins
Guest





Posted: Tue Dec 20, 2005 5:16 pm    Post subject: Re: notch filter to remove 20Hz noise of ECG signal Reply with quote

allanherriman@hotmail.com wrote:
Quote:
Richard Owlett wrote:

ashcroft2006 wrote:


I don't really wish to "rain on your parade"
*BUT*
Is your interference *ONLY* at 20 Hz?
Could it also be at harmonics of 20 Hz?


I was guessing that it was the third harmonic of 60Hz mains, aliased
down to 20Hz by the 200Hz sampler.

If that's the case, it could be possible to reduce the level of the
20Hz interference by cancelling it (e.g. by sampling the mains,
estimating the 20Hz component, then subtracting it from the ECG
signal), rather than by filtering it out.

It might also be possible to fix this with a 180 Hz notch or low pass
filter prior to sampling at 200Hz.

Or you could sample at some higher frequency, and eliminate the 180Hz
with a simple low pass filter.

These solutions give lower distortion of the wanted signal than a
simple 20Hz notch filter.

Allan,

If it is as you guess, I'd call it a failure of the anti-alias filter. I
don't see how cancellation would work if the sample clock and power line
weren't derived from the same master, and even so, the phase would
likely depend on the lead placement.

An important issue is whether the signals are already acquired, or if
the acquisition can be made cleaner. It does no good to filter the input
from the leads if there is hum on the power supply.

Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Back to top
Guest






Posted: Tue Dec 20, 2005 5:16 pm    Post subject: Re: notch filter to remove 20Hz noise of ECG signal Reply with quote

Richard Owlett wrote:
Quote:
ashcroft2006 wrote:

I don't really wish to "rain on your parade"
*BUT*
Is your interference *ONLY* at 20 Hz?
Could it also be at harmonics of 20 Hz?

I was guessing that it was the third harmonic of 60Hz mains, aliased
down to 20Hz by the 200Hz sampler.

If that's the case, it could be possible to reduce the level of the
20Hz interference by cancelling it (e.g. by sampling the mains,
estimating the 20Hz component, then subtracting it from the ECG
signal), rather than by filtering it out.

It might also be possible to fix this with a 180 Hz notch or low pass
filter prior to sampling at 200Hz.

Or you could sample at some higher frequency, and eliminate the 180Hz
with a simple low pass filter.

These solutions give lower distortion of the wanted signal than a
simple 20Hz notch filter.

Regards,
Allan
Back to top
Guest






Posted: Tue Dec 20, 2005 5:16 pm    Post subject: Re: notch filter to remove 20Hz noise of ECG signal Reply with quote

Jerry Avins wrote:
Quote:
allanherriman@hotmail.com wrote:
Richard Owlett wrote:

ashcroft2006 wrote:


I don't really wish to "rain on your parade"
*BUT*
Is your interference *ONLY* at 20 Hz?
Could it also be at harmonics of 20 Hz?


I was guessing that it was the third harmonic of 60Hz mains, aliased
down to 20Hz by the 200Hz sampler.

If that's the case, it could be possible to reduce the level of the
20Hz interference by cancelling it (e.g. by sampling the mains,
estimating the 20Hz component, then subtracting it from the ECG
signal), rather than by filtering it out.

It might also be possible to fix this with a 180 Hz notch or low pass
filter prior to sampling at 200Hz.

Or you could sample at some higher frequency, and eliminate the 180Hz
with a simple low pass filter.

These solutions give lower distortion of the wanted signal than a
simple 20Hz notch filter.

Allan,

If it is as you guess, I'd call it a failure of the anti-alias filter. I
don't see how cancellation would work if the sample clock and power line
weren't derived from the same master, and even so, the phase would
likely depend on the lead placement.

An important issue is whether the signals are already acquired, or if
the acquisition can be made cleaner.

This wasn't apparent from the OP's post :(

Quote:
It does no good to filter the input from the leads if there is
hum on the power supply.

PSU ripple on a supply rail would give even harmonics, and magnetic
leakage from the transformer would be mostly fundamental (I think), so
I assumed that the third was being picked up through capacitive
coupling from the mains to the body under test. Proper probing could
help here.

Too many guesses, and not enough information from the OP! I'll stop
now.

Regards,
Allan
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB