1. .a. fWe fare fusing fthe fIRR ffilter fto fdetermine fthe fspectrum.

When f|z| f= f1, fthat fis fz f= fe fjω f, fthe foutput freduces fto fX(e fjω f)|H(e
fjω f)|2 f. fGiven fall fthe fsamples fas fin fthe fdata ffiles, fthe fsequence
fx(n), fa fdoubly ffiltered fversion fof fx fthat fhas fzero-phase fdistortion. fFor
fexample, fa f1-second fduration fsignal fsampled fat f100 fHz, fcomposed fof
ftwo fsinusoidal fcomponents fat f3 fHz fand f40 fHz, fis ffs f= f100; ft f=
f0:1/fs:1; fx f= fsin(2*pi*t*3)+.25*sin(2*pi*t*40); fNow fwe fcreate fa f10point faveraging fIRR ffilter, fand ffilter fx fusing fboth ffilter fand ffiltfilt ffor
fcomparison: fb f= fones(1,10)/10; f% f10 fpoint faveraging ffilter fy f=
ffiltfilt(b,1,x); f% fNoncausal ffiltering fyy f= ffilter(b,1,x); f% fNormal ffiltering

.b. fthe fnoise f(“wildtrack” for fEMG)
The fsignal fis fa f100 fHz fsine fwave fin fadditive fwhite fGaussian fnoise.
fSet fthe frandom fnumber fgenerator fto fthe fdefault fstate ffor
freproducible fresults. frng fdefault fFs f= f1000; ft f= flinspace(0,1,Fs); fx f=
fcos(2*pi*100*t)+0.5*randn(size(t)); ffc f= f150; fWn f= f(2/Fs)*fc; fb f=
ffir1(20,Wn,'low',kaiser(21,3)); ffvtool(b,1,'Fs',Fs)

fthe fsignal frecorded funder fnormal fconditions f(background fnoise. falong fwith fthe fnoise f(original fsignal fand fthen fthe ffiltered fsignal: Apply fthe ffilter fto fthe fsignal fand fplot fthe fresult ffor fthe ffirst ften fperiods fof fthe f100 fHz fsinusoid.1.x(1:100)) fhold fon fplot(t(1:100).e.x). fECG fwhile fsitting f/ fstanding f/ f. f. fplot(t(1:100).y(1:100)) fxlabel('Time f(s)') fylabel('Amplitude') flegend('Original fSignal'. f.'Filtered fData') .c. f) f The fbelow fsignals fshows fthe fsignal frecorded fin fnormal fconditions fi. fy f= ffilter(b.

fset fUnits fto fHz. . f• fSet fthe fDesign fMethod fto fFIR fand fselect fthe fWindow fmethod. fFs fto f1000. fselect fSpecify forder. f• fStart fFDATool fby fentering ffdatool fat fthe fcommand fline. fSet fthe forder fto f20.. fresponse fwhich fremoves fas fmuch fnoise fas fpossible fwhile fleaving fthe fsignal fintact f(i.e. f• fUnder fFilter fOrder. fmaximizes fsignal fto fnoise fratio This fexample fshows fhow fto fdesign fand fimplement fa flowpass fFIR ffilter fusing fthe fwindow fmethod fwith fthe finteractive ftool ffdatool.(d) fdetermine fthe fideal flowpass/bandpass/highpass/. fand fFc fto f150. f• fUnder fFrequency fSpecifications.. Set fthe fResponse fType fto fLowpass.

f f´ fy_out fis fthe ffilter foutput. fmxArray f*plhs[].x). f f Used fmex fwith fthe fC++ fcompiler fto fcompile fthe froutine # finclude f"mex. fThis fcan fbe fsamples fof fa fsignal fwith fM fchannels.2. fdenominator fcoeff. fin fA_in. fIt fis fassumed fthat fA_in fand fB_in fhave fthe fsame f f fnumber fof fcoefficients fand fthat fB_in[0]=1.h" void fmexFunction(int fnlhs. f f f f f fUsage: f fy=myfilter(A.B. f f f fand finput fsamples fin fx_in. The fbelow ffunction fImplements fan fIIR-Filter fwith frational ftransfer ffunction. fint fnrhs. fin fB_in. fconst fmxArray f*prhs[]) f{ #define fA_in fprhs[0] f #define fB_in fprhs[1] f . f f f fwhose fnominator fcoeff.

f*x. f int fn. f/* fnumber fof fdenominator fcoeff. x f= fmxGetPr f(x_in).")."). f*y. y f= fmxGetPr f(y_out). fof fthe ffilter f*/ if(n!=m) f/* fCheck fthe fnumber fof ffilter fcoefficients f*/ mexErrMsgTxt("ERROR: fUnequal fnumber fof ffilter fcoefficients fin fnominator fand fdenominator. fN. int fc f. else N f= fmxGetM(prhs[ f2 f]). f/* fnumber fof fsamples fto fbe ffiltered f f*/ M f= fmxGetN(prhs[ f2 f]). fmxREAL f). fM f. fm. fk. f/* fnumber fof finput fchannels f f*/ /* fCreate fmatrix ffor fthe freturn fargument f*/ y_out f= fmxCreateDoubleMatrix f(N f. B f= fmxGetPr f(B_in). f /* fAssign fpointers fto finput fand foutput f*/ A f= fmxGetPr f(A_in).#define fx_in fprhs[2] f f #define fy_out fplhs[0] double f*A. f*B. fM. else . if(B[0]!=1) f/* fCheck fthe fnormalization fof fB f*/ mexErrMsgTxt("ERROR: fFilter fcoefficient fB[0] fis fnot f1. fof fthe ffilter f f*/ m f= fmxGetNumberOfElements(B_in). f double fs. /* fThe finputs fmust fbe fnoncomplex fscalar fdouble f*/ n f= fmxGetNumberOfElements(A_in). fp. f/* fnumber fof fnominator fcoeff.

f f f f f f f f f f f f f} f f f f f f f f f fy[p+N*c]=s. fc++){ f f f f f f f ffor f(p=n.k<n.f f ffor f(c= f0. f f f f f f} f f}return. fc<M.k++){ f f f f f f f f f f fs= fs+A[k]*x[p-k+N*c]-B[k]*y[p-k+N*c]. fp++){ f f f f f f f f f fs=A[0]*x[p+N*c]. fp<N-1. f } . f f f f f f f f f ffor f(k=1.