|
"Wayne King" <wmkingty@gmail.com> wrote in message <ih9d78$8br$1@fred.mathworks.com>...
> "vinay " <vinay9023remove.this@gmail.com> wrote in message <ih8kgg$4oj$1@fred.mathworks.com>...
> > Here is the code:
> > I've used MIT-BIH105 record from the physionet database.
> >
> > fs=334;
> > N=length(data);%data is the imported signal i.e rec105
> > t = ((0:length(data)-1)./fs);
> > t=t';
> > noise=0.5*sin(2*pi*60*t);
> > input=data+noise;
> > subplot(2,1,1);
> > plot(t,input);
> > title('Noise Corrupted ECG Signal'); xlabel('Time [sec]'); ylabel('Amplitude');
> > Ys = fft(input)/N;
> > equal_space=linspace(0,.5,N/2);
> > freq = fs*equal_space;
> > Ys = Ys(1:ceil(N)/2);
> > subplot(2,1,2);
> > plot(freq,2*abs(Ys));
> > title('ECG signal in Frequency Domain'); xlabel('Frequency (Hz)'); ylabel('|Y(f)|');
> > F_0=60;
> > Delta_F=1;
> > [b,a] = f_iirnotch (F_0,Delta_F,fs);%creates coefficient vectors a and b
> > refined1=filter(b,a,input); %filter signal
> > figure;
> > subplot(2,1,1);
> > plot(t,refined);
> > d1=refined1-data;
> > hold;plot(t,data,'r');% red plot is of the pure signal
> > Delta_F=3;
> > [b,a] = f_iirnotch (F_0,Delta_F,fs);%creates coefficient vectors a and b
> > refined2=filter(b,a,input); %filter signal
> > d2=refined2-data;
> > subplot(2,1,2);
> > plot(t,refined2);
> >
> >
> > f_iirnotch is a function to find out the coefficients of the notch filter
> >
> > function [b,a] = f_iirnotch (F_0,Delta_F,fs)
> >
> > fs = f_clip (fs,0,fs);
> > F_0 = f_clip (F_0,0,fs/2);
> > Delta_F = f_clip (Delta_F,0,fs/4);
> > r = 1 - (Delta_F*pi/fs);%pole radius
> > theta_0 = 2*pi*F_0/fs;
> > b_0 = abs(1 - 2*r*cos(theta_0) + r^2)/(2*abs(1-cos(theta_0)));%gain factor
> > b = b_0*[1,-2*cos(theta_0),1];%num coefficients
> > a = [1,-2*r*cos(theta_0),r^2];%den coefficients
> >
> > function y = f_clip (x,a,b,k,s)
> >
> > % F_CLIP: Clip a value, or a calling argument, to an interval
> > %
> > % Usage: y = f_clip (x,a,b,k,s)
> > %
> > % Inputs:
> > % x = input to be clipped
> > % a = lower limit of clip range
> > % b = upper limit of clip range
> > % k = an optional integer specifying the number of
> > % the calling argument
> > % s = an optional string specifying the name of the
> > % function being called.
> > % Outputs:
> > % y = x clipped to interval [a,b]. If a <= x <= b,
> > % then y = x.
> > %
> > % See also: F_DEADZONE, F_WAIT, F_PROMPT
> >
> > y = min(x,b);
> > y = max(y,a);
> > if (nargin >= 5) & (y ~= x)
> > fprintf ('\nCalling argument %d of %s was clipped to [%g,%g].\n',k,s,a,b);
> > end
> >
> >
> > So this is the code..i hope you can figure it out
>
> Hi Vinay, before I attempt to look at all this code (this was a bit more information than I intended to get :) ), do you have the Filter Design Toolbox? If so, I think you should use iirnotch
>
> Wayne
Hi Vinay, I see from the earlier posts that you must have iirnotch() and I see that your function is just a reimplementation of the 2nd order IIR notch filter in iirnotch(). The bandwidth of the notch appears to be correct to me.
Wayne
|