MATLAB: Butterworth Notch Filters

butterworthfilter designSignal Processing Toolbox

I'm designing a simple 60 Hz butterworth notch filter like this
[b a] = butter(n, [59 61]./(fs/2), 'stop');
When I use fvtool to look at the magnitude and phase response everything looks fine until I make n>=5, then both responses start to go all of the place. My magnitude response no longer looks like a notch.
My suspicion is that there is some roundoff error going on somewhere , but I'm unsure. Also, on my machine
>> eps
ans =
2.22044604925031e-16
Thanks for any help.

Best Answer

For higher order filters (possibly starting as low as order 8), numerical problems due to roundoff errors may occur when forming the transfer function using the [b,a] syntax. You can avoid this by using the [z,p,k] syntax to design IIR filters. Here is an example:
[z p k] = butter(10, [59 61]./(fs/2), 'stop'); % 10th order filter
[sos,g]=zp2sos(z,p,k); % Convert to 2nd order sections form
h=dfilt.df2sos(sos,g); % Create filter object
fvtool(h);