Effacer les filtres
Effacer les filtres

filtfilt.m fails for input array x with 3 or more dimensions

7 vues (au cours des 30 derniers jours)
Helmut Riedel
Helmut Riedel le 12 Sep 2011
Modifié(e) : Jan le 28 Sep 2016
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

Réponses (2)

Jan
Jan le 12 Sep 2011
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.

Nitesh Chowdhury
Nitesh Chowdhury le 27 Sep 2016
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);
  1 commentaire
Jan
Jan le 28 Sep 2016
Modifié(e) : Jan le 28 Sep 2016
Please post a new question in a new thread and not as an answer of another question. Thanks.
Do you get the same error for this code:
ax = rand(1, 16060);
y = filtfilt(1,10,ax);
?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by