Error with butter function
Show older comments
I have been having this problem for a while now on my matlab 2020b while using the butter function to create a bandpass filter for a continous waveform seismogram. My input is in accordance to what is in the documentation
I created a bandpass filter function first
function [ ts ] = bandpassfilt( ts, dt, high, low )
[n ,q] = size(ts);
tap = tukeywin(n, 0.1);
[b,a] = butter(1,[low, high].*(2*dt),'bandpass');
for i = 1:q
ts(:, i) = single(filtfilt(b,a,double(ts(:, i).*tap).*tap));
end
end
clc
clear
close all
Then created a script named "quick filt" to filter and plot
load trace
%samples and timing
sps = 250; %node sample rate
dt = 1/sps;
%data_samps = 60*60*250;
% body wave filter bandwidth ~0.5-2 Hz
P_low = .5;
P_high = 2;
dat_filt_Z_p = bandpassfilt(trace', dt, P_high, P_low);
%% quick plot
figure
subplot(2,1,1)
plot(trace)
title('Unfiltered')
subplot(2,1,2)
plot(dat_filt_Z_p)
title('Filtered')
It gives the error
Error using *
Inner matrix dimensions must agree.
Error in butter>buttnum (line 179)
b = real(b*(kern*den(:))/(kern*b(:)));
Error in butter (line 133)
num = buttnum(btype,n,Wn,Bw,analog,den);
Error in bandpassfilt (line 7)
[b,a] = butter(1,[low, high].*(2*dt),'bandpass');
Error in quick_filt (line 16)
dat_filt_Z_p = bandpassfilt(trace', dt, P_high, P_low);
I am also getting errors for using the lines of code given as example in the documentation
Input
low=0.5;
high=2;
dt=1/250;
[b,a] = butter(1,[low, high].*(2*dt));
Error
Index exceeds matrix dimensions.
Error in zp2ss (line 131)
a1 = t\[-den(2) -den(3); 1 0]*t;
Error in butter (line 97)
[a,b,c,d] = zp2ss(z,p,k);
4 Comments
Mathieu NOE
on 2 Apr 2021
Edited: Jan
on 6 Apr 2021
hello
your code works on my R2020b without any issue
funny the my butter function does not have the
zp2ss
function in line 131 where your error appears , so I wonder if your version of butter is corrupt or ?
this is mine :
% [CODE removed due to:]
% Copyright 1998-2019 The MathWorks, Inc.
Olumide Adedeji
on 6 Apr 2021
Mathieu NOE
on 6 Apr 2021
Well, you probably should ask the technical support of the vendor....
DGM
on 6 Apr 2021
Is it possible that the function butter() has been overloaded?
Answers (0)
Categories
Find more on Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!