filtfilt and filtfilthd give different results and behave differently under parallel for loop
Show older comments
These are actually two related questions.
First: I get two different results from filtfilt and filtfilthd. The latter gives the correct result, but the former gives an unstable result.
Second: when I try to use filtfilthd inside a parfor loop, I get an error message. Here is my code snippet and comments tell you what happens:
======
clear all, close all, clc
% design bandpass filter 80 - 600 Hz for a signal of Fs=1500,
% also get the matrix and scale values to use in filtfilt
Fs=1500;
h1 = fdesign.bandpass(75, 80, 600, 610, 60, 1, 80, Fs);
Hd = design(h1, 'cheby2', 'MatchExactly', 'stopband');
sos=Hd.sosMatrix ;
scale=Hd.ScaleValues;
%input signal is random noise of 200 seconds ,
sig=rand(Fs*200,1);
% first use filtfilthd , this produces correct output, as seen in
% figure(1), which is bound between -1 and 1
output1=filtfilthd(Hd, sig);
figure(1), plot(output1), title('output1')
% First problem: I use the matrix and scales of the same filter in filtfilt. THis
% produces an unstable output, which shoots up to 10^32 .
output2=filtfilt(sos, scale, sig);
figure(2), plot(output2,'r'), title('output2')
% open 4 labs, though this behavior happens with 2 or 12 labs which I tested.
desired_pool=4 ;
if ~matlabpool('size') %if no lab is open,
matlabpool('OPEN', desired_pool) % open the desired # of labs
sprintf('No Open Labs, Opened %d pools. \n', desired_pool)
end
% Use filtfilt method (that gave unstable output) inside parfor. Parfor
% works , but not surprisignly produces the same unstable results again.
% which -all filtfilt shows the correct version of filtfilt is used i.e.:
% Lab 1:
% /Applications/MATLAB_R2011b.app/toolbox/signal/signal/filtfilt.m
spmd
which -all filtfilt,
paroutput2=filtfilt(sos, scale, sig);
end
figure, plot(paroutput2{1}), title('parout2 (1)')
% Try to put the first version (filtfilthd) inside the parfor loop,
spmd
which -all filtfilthd,
paroutput1=filtfilthd(Hd, sig);
end
% I get this error message:
% Error using spmd_feval (line 8)
% Error detected on lab(s) 4
%
% Error in ParForError (line 31)
% which -all filtfilthd,
%
% Caused by:
%
% Coefficients must be nonempty.
%
% Error stack:
% schema>checkNonemptyVector at 54
% dtfwnum_setnumerator.m at 11
% setnumerator.m at 35
% df2.m at 44
% filtfilthd.m at 65
=============
As shown in the error message, it seems the coefficient are empty when filtfilthd is used inside parallel for loop. I made sure there are no other versions of filtfilt or filtfilthd on my machine (e.g Octave ones which behave erratic). My version is: MATLAB Version 7.13.0.564 (R2011b) Operating System: Mac OS X Version: 10.7.3 Build: 11D50b Java VM Version: Java 1.6.0_29-b11-402-11D50b with Apple Inc. Java HotSpot™ 64-Bit Server VM mixed mode
Answers (1)
Wayne King
on 17 Feb 2012
0 votes
filtfilthd is not a MathWorks' function. Beginning in R2011a, the MathWorks' function filtfilt accepts filters in biquad filter object form. Since I see you are using R2011b why not just use filtfilt() with filter objects in SOS form?
1 Comment
ArashMat Fazl
on 17 Feb 2012
Categories
Find more on Vibration 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!