No BSD License  

Highlights from
Generic Signal Class

from Generic Signal Class by Stefan Bleeck
A generic class that allows easy signal (data in time) managment

filtered_sig=lowpass(sig,frequency,stopband,ripple,stopbandatten)
% method of class @signal
%
%   INPUT VALUES:
%
%   RETURN VALUE:
%
%
% (c) 2003, University of Cambridge, Medical Research Council
% Stefan Bleeck (stefan@bleeck.de)
% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual
% $Date: 2003/07/17 10:56:16 $
% $Revision: 1.6 $

function filtered_sig=lowpass(sig,frequency,stopband,ripple,stopbandatten)
% hack for an phase true lowpassfilter with cutoff at frequency
% used is a ButterworthFilter

if nargin < 5
    stopbandatten=60; % in dB - how many dB the signal is reduced in the stopband at least
end
if nargin < 4
    ripple=1; % in dB = ripple in the passband
end
if nargin <3
    stopband=frequency*2; % eine Oktave drber
end

nyquist=getsr(sig)/2;
% fre_low=2;
fre_high=frequency;

% Finde raus, wieviel Punkte der Filter dafr haben muss
Wpass=fre_high/nyquist;
Wstop=(fre_high+stopband)/nyquist;
Wstop=min(Wstop,0.999999);
try
    [n,Wn] = buttord(Wpass,Wstop,ripple,stopbandatten);
    % Berechne den IIR-Filter
    [b,a] = butter(n,Wn);

    vals=sig.werte';

    % fill the part behind the signal and in front of the signal with
    % values to avoid corner effects. this is probably not clever in all
    % cases...
    firstval=vals(1);
    lastval=vals(end);
    nr_vals=length(vals);
    vals=[ones(1,nr_vals)*firstval vals ones(1,nr_vals)*lastval];

    nvals = filtfilt(b,a,vals);
    % extract the values back
    nvals=nvals(nr_vals+1:2*nr_vals);

    filtered_sig=sig;	% a copy of the old one
    newname=sprintf('Lowpass filterd (%3.2fkHz) Signal: %s',frequency/1000,getname(sig));
    filtered_sig=setname(filtered_sig,newname);
    filtered_sig.werte=nvals';

catch
    disp('error: cant do the low pass filtering');
    filtered_sig=sig;
end

% figure(235423)
% plot(sig);
% hold on
% plot(filtered_sig,'g');
% s=0;

Contact us at files@mathworks.com