filtfilt.m fails for input array x with 3 or more dimensions
7 次查看(过去 30 天)
显示 更早的评论
Dear all,
filtfilt.m does not work for ndim-arrays anymore, e.g.:
x = randn(1000,3,2); % i.e., random signal with 3x2 channels
[b,a] = butter(2,0.1); % 2nd order Butterworth lowpass filter
In older matlab versions, e.g., R2007b, I could say
fx = filtfilt(b,a,x);
and got the filtered signal fx with the same size as x. In R2011a the same command
fx = filtfilt(b,a,x);
returns the following error:
??? Error using ==> filter
Initial conditions must be a vector of length max(length(a),length(b))-1, or an array with the leading dimension of size max(length(a),length(b))-1 and with remaining dimensions matching those of x.
Error in ==> filtfilt>ffMultiChan at 296
yc3 = filter(b(:,ii),a(:,ii),xt,zo);
Error in ==> filtfilt at 78
y = ffMultiChan(b,a,x,zi,nfact,L);
My impression is that the dimensionality of the initial and final conditions, Zi and Zf is not correctly passed to filter.m.
Of course, I can circumvent the error by filtering data with maximal two dimensions, e.g., by reshaping before and after filtering or as follows:
fx = zeros(size(x)); % allocation
fx(:,:,1) = filtfilt(b,a,x(:,:,1));
fx(:,:,2) = filtfilt(b,a,x(:,:,2));
However, I just would like that filtfilt.m can handle n-dimensional input x as in earlier versions.
Thanks in advance for any help,
Helmut
0 个评论
回答(2 个)
Jan
2011-9-12
Does it help to specify the dimension to operate on?
You could try to use Fex: FiltFiltM, which is much faster than Matlab's implementation, while it replies identical values. FILTFILT wastes a lot of time with expanding the signal by initial and final phases, while FiltFiltM calculates the edges separately. In addition FILTFILT reverses the expanded signal twice, while FiltFiltM uses a fast C-mex to emulate FILTER with allowing to filter in teh reverse direction. In sonsequence FiltFiltM is 5 (short signal) to 20 (large signal) times faster.
0 个评论
Nitesh Chowdhury
2016-9-27
hi,
I'm new to using MATLAB and i'm using 2014a version, trying to filter a sensor signal which has a lot of noise. The data is in 1*16060double matrix. I have attempted multiple different variations of the command filtfilt but I keep getting errors. Also what should be the values for 'a' and 'b'?
I have already used transpose, converted into a 2*16060double matrix with time in the new row but nothing works. Here are the errors that I have got.
>
> filtfilt(1,10,ax)
Index exceeds matrix dimensions.
Error in filtfilt>ffMultiChan (line 320)
[~,zo] = filter(b(:,ii),a(:,ii),xt,zi(:,ii)*xt(1,:)); % outer product
Error in filtfilt (line 106)
y = ffMultiChan(b,a,x,zi,nfact,L);
>> filtfilt(1000,10000,ax)
Index exceeds matrix dimensions.
Error in filtfilt>ffMultiChan (line 320)
[~,zo] = filter(b(:,ii),a(:,ii),xt,zi(:,ii)*xt(1,:)); % outer product
Error in filtfilt (line 106)
y = ffMultiChan(b,a,x,zi,nfact,L);
>> filtfilt(17000,17000,ax)
Index exceeds matrix dimensions.
Error in filtfilt>ffMultiChan (line 320)
[~,zo] = filter(b(:,ii),a(:,ii),xt,zi(:,ii)*xt(1,:)); % outer product
Error in filtfilt (line 106)
y = ffMultiChan(b,a,x,zi,nfact,L);
>> filtfilt(17000,17000,ax)
Attempted to access xt(1); index out of bounds because numel(xt)=0.
Error in filtfilt>ffOneChan (line 260)
[~,zo] = filter(b(:,ii),a(:,ii), xt, zi(:,ii)*xt(1)); % yc1 not needed
Error in filtfilt (line 103)
y = ffOneChan(b,a,x,zi,nfact,L);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Digital Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!