# Designing appropriate filter by choosing values for $A$ and $B$

Signal Processing Asked on January 6, 2022

Let $$y[n] – ABy[n-1] +A^2y[n-2] = x[n] – Bx[n-1] +x[n-2]$$
Where $$A$$ and $$B$$ are constants. Also there are two sounds which have $$400$$ hertz noise and the sampling rate is $$8000$$ samples/sec. The task is determining $$A$$ and $$B$$ in order to eliminate the noise. I’ve written a MATLAB program which takes $$A$$ and $$B$$ as inputs and then plots the frequency response of the filter as output(using freqz command). Letting $$A = 0.9$$ and changing $$B$$ from $$1.4$$ to $$1.9$$ leads to shifting the band stop region to the left:

Since we want to remove $$400$$ hertz noise choosing $$B = 1.9$$ is good because $$0.1 times frac{8000}{2} = 400$$. The main problem is finding appropriate $$A$$. Let $$B = 1.4$$ and increase $$A$$ from $$1.1$$. Part of magnitude plot will move downward:

Conversely, if $$B = 1.9$$ increasing $$A$$ from $$0.1$$ to $$0.9$$ causes plot moves upward. If $$A = 1$$ then magnitude plot is a straight line

It seems there is some sort of usual trade-off situation here. More elimination of noise is achieved if we select larger values for $$A$$ but this causes more attenuation in other frequencies as well. Is there any mathematical solution for finding the best values for $$A$$ and $$B$$? Also how we can design better filters for removing $$400$$ hertz noise? I mean alternative solutions instead of mentioned IIR filter.

## 2 Answers

This is meant as a stepping stone up to Dan's answer.

The units for frequency at the sample level are radians per sample. You've got:

$$400 frac{cycles}{second} cdot 2 pi frac{radians}{cycle} / 8000 frac{samples}{second} = frac{pi}{10} frac{radians}{sample}$$

That is your target $$omega_t$$.

Sound is a real valued signal, so you can model it like this:

$$s[n] = A cos( omega n + phi ) = A frac{ e^{i(omega n + phi)}+e^{-i(omega n + phi)} }{2}$$

Those are your two complex tones you want to zero out. Notice the the units work out as well.

$$omega frac{radians}{sample} cdot n; samples = omega n ; radians$$

Starting with:

$$y[n] - ABy[n-1] +A^2y[n-2] = x[n] - Bx[n-1] +x[n-2]$$

Suppose that: begin{aligned} y[n] &= A_y e^{i(omega n + phi_y) } \ x[n] &= A_x e^{i(omega n + phi_x) } \ end{aligned}

It follows that: begin{aligned} y[n+d] &= A_y e^{i(omega (n + d) + phi_y) } = A_y e^{i(omega n + phi_y }e^{i(omega d) } = y[n]e^{iomega d } \ x[n+d] &= A_x e^{i(omega (n + d) + phi_x) } = A_x e^{i(omega n + phi_x }e^{i(omega d) } = x[n]e^{iomega d } \ end{aligned}

Plug those into your equation:

begin{aligned} y[n] - ABy[n-1] +A^2y[n-2] &= x[n] - Bx[n-1] +x[n-2] \ y[n] left[ 1 - AB e^{iomega } + A^2 e^{i2omega } right] &= x[n] left[ 1 - B e^{iomega} + e^{i2omega} right] \ end{aligned}

For convenience, make a substitution:

$$z = e^{iomega}$$

begin{aligned} ( 1 - AB z + A^2 z^2 ) cdot y[n] &= ( 1 - B z + z^2 ) cdot x[n] end{aligned}

Your $$z_1$$ and $$z_2$$ represent the two tones you want to zero. By putting the polynomial for $$x[n]$$ in factor form, your target values can be plugged right in.

begin{aligned} 0 = ( 1 - B z + z^2 ) = ( z - z_1 )(z - z_2 ) = z^2 - (z_1 + z_2)z + z_1 z_2 end{aligned}

begin{aligned} z_1 &= e^{iomega_t} \ z_2 &= e^{-iomega_t} end{aligned}

Observe:

$$z_1 z_2 = e^{iomega_t} e^{-iomega_t} = e^0 = 1$$

Which fits in the equation without rescaling, therefore

$$B = z_1 + z_2 = e^{iomega_t} + e^{-iomega_t} = 2 cos(omega_t)$$

Now, continue with Dan's answer.

Answered by Cedron Dawg on January 6, 2022

Bottom Line:

$$A <1$$

$$B =2cos(omega_n)$$

Where $$omega_n$$ is the normalized angular frequency of the desired notch location (in this case for the OP with a sampling rate of 8KHz and notch at 400 Hz this would be $$omega_n = 2pi400/8000 = pi/10$$), resulting in $$B approx 1.902$$ and $$A$$ is the frequency notch bandwidth parameter; the closer $$A$$ is to 1 the tighter the bandwidth of the notch.

Details:

The straight-forward approach to eliminating narrow band noise at 400 Hz would be a classic 2nd order notch filter. This is detailed at this post:

Transfer function of second order notch filter

This approach is done by simply placing a zero at the frequency of interest, and by adding a pole close to the zero, but inside the unit circle of course to be stable, we can adjust the bandwidth of the notch by the proximity of this pole to that zero, meaning $$|p|<1$$, but close to 1.

Using real coefficients, meaning complex conjugate zeros and poles as detailed in the linked post, this results in the transfer function:

$$H(z) = frac{1+a}{2}frac{z^2-2zcos(omega_n)+1}{(z^2-2azcos(omega_n)+a^2)}$$

Which as a difference equation is exactly in the form that the OP has used and therefore given this is the same filter, answers the OP's question. This is is derived from the z-transform as follows (we can ignore the gain scaling parameter $$(1+a)/2$$ which for most cases is close to 1, and express in decreasing powers of z (and assuming I didn't make simple algebra errors!):

$$frac{Y(z)}{X(z)} = frac{1-2z^{-1}cos(omega_n)+z^{-2}}{(1-2az^{-1}cos(omega_n)+a^2z^{-2})}$$

$$Y(z) (1-2az^{-1}cos(omega_n)+a^2z^{-2})= X(z)(1-2z^{-1}cos(omega_n)+z^{-2})$$

$$Y(z)- Y(z)2acos(omega_n)z^{-1}+Y(z)a^2z^{-2} = X(z)-X(z)2cos(omega_n) z^{-1} +X(z)z^{-2}$$

And then with the inverse Z transform we get the desired coefficients that the OP wanted:

$$y[n] - 2acos(omega_n)y[n-1] + a^2y[n-2] = x[n]-2cos(omega_n)x[n-1] + x[n-2]$$

With comparison to OP's expression:

$$y[n] - ABy[n-1] +A^2y[n-2] = x[n] - Bx[n-1] +x[n-2]$$

Results in the following:

$$A = a$$

$$B =2cos(omega_n)$$

Where $$omega_n$$ is the normalized angular frequency of the desired notch (for the OP's sampling rate and notch frequency this would be $$omega_n = 2pi400/8000 = pi/10$$) and $$a$$ is the notch bandwidth parameter ($$a<1$$, the closer a is to 1 the tighter the notch, refer to the linked post for complete details).

Answered by Dan Boschen on January 6, 2022

## Related Questions

### How to detect start and finish of temperature control in temperature time series

2  Asked on January 1, 2021 by regnav

### Phantom harmonics when using cosine windows why do they appear and how to avoid them?

1  Asked on December 25, 2020 by mickkk

### Sampling the Wave Equation for String Vibration

1  Asked on December 25, 2020 by leonard

### Simulate BER curves for OFDM with convolutional coding

1  Asked on December 25, 2020 by user2913869

### What is the order of the output of HoughCircles in OpenCV, when having several circles on a frame?

0  Asked on December 23, 2020 by faiza-ali

### Meaning of lines on x- and y-axis of a centered FFT-spectrum of an image

1  Asked on December 22, 2020 by doublesteakhouse

### Different type of padding in image?

1  Asked on December 22, 2020 by ritika-malik

### What papers or resources explain the conditions needed for filter stability in real-time tuning of parameters?

1  Asked on December 18, 2020 by mavavilj

### Real-time mixing of two audio clips while only modifying the data of one

1  Asked on December 13, 2020 by k-claesson

### When I double bit rate I do not see a difference in I_spectrum and Q_spectrum, but why?

1  Asked on December 11, 2020 by sawpythonnewbie

### phase response of an analog filter

1  Asked on December 10, 2020 by dcs

### how to extract a radio signal features with python?

1  Asked on December 8, 2020 by nechi

### Is there a program to extract features from an audio signal?

3  Asked on December 7, 2020 by signaler

### BER performance of fractional equalizers for colored noise

1  Asked on December 2, 2020 by san

### If you would write the frequency-response in terms of projections through inproducts. How would you do it?

1  Asked on November 30, 2020 by laurens

### Why does time-domain convolution correspond to frequency-domain multiplication? (visual)

0  Asked on November 27, 2020

### How to detect defects at a contour?

2  Asked on November 26, 2020 by superuser

### When is it possible to swap expander and compressor?

0  Asked on November 26, 2020 by m-sh-shokouhi

### Decimation FFT Result

1  Asked on November 13, 2020 by helpmebro

### Why does fine CFO cause rotation of the constellation?

1  Asked on November 7, 2020 by lewis-kelsey

### Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP