Hi, I'm having problem getting rid of a 2kHz sine wave from a digitized signal at 128kHz. I do know the exact frequency of the 2kHz (I generate it in the first place with a DDS), but the phase/amplitude are unknown (it goes through DAC->ADC. Now, there seems to be two approach to do this, and I don't know what would be best. 1) Simple IIR 2nd order notch filter. I can center the notch at exactly 2kHz. It gets trick when quantizing the coefficients but it seems doable to get 60dB with 14 bits. The problem is that the notch has to be very narrow to avoid huge ringing in the step response. Is there a way to improve the step response here? 2) Use some kind of adaptive scheme to find out the 2kHz sine/cosine component in the incoming signal and remove it. I wouldn't know where to start with such an approach. Can anyone elaborate on what the time domain response would be when compared to the simple notch? This is all real time. Thanks!

# Best way to remove a known frequency

Started by ●March 23, 2010

Reply by ●March 23, 20102010-03-23

On Mar 23, 9:41�am, "gretzteam" <gretzteam@n_o_s_p_a_m.yahoo.com> wrote:> Hi, > I'm having problem getting rid of a 2kHz sine wave from a digitized signal > at 128kHz. I do know the exact frequency of the 2kHz (I generate it in the > first place with a DDS), but the phase/amplitude are unknown (it goes > through DAC->ADC. > > Now, there seems to be two approach to do this, and I don't know what would > be best. > > 1) Simple IIR 2nd order notch filter. I can center the notch at exactly > 2kHz. It gets trick when quantizing the coefficients but it seems doable to > get 60dB with 14 bits. The problem is that the notch has to be very narrow > to avoid huge ringing in the step response. � > Is there a way to improve the step response here? > > 2) Use some kind of adaptive scheme to find out the 2kHz sine/cosine > component in the incoming signal and remove it. I wouldn't know where to > start with such an approach. Can anyone elaborate on what the time domain > response would be when compared to the simple notch? > > This is all real time. � > > Thanks!The notch approach is simplest but instead of trying it with a single very high "q" 2nd order filter, just cascade several lower "q" 2nd order filters in series. IHTH, Clay

Reply by ●March 23, 20102010-03-23

>The notch approach is simplest but instead of trying it with a single >very high "q" 2nd order filter, just cascade several lower "q" 2nd >order filters in series. > >IHTH, >ClayHi, Are you saying a few even narrower notch in series with slightly different center frequency? Thanks!

Reply by ●March 23, 20102010-03-23

On Mar 23, 9:41 am, "gretzteam" <gretzteam@n_o_s_p_a_m.yahoo.com> wrote:> Hi, > I'm having problem getting rid of a 2kHz sine wave from a digitized signal > at 128kHz. I do know the exact frequency of the 2kHz (I generate it in the > first place with a DDS), but the phase/amplitude are unknown (it goes > through DAC->ADC. > > Now, there seems to be two approach to do this, and I don't know what would > be best. > > 1) Simple IIR 2nd order notch filter. I can center the notch at exactly > 2kHz. It gets trick when quantizing the coefficients but it seems doable to > get 60dB with 14 bits. The problem is that the notch has to be very narrow > to avoid huge ringing in the step response. > Is there a way to improve the step response here? > > 2) Use some kind of adaptive scheme to find out the 2kHz sine/cosine > component in the incoming signal and remove it. I wouldn't know where to > start with such an approach. Can anyone elaborate on what the time domain > response would be when compared to the simple notch? > > This is all real time. > > Thanks!60 dB sounds pretty aggressive for a subtraction scheme, but it may be possible. You need to use a PLL to generate a 2 kHz sine wave in phase with your incoming signal (better, use your original source). By using a LPF with a very low cutoff in the PLL, it will not respond to transient components in your desired signal. You need then to measure the amplitude of the interfering tone. Then you can subtract the output of the PLL with the appropriate amplitude. If it is constant, you can adjust the level of the subtracted tone until you optimize the result. Otherwise you will need a narrow band pass to measure it in real time. I can't say that you will get 60 dB of attenuation. That would mean you have to match the phase very accurately and match the subtracted tone amplitude to the interfering tone to at least an accuracy of 0.1%. Think you are up to that? Rick

Reply by ●March 23, 20102010-03-23

gretzteam wrote:> Hi, > I'm having problem getting rid of a 2kHz sine wave from a digitized signal > at 128kHz. I do know the exact frequency of the 2kHz (I generate it in the > first place with a DDS), but the phase/amplitude are unknown (it goes > through DAC->ADC. > > Now, there seems to be two approach to do this, and I don't know what would > be best. > > 1) Simple IIR 2nd order notch filter. I can center the notch at exactly > 2kHz. It gets trick when quantizing the coefficients but it seems doable to > get 60dB with 14 bits. The problem is that the notch has to be very narrow > to avoid huge ringing in the step response. > Is there a way to improve the step response here?The widest possible notch filter has a denominator of z^2, and will only 'ring' for two steps -- but it may be a bit too wide for you. You could play with longer, narrower FIR notch filters, if you don't mind their "FIR"-ness. Like Clay said -- multiple, lower-Q (wider) filters in cascade will probably help. This would approach the performance of the above-mentioned FIR notch, with all the attendant complications of using an IIR filter. If it makes sense, you could use a notch filter whose gains can be switched -- make it wide to acquire the tone, then narrow it up as time goes by to avoid the ringing on a step. This is a good place to use a Kalman filter* in fact, or to start by designing a Kalman filter to take out the tone, then treat it as a probably-too-complicated time-varying filter that you then simplify to your desires and needs. For that matter, you could make your time-varying filter adaptive, by sensing when seriously mis-estimating the tone. This is a minefield, because distinguishing between a badly-estimated tone and noise gets iffy, but depending on your requirements it may be a necessary one.> 2) Use some kind of adaptive scheme to find out the 2kHz sine/cosine > component in the incoming signal and remove it. I wouldn't know where to > start with such an approach. Can anyone elaborate on what the time domain > response would be when compared to the simple notch?a: Lock onto the tone with a PLL. If you know the frequency _exactly_ then you just need to find phase and amplitude; if there is much phase uncertainty then you'll need to adjust frequency as well. Done right this is going to end up behaving an awful lot like a notch filter, so there's really only a tactical gain here -- if the PLL solution with all its decorations is easier for you to understand and explain in your documentation than the notch filter, that's the way to go. a1: The PLL can be made to be time varying easier than the Kalman can, ditto with adaptive. a2: The PLL approach will probably be more complex than the IIR notch approach, but if the code is more clear... * If you search through the group you'll see me stomping on the notion of a Kalman filter as grasping for a magic solution -- so you know I must be serious here! -- Tim Wescott Control system and signal processing consulting www.wescottdesign.com

Reply by ●March 23, 20102010-03-23

gretzteam wrote:> Hi, > I'm having problem getting rid of a 2kHz sine wave from a digitized signal > at 128kHz. I do know the exact frequency of the 2kHz (I generate it in the > first place with a DDS), but the phase/amplitude are unknown (it goes > through DAC->ADC. > > Now, there seems to be two approach to do this, and I don't know what would > be best. > > 1) Simple IIR 2nd order notch filter. I can center the notch at exactly > 2kHz. It gets trick when quantizing the coefficients but it seems doable to > get 60dB with 14 bits. The problem is that the notch has to be very narrow > to avoid huge ringing in the step response. > Is there a way to improve the step response here? > > 2) Use some kind of adaptive scheme to find out the 2kHz sine/cosine > component in the incoming signal and remove it. I wouldn't know where to > start with such an approach. Can anyone elaborate on what the time domain > response would be when compared to the simple notch? > > This is all real time. > > Thanks!I'm over 4 decades out of date, but I suspect that you have omitted specifications which might make you life simpler. Is your system: 1. linear? 2. time invariant? 3. passive? Do you need "real time" as opposed to "post processing"? What is relevant definition of "real time"? (Hint -- an analytical solution may be massively complex. reality *MAY* be simpler ;/ In other words - what is problem you set out to solve?

Reply by ●March 23, 20102010-03-23

>The widest possible notch filter has a denominator of z^2, and will only >'ring' for two steps -- but it may be a bit too wide for you. You could >play with longer, narrower FIR notch filters, if you don't mind their >"FIR"-ness. > >Like Clay said -- multiple, lower-Q (wider) filters in cascade will >probably help. This would approach the performance of the >above-mentioned FIR notch, with all the attendant complications of using >an IIR filter.Ok am I completely missing something here? I'm playing with a 2nd order IIR notch filter in FDATOOL, and the wider the notch, the larger amplitude of the ringing. This is why I have to go to a very narrow notch (500Hz gives manageable ringing). Am I doing this wrong?>a1: The PLL can be made to be time varying easier than the Kalman can, >ditto with adaptive. > >a2: The PLL approach will probably be more complex than the IIR notch >approach, but if the code is more clear...I've been learning about the Goertzel algorithm, which seems to be a clever way to find the I and Q of a given tone. Would this be a good way to start and avoid having to go through adaptive filters and PLL? The output of the Goertzel 'filter' is basically the DFT output coefficient for that bin. It updates every N output, which can be a parameter. I got this stuff from 'Understanding Digital Signal Processing' by R. Lyons. Thanks!

Reply by ●March 23, 20102010-03-23

gretzteam wrote:>> The widest possible notch filter has a denominator of z^2, and will only >> 'ring' for two steps -- but it may be a bit too wide for you. You could >> play with longer, narrower FIR notch filters, if you don't mind their >> "FIR"-ness. >> >> Like Clay said -- multiple, lower-Q (wider) filters in cascade will >> probably help. This would approach the performance of the >> above-mentioned FIR notch, with all the attendant complications of using >> an IIR filter. > > Ok am I completely missing something here? I'm playing with a 2nd order IIR > notch filter in FDATOOL, and the wider the notch, the larger amplitude of > the ringing. This is why I have to go to a very narrow notch (500Hz gives > manageable ringing). Am I doing this wrong? >No. That's to be expected. The step function has a certain amount of energy around the notch frequency, and when you take that out everything else rings around it. But Clay and I aren't saying you should reduce the Q of one filter, we're saying you should use multiple filters with reduced Q. The only way to reduce the energy in the ring is to reduce the width of the notch -- you do that either by increasing the Q of your single filter, or by cascading multiple filters. So reducing the Q _of one filter_ will increase the ring amplitude, and make the ringing die out quicker. Increasing it will do the opposite. Adding more lower Q filters should (I haven't tried it) both reduce the amplitude and the length of the ring. That can't be a bad thing.>> a1: The PLL can be made to be time varying easier than the Kalman can, >> ditto with adaptive. >> >> a2: The PLL approach will probably be more complex than the IIR notch >> approach, but if the code is more clear... > > I've been learning about the Goertzel algorithm, which seems to be a clever > way to find the I and Q of a given tone. Would this be a good way to start > and avoid having to go through adaptive filters and PLL? The output of the > Goertzel 'filter' is basically the DFT output coefficient for that bin. It > updates every N output, which can be a parameter. > I got this stuff from 'Understanding Digital Signal Processing' by R. > Lyons.The Goertzel filter is just a bandpass filter that you run for a finite amount of time. A notch filter is just your signal minus the output of a bandpass filter. So a scheme that uses a Goertzel filter to periodically measure amplitude and phase is _probably_ not going to work as well as a notch filter. Besides, there are better methods than Goertzel filters if you happen to be on a processor with oodles of resources compared to your problem, as is often the case these days. -- Tim Wescott Control system and signal processing consulting www.wescottdesign.com

Reply by ●March 23, 20102010-03-23

On Mar 23, 10:20�am, "gretzteam" <gretzteam@n_o_s_p_a_m.yahoo.com> wrote:> >The notch approach is simplest but instead of trying it with a single > >very high "q" 2nd order filter, just cascade several lower "q" 2nd > >order filters in series. > > >IHTH, > >Clay > > Hi, > Are you saying a few even narrower notch in series with slightly different > center frequency? > > Thanks!No since you know the frequency, design each notch to be at that exact frequency. But in the filter equation you have a "q" factor that determines the "narrowness" of the filter. Instead of one very narrow filter use several not as narrow filters. And of course connect them in cascade where the output of one filter becomes the input of the next. By increasing the filter order we are increasing the transient response thus shortening the ring down time. IHTH, Clay

Reply by ●March 23, 20102010-03-23

>The Goertzel filter is just a bandpass filter that you run for a finite >amount of time. A notch filter is just your signal minus the output of >a bandpass filter. So a scheme that uses a Goertzel filter to >periodically measure amplitude and phase is _probably_ not going to work >as well as a notch filter. > >Besides, there are better methods than Goertzel filters if you happen to >be on a processor with oodles of resources compared to your problem, as >is often the case these days. > >-- >Tim Wescott >Control system and signal processing consulting >www.wescottdesign.com >Hi, Thanks for the comments on the Goertzel filter. I agree that even if I could make that to work, I don't see how it could beat a simple notch filter. I'm actually implementing this in straight hardware where power/area is a concern. I would be interested in knowing if anything could better than the Goertzel filter in this case (let's say I was trying to 'detect' this tone instead of removing it). Thanks!