function y = passfilter(x, threshold, samplingFrequency)
% function y = passfilter(x, threshold, samplingFrequency)
% low or/and high pass filter
%
% x: orginal signal
% threshold: the frequency thresholds. It should be an array of length 2.
% The first component corresponds to the low pass filter threshold and the
% 2nd one corresponds to the high pass threshold. If you don¡¯t want to
% set the threshold, put nan.
% samplingFrequency: the sampling frequency of the original signal x.
% Default 10 Hz
%
% y: the result signal
%
% Note: this script needs signal toolbox
%
% Example:
% y=humps([0:.01:1])+randn(1,101)*10;
% figure;plot(y)
% hold on; plot(passfilter(y, [0.5, nan], 10), ¡®r¡¯)
%
% Xu Cui
% 2007-10-02
if nargin < 2
error(¡¯At least two arguments are required.¡¯);
end
if nargin < 3
samplingFrequency = 10;
end
if ~isfinite(threshold(1)) && ~isfinite(threshold(2))
y = x;
return
end
if isfinite(threshold(1)) && isfinite(threshold(2))
[b,a]=ellip(4,0.1,40,[threshold(2) threshold(1)]*2/samplingFrequency);
elseif isfinite(threshold(1))
[b,a]=ellip(4,0.1,40,[threshold(1)]*2/samplingFrequency);
elseif isfinite(threshold(2))
[b,a]=ellip(4,0.1,40,[threshold(2)]*2/samplingFrequency, ¡®high¡¯);
end
y = filtfilt(b,a,x);
return