I've read up a lot about this, but haven't been able to piece everything together successfully, so I'm looking for some help.

I need to filter 50 Hz from a signal. It looks like the best options are either a notch filter or a LMS filter, but I don't have a copy of the noise so a notch filter seems to be the best choice.

I don't need the frequencies normalised, as I know the sampling frequency (16kHz), and the duration is 30 seconds. The bandwidth can be fairly tight, 49.5Hz ~ 50.5Hz should be fine.

It looks like I need to use a combination of filter and iirnotch, but I'm not entirely sure how.

If someone can bring this all together I would greatly appreciate it. Thanks.

  • $\begingroup$ I want to ask how the autoregressive filter simulation on damping/redaman??? $\endgroup$
    – user10285
    Commented Jun 22, 2014 at 5:42
  • $\begingroup$ How to define 'x' in above program (where 'x' is a signal input)... thanks $\endgroup$
    – user18358
    Commented Nov 19, 2015 at 12:45

2 Answers 2


I'm not sure what iirnotch does, but this is how to design the notch filter by hand.

fs = 20000;             % sampling rate
f0 = 50;                % notch frequency
fn = fs/2;              % Nyquist frequency
freqRatio = f0/fn;      % ratio of notch freq. to Nyquist freq.

notchWidth = 0.1;       % width of the notch

% Compute zeros
notchZeros = [exp( sqrt(-1)*pi*freqRatio ), exp( -sqrt(-1)*pi*freqRatio )];

% Compute poles
notchPoles = (1-notchWidth) * notchZeros;

zplane(notchZeros.', notchPoles.');

b = poly( notchZeros ); %  Get moving average filter coefficients
a = poly( notchPoles ); %  Get autoregressive filter coefficients


% filter signal x
y = filter(b,a,x);
  • $\begingroup$ Simple and elegant. I understand that the smaller notchWidth, the smaller the width of the notch will be, but does notchWidth relate to a concrete quantity? $\endgroup$
    – Lolo
    Commented Mar 9, 2016 at 3:06
  • $\begingroup$ @Lolo I don't think it does. I just picked it because it seemed like a convenient number. $\endgroup$
    – Phonon
    Commented Mar 9, 2016 at 4:25

You can just type help iirnotch and then see the following example:

% Design a filter with a Q-factor of Q=35 to remove a 60 Hz tone from 
% system running at 300 Hz.
Wo = 60/(300/2);  BW = Wo/35;
[b,a] = iirnotch(Wo,BW);  

If you replace the 60 with 50 Hz and then do:

Y = filter(b,a,X)

It should work (with X your data)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.