Error While Using the butter() function for IIR Butterworth filter design

I am using Matlab 2012a. My code for the design of IIR Butterworth filter is:
clc
clear all
Fs=1000;
fc=300;
WC=2*pi*fc;
N=5;
[b,a]=butter(N,WC,'s');
[z,p,k]=butter(N,WC,'s');
[bz,az]=ipminvar(b,a,Fs);
[h, f]=freqz(bz,az,512,Fs);
plot(f, 20*log10(asb(h))),grid;
xlabel('frequency(Hz)');
ylabel('Magnitude(dB)');
The error encountered after execution of the program is:
??? Attempt to execute SCRIPT butter as a function: E:\Academics\6th Sem\DSP Lab\Exp-8\butter.m
Error in ==> butter at 8 [b,a]=butter(N,WC,'s');
Signal Processing Toolbox is already present in my Matlab. I have checked it using
>>ver
Please help me to debug the problem.

 Accepted Answer

I don't see where you are using butter() at all in the code you have posted here. This is an FIR filter design. Did you copy and paste the wrong code?
At any rate, do not name a script, or variable the same name as an exisiting MathWorks' function. If you really have a script named butter.m on your path (E:\Academics\6th Sem\DSP Lab\Exp-8\butter.m) , then rename that to something like my_butter.m, anything but butter. Then enter
>>which butter
and make sure you get something like:
matlab\toolbox\signal\signal\butter.m
returned.

4 Comments

I am sorry. I had copied and pasted the wrong code. I have edited the pasted the correct code for butterworth filter in the question.
I even tried out by renaming the script as 'my_butter.m'. Now a new error has cropped up. The error is:
??? Undefined function or method 'ipminvar' for input arguments of type 'double'.
Error in ==> my_butter at 10
[bz,az]=ipminvar(b,a,Fs);
Entering >>which butter returns:
E:\MATLAB 2010a\toolbox\signal\signal\butter.m
Please help.
you spelled the function name incorrectly
impinvar
not ipminvar
BTW, you have another spelling error: it's abs() not asb()
plot(f, 20*log10(abs(h))),grid;
thanks a lot!! the program is working and I got the correct graph..

Sign in to comment.

More Answers (1)

This error
??? Attempt to execute SCRIPT butter as a function: E:\Academics\6th Sem\DSP Lab\Exp-8\butter.m
indicates that you have a butter.m on your path that shadowed MATLAB's butter() function. You need to either remove it from the path or change its name to something other than butter.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!