1

I have a signal that contains energy at a fundamental frequency (60 Hz) plus significant energy at harmonics (2nd, 3rd etc up to 15th). The signal is sampled by an ADC at 1920 Hz. I want to construct a digital filter that removes / reduces the harmonics but allows the fundamental and non-harmonic content to pass through. In my application it is important to minimize the overall time delay introduced by the filter as well as minimize over / undershoot on steep leading edges. Such edges occur when a relay closes while the signal is not at a zero crossing. Since the signal source is 3-phase it is not possible to close the relay at a zero crossing for all three phases. I am particularly concerned with removing the so-called triplen harmonics (3rd, 9th & 15th) and could sacrifice performance of the filter at other harmonics if necessary.

I am currently using a series of IIR notch filters, one at each harmonic frequency starting at the 3rd harmonic. I wonder if there might be more efficient / elegant solutions that I should consider. I considered a comb filter, but don't know how to make one that allows the fundamental to pass through. I also considered a simple LPF but found it difficult to create one that has good performance at the 3rd harmonic without introducing significant group delay at the fundamental. I'd like to hold the fundamental delay to 500uS or less, which is approximately 1 sample period in my case.

I am a novice on digital filter design. Perhaps others on this forum have faced similar design challenges? Any suggestions or advice is appreciated.Example signal with harmonic content

  • You're using words like "reduces", "minimizes", "fast", but not putting numbers to them. This makes it difficult to know what you really want. – TimWescott Jan 11 '22 at 18:06
  • 2
    Why not an FIR filter that's one cycle of a 60Hz sine wave? That should be bandpass around 60Hz, with nulls at every harmonic including DC. – TimWescott Jan 11 '22 at 18:07
  • So you have a signal that consists of a (weak) 60Hz, harmonics, and you want to minimize delay of detecting when this signal is switched on? It seems that you have a very specific application, may I ask how you are using this signal downstream? Perhaps the filtering operation could be replaced by something else? – Knut Inge Jan 11 '22 at 23:06
  • Thanks Tim & Knut for your replies. – Doug DeVries Jan 11 '22 at 23:46
  • Sorry about being so vague. I have not collected enough field data yet to really know what amount of filter is sufficient at at which frequencies. The application is measuring leakage current in a 3-phase GFCI device. I want to measure the fundamental and not the harmonics. Yes, the fundamental can be small relative to the triplen harmonics due to 3-phase cancellation at the fundamental and addition that occurs at the triplen harmonics. It is important that the signal be minimally delayed because I need to react quickly (e.g. within 1ms) to large amplitude (e.g. 300 mA) leakage signals. – Doug DeVries Jan 11 '22 at 23:55
  • At lower amplitudes of leakage (e.g. 30 mA), I have more time (e.g. 1 second) to react. Tim's idea of a FIR filter that forms a bandpass around 60 Hz is interesting. My concern would be how much delay such a filter would add. I probably should try it and see what happens. – Doug DeVries Jan 12 '22 at 00:00
  • Please see: https://dsp.stackexchange.com/questions/74995/filter-odd-or-even-harmonics-with-notch-or-inverse-notch-filter/74998#74998 – Dan Boschen Jan 12 '22 at 00:18
  • Thanks very much for the link Dan. The comb filter looks like a promising approach. I couldn't figure out how to avoid removing the fundamental with the comb filter before reading this. I will attempt to build & test a comb filter based on the info presented in the link and explore the tradeoffs for my specific needs. – Doug DeVries Jan 12 '22 at 15:43
  • I dont know anything about the application, but is the 60 Hz signal something that you need to know amplitude and phase of? Or only magnitude-envelope? Are the harmonics at locked relationship to the fundamental, or do they fluctuate chaotically in amplitude and phase? – Knut Inge Jan 12 '22 at 16:45
  • If the harmonics are free running, perhaps you can track them using PLLs and subtract them. If they are in a locked relationship with the fundamental, then I would think that they can contribute to your control sensing? – Knut Inge Jan 12 '22 at 16:50
  • Knut - I only need to determine the amplitude of the fundamental. The harmonics are created by equipment that is operating from the fundamental so I have to assume they are in a locked relationship. The fundamental is pretty stable in frequency in North America but can drift by a few percent - especially over short periods of time. The power company is supposed to ensure that there are exactly 5184000 cycles of the fundamental per 24 hour period but over short periods of time the fundamental can drift a little. The harmonics should stay locked to the fundamental. – Doug DeVries Jan 12 '22 at 21:09

2 Answers2

2

The following is useful in applications where we want to null out interfering tones that are within are spectrum of interest where our signal occupies, so with that we want to minimize how much spectrum we remove. In cases where we are really only interested in the signal at 60 Hz (as the OP may be) then a PLL or 2nd order resonator would be most applicable and simply done, and I have already detailed in this link.

The comb filter described in this link shows the approach to notch out the harmonics while preserving the fundamental, but has a longer delay equal to half the number of filter coefficients and much roll-off at all the frequencies in between.

An approach where you can minimize group delay and narrow the width of the notch is with a zero-stuffed 2nd order notch filter cascaded with pole-zero cancellation filter for the pass frequency of interest. This is accomplished by combining the details from both of the posts linked below.

This first post shows how to make a harmonic notch filter by simply zero stuffing the 2nd order notch filter:

how to create a harmonic mask from fundamental frequency?

Similar to a decomposition of a moving average to a cascade-integrator-comb structure, we can cascade the above structure of the interpolated notch with the inverse of the single tone notch filter that is described in this post:

Transfer function of second order notch filter

This will be a very easy solution since the OP has a sampling rate that is a multiple of the tone of interest.

The filter is created by cascading the harmonic nulling filter which is given by the following transfer function:

$$H_1(z) = K_1 \frac{1 - z^{-N}}{1-\alpha^N z^{-1}}$$

With the pole / zero canceller at the desired Harmonic which is given by the following transfer function:

$$H_2(z) = K_2 \frac{1-2\alpha \cos(2\pi/N)z^{-1}+\alpha^2}{1-2\cos(2\pi/N)z^{-1}+1}$$

Where:

$N$ is the number of total harmonics up to the sampling frequency (in the OP's case $N=32$.

$\alpha$ is a filter Q-factor with the closer $\alpha$ is to 1, the tighter the notches will be (and the greater the required total number of bits will be in the extended precision accumulators for fixed point implementations!).

$K_1$ and $K_2$ are gain normalization constants, and computed as follows:

$$K_1 = \frac{1+\alpha^N}{2}$$

$$K_2 = \frac{2+2\cos(2\pi/N)}{1+2\alpha\cos(2\pi/N)+\alpha^2}$$

Below shows the resulting filter and group delay using $\alpha=0.99$ with $N=32$. (Note that we can optionally select any particular Harmonic to pass by changing $2\pi/N$ where used in both numerator and denominator in $H_2(z)$ and $K_2$ to be $2\pi k/N$ where $k$ is the selected harmonic):

frequency response

Notice that the Group Delay is minimized at the passband of interest. (1st Harmonic).

Group Delay

Interesting side-note: A moving average filter similarly has a frequency response given by the Dirichlet Kernel (basically an aliased Sinc) which is useful when we want to pass DC but null every harmonic of a given frequency. When this same technique is used to sharpen the frequency response nulls in the moving average filter, the resulting structure is the moving average in the forward path, and a "leaky" moving average fed back and subtracted as an IIR structure. The "leaky" moving average is given by coefficients $c_n = \alpha^n$ for $n = 0,1,2 \ldots N-1$.

Dan Boschen
  • 50,942
  • 2
  • 57
  • 135
0

My apologies if this is more of a comment then an answer, given my low reputation.

As the other comments have mentioned, a sinusoidal impulse response at 60 Hz would be adequate for satisfying the removal of harmonics. If you are concerned with preserving group-delay (and thus phase-delay), consider using a zero-phase digital filter. The MATLAB documentation on the filtfilt function that has some good examples to see if it would suite your needs. Essentially, phase-delay is maintained by performing two filtering operations: one in the forward direction, and one in reverse. The filter's impulse response should be selected such that it is even with respect to the filter's center, i.e. $$h(n)=h(-n)$$ These two filtering operations will have phase delays that will cancel each other out. Keep in mind, this filter is non-causal.

Ash
  • 895
  • 2
  • 6
  • As the OT wanted minimal delay, I assume that this is a realtime control loop of sorts, not somewhere you would want to use filtfilt() – Knut Inge Jan 12 '22 at 16:47
  • Knut is correct. This is a realtime system. I though perhaps Beemsie was joking when I saw his note about filtfilt being a "non-causal" filter. I didn't know such a thing existed but apparently it does. I have enough problems introducing non-causal behavior into my systems without doing it on purpose with a non-causal filter. :-) Thanks anyway for the response though. I learned that non-causal filters are a thing! – Doug DeVries Jan 12 '22 at 21:03
  • It actually is causal in reality of course. Non-causal means you can only get the solution after the fact (post processing). For applications when you want the output resulting array to be time aligned with the input (meaning the first sample in the output is implied to be at t=0, filtfilt works well. – Dan Boschen Jan 12 '22 at 22:51