Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

Removing 60Hz from ECG using digital band stop filter

Let’s make a filter, which filters off the 60Hz frequency from the ECG signal. As we know, the American power supply is 60Hz. This is a common noise in biomedical signals while the industrial power supply powers them. This type of noise can be defined easily and can be filtered as parameters of noise are known.
Here is one example of how to implement an FIR filter using mathematical tools, like Matlab. This can be done using a microcontroller, like ARM or even AVR, because the frequencies are up to 1 kHz.
Initial conditions:

f0=60Hz – power supply frequency;
fs=500Hz – sampling rate;
frequencies who define complex zeros:

we get w0=0.754;
Positions of complex zeros:

Zeros and poles in z plane

System Function

From it we can calculate filter coefficients:

And filter coefficients: b3 = 1; b2 = -2cos(w0); b1 = 1

Also we know that:

And here we get filter characteristics:

We have a band stop filter at 60Hz, and its jam at 60Hz is -300dB. Bellow is a filter structure:

Now using this filter we can filter ECG signal:

As you can see, this is a simple FIR filter. In other words, there is nothing more than an average function that doesn’t need many resources. The other benefit of the FIR filter is that we can get linear Phase characteristics; therefore filtered signal isn’t distorted because of different spectra frequency delay. As a result, we see that ECG becomes more smooth. FIR filter

21 Comments:

  1. Good article.

  2. Click right mouse button and select open/view image for better image quality.

  3. hi, i’m developping an application for removing 60 Hz noise from ECG diagram, and i’m newbie in all of this.
    I have an array on 2000 points for 4 secs. So Fs=500Hz, how can i remove the 60 Hz noise.

    Ok…if i anderstood w0=0.754 and If the sampling frequency is 500 Hz, the zero at +43,2 degres will completely eliminate any signal at
    60 Hz is it correct??

  4. As far as I remember yes. Because we get band-stop filter at 60Hz.

  5. hello Dear
    I want remove 50Hz noise of EKG with 500Hz sps. please help me for writing m file(mATLAB pROG.) of your technic.

  6. Just change
    w0=2*pi*((60)/(fs));
    to
    w0=2*pi*((50)/(fs));
    in attached file bellow article. That should help.

  7. hi
    i want to remove 50Hz noise of ECG..please help me where i can find the source code..i prefer c language..please help me..

  8. The Fs in the zip file is 200, why?

  9. Probably a mistake, but as ECG signal is low freq, it is even enough of 200Hz sampling freq.

  10. Hi,
    I am using digital filters,but since i am new to this concept,i have stuck at one doubt.Please help me out. i am designing a LPF having 6Hz & 30Hz passband & stopband edge freq Also Fs(Sampling) is 512Hz. I have got the filters coefficient by implementing it in matlab but on the site from where i am taking guidance of this topic they have got coeff. in integer forms like

    //Lowpass FIR filter coefficients for 17 taps to filter > 30Hz
    static const int coeffslp[9] = {
    5225, 5175, 7255, 9453, 11595, 13507, 15016, 15983, 16315 };//

    I am not getting that how can we get such a large integer no. as a coeff.Is there any scaling process.
    Please guide me about this

  11. Hi,

    am working on something like that and am trying to understand your article. You are talking about a sample frequency of 500Hz, but yout code only works with 200Hz. i tried to tune it to get it to work, but that didn’t help at all ^^.
    So why the fs=200 in the code?

  12. Probably it was left after some tweaks. The change of fs to 500 didn’t work?

  13. Have you tried with IFIR filters and FRM technique for ECG signal?

    Probe this code in MATLAB with fs=600Hz
    High-Pass=0.05Hz
    Notch=60Hz,120Hz
    Low-Pass=250Hz

    close all
    hm1=firpm(42,[0 .0200 .04 .5]*2,[1 1 0 0],[1 20]);
    fc1=fft(hm1,512);
    hm1=hm1*(1/fc1(1));
    hm1i=upsample(hm1,10);
    hm11=conv(hm1i,hm1i);
    ind=(20*(length(hm1)-1))/2+1;
    hm11n=-hm11;
    hm11n(ind)=hm11n(ind)+1;
    fvtool(hm1,1,hm11,1,hm11n);
    fvtool(hm11n);
    hm2=firls(36,[0 .21 .3 .5]*2,[1 1 0 0],[1 10]);
    hm12=conv(hm11n,hm2);
    fvtool(hm12,1);

  14. hi,
    iam working on ecg signal spectral estimation..
    iam new to signal processing… i need to sample my signal 500hz.. after that i need to eliminate the frequencies above 35Hz and after that i need to apply fft for specturl estimation..
    and one more dought is .. which filter is the best for ecg signal analysis… waiting for reply

  15. hi

    where is the code plz?

  16. Just one observation: this filter is active, his gain is greater than one for some frequencies. Original signal is in [-1, 3], the filtered is in [-10, 20].

    So, if just the shape is needed (this case), no problem.

    Cya.

  17. Any of you can send me matlab code for 60hz noise filter?

  18. I hope to help me what is the input in ecg_signals file

  19. Hi, I tried to implement the code metioned above.

    Unfortunately, when i evaluating it with MIT-BIH database case, it would not filter the 60Hz, instead, it will added 60Hz into the orignal ECG signal and I was confusing now..

    I implemented the code as shown as below:

    w0=2*pi*((60)/(fs));
    G=1/(2-2*cos(w0));

    %z1=cos(w0)+j*sin(w0);
    %z2=cos(w0)-j*sin(w0);

    Fecg=filter( [1/G, -2*cos(w0)/G, 1/G],1, ecg);

Leave a Reply