butterworth filter, does not work selectively
Show older comments
Hello MATLAB users,
I'm a relatively new user of MATLAB. This may be a simple question, but it seems to be beyond my current skills and knowledge. I much appreciate it if anyone can give me some thought.
I have access to two MATLABs. One at home (student version); the other at work (a different version). I'm working on the butterworth filter. Somehow, it works at work, but it doesn't at home.
Here are two ways that 'butter' doesn't work only at home.
1. It gives an error, and this happens when the order is 2, 3, 4, etc. % eg. I want to make a 2nd order lowpass butter filter at 1k Hz srate = 48000; [b,a] = butter(2, 1000/srate/2);
??? Attempted to access den(3); index out of bounds because numel(den)=2.
Error in ==> zp2ss at 134 a1 = t\[-den(2) -den(3); 1 0]*t;
Error in ==> butter at 73 [a,b,c,d] = zp2ss(z,p,k);
2. It does not give me an error but the filter does not seem to filter. eg. I want to lowpass white noise at 1k Hz deltat = duration/1000; srate = 48000; t = linspace(0, deltat, deltat*srate); noise = randn(1, length(t)); [b,a] = butter(1, 1000/srate/2); % this gives me a = b = 6.4670 new_noise = filter(b,a,noise); wavplay(new_noise, srate) % this sounds just like wavplay(noise, srate)
My further observation
1. If I make the same lowpass filter by using Filter Design & Analysis Tool box at home, I can successfully make this lowpass filter. 2. For both cases, I have no trouble using the 'butter' function at work.
Thank you very much for your thought. -Osamu
Accepted Answer
More Answers (3)
Wayne King
on 3 Mar 2012
0 votes
Hi Osamu, Is it possible that you have a non-MathWorks version of zp2ss at home?
If you enter
>>which zp2ss
what path is returned?
Is it something like:
matlab\toolbox\shared\controllib\general\zp2ss.m
My suspicion is that you have another zp2ss.m which precedes the MathWorks' version on your path.
1 Comment
Osamu Takai
on 3 Mar 2012
Wayne King
on 4 Mar 2012
Hi Osamu, That is the correct path for R2011a. I'm wondering if you have some other function which is not a MathWorks' function (perhaps something being called by zp2ss.m, which calls several functions).
Can you try something:
Restart MATLAB and make sure you do not have any added paths where you may have your own .m files, or .m files you have obtained from some non-MathWorks source.
You can examine these paths with:
>>path
I have no problem with this line in R2011a:
srate = 48000; [b,a] = butter(2, 1000/srate/2);
1 Comment
Osamu Takai
on 4 Mar 2012
Osamu Takai
on 4 Mar 2012
0 votes
3 Comments
Wayne King
on 4 Mar 2012
The output of path shows you the order in which MATLAB searches the path for an .m file (and other things). So if you have a folder on the path (including the current folder, which is always on the path), that comes before the folder where the MathWorks' function lives, then you are not using the MathWorks version.
Daniel Shub
on 4 Mar 2012
MATLAB has a complicated rule about what functions it uses. Eventually, it gets to the search path (after checking the current workspace and current directory). You can see the search path with the command path.
Osamu Takai
on 5 Mar 2012
Categories
Find more on Filter Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!