DSPRelated.com
Forums

How to write a NotchFilter procedure

Started by gpdsoft June 5, 2006
Oops...obviously I meant to say that the notch for the second harmonic
should be at 100Hz.

'scuse the confusion....

Rick Lyons wrote:
> On Mon, 05 Jun 2006 12:51:37 -0500, "gpdsoft" <gpdsoftware@yahoo.it> > wrote: > > >Hi, > >I have do write a procedure in Delphi that take an array of samples and > >filters it. > > > >The filter I've to do is Notch to cut out the 50Hz from my signal. > > > >My signal is sampled at 50Khz for a max of 250 millisec. > > > >Do you know where I can find the code or something similar to quickly > >implement this function in my software? > > > >Thnx a lot > > Hello gpdsoft, > > Implement a filter whose time-domain > expression is: > > y(n) = x(n) + Kx(n-1) + x(n-2). > > Variable y(n) is the filter's output, and variable > x(n) is the filter's input. > > The value for K is: > > K = -2cos(2*pi*fn/fs) > > where fn is 50 Hz, and fs is 50 kHz. > > Good Luck, > [-Rick-]
Hi,
I think I've resolved my problem... thnx to all for the help!
This is the code I used to notch 50Hz from my signal (the code is in
Delphi/pascal language)

//CC is the array of samples to filter
CutFreq:=50;  //50Hz
FS:=50000;    //SampleRate 50KHz

for n:=0 to CC.length-1 do
 begin
   cos50:=(cos(((2*pi)*CutFreq * n)/FS) );
   sin50:=(sin(((2*pi)*CutFreq * n)/FS) );

   I:=CC[n]* cos50;
   Q:=CC[n]* sin50;

   TotI:=TotI+(I);
   TotQ:=TotQ+(Q);
 end;

for n:=0 to CC.Length-1 do
 begin
   cos50:=(cos(((2*pi)*CutFreq * n)/FS) );
   sin50:=(sin(((2*pi)*CutFreq * n)/FS) );

   Tone:=(2/OriginalSignal.length)*(TotI*cos50 + TotQ*sin50);
   CC[n]:=CC[n]-Tone;
 end;

This code works well!