<<

AUDIO SIEVING USING SIGNAL FILTERS

A project under V.6.2 – Signals and System Engineering

Yatharth Aggarwal Sagar Mayank Chauhan Rajan

Table of Contents

Introduction ...... 2 Filters ...... 4 ...... 7 (Type 1) ...... 9 Chebyshev Filter (Type 2) ...... 11 Filter performance...... 13 Bibliography ...... 15

1 | Page

Introduction

Noise-cancellation feature in headphones measure the external ambient noise with a microphone, and generate a signal that matches the noise, but with the opposite amplitude. This “anti-noise” (filter) is added to the original music signal and effectively interfere destructively with the ambient noise. This addition of anti-noise might also depend upon certain mathematical function which is known as filtering process. The motivation for the project came from a question paper of University of Colorado of ECE department. With that lead we will: Design a bandstop filter with the following specifications: Passbands: 0 – 1400 Hz and 1,900 – 5,512.5Hz : 1,600 - 1,700Hz Tolerance in the passband: 0.5 dB Maximum gain in the stopband: 100 dB. And will implement the filter using each of the following design methods: Butterworth Chebyshev Type I Chebyshev Type II

For a noisy signal(sound file) given here [1] The software tool used here is MATLAB provided by Mathworks[2].

The purpose of this assignment is to compare the above mentioned bandstop filters with the same cut-off , transition band, and .

2 | Page

The sound file consists of a song which we need and filter out rest of the other sounds which in this is heard at maximum decibels. The following graphs are that of noisy sound signal.

Frequency

Figure I: Graph (top) is x(t) versus time and bottom graph represents the fourier transform X(f) and f ()

The x(t) graph seems to periodic at some point indicating the sound is repetitive. The second graph left part (beginning from x-axis = 6000) should not be considered as it is made just for numerical values by the software.

3 | Page

Filters

In , a filter is a device or process that removes from a signal some unwanted component or feature[3]. Filtering is a class of signal processing, which involves the designing of filters in such a manner that they either do complete or partial suppression of some aspect of the signal. Filters can be classified in several different groups, depending on what criteria are used for classification. The two major types of digital filters are finite impulse response digital filters (FIR filters) and infinite impulse response digital filters (IIR). Some basic terminology:

The frequency response can be classified into a number of different band forms describing which frequency bands the filter passes (the passband) and which it rejects (the stopband):

o Low-pass filter: low frequencies are passed, high frequencies are attenuated. o High-pass filter: high frequencies are passed, low frequencies are attenuated. o Band-pass filter: only frequencies in a frequency band are passed. o Band-stop filter: only frequencies in a frequency band are attenuated. o Notch filter: rejects just one specific frequency - an extreme band-stop filter. o Comb filter: has multiple regularly spaced narrow passbands giving the bandform the appearance of a comb. o All-pass filter: all frequencies are passed, but the phase of the output is modified.

Cut-off frequency is the frequency beyond which the filter will not pass signals. Roll-off is the rate at which attenuation increases beyond the cut-off frequency. Transition band, the (usually narrow) band of frequencies between a passband and stopband. Ripple is the variation of the filter's insertion loss in the passband. The order of a filter is the degree of the approximating polynomial and in passive filters corresponds to the number of elements required to build it. Increasing order increases roll-off and brings the filter closer to the ideal response, but also the longer the impulse response is and the longer the latency will be.

Designing filters comes with many trade-offs; among the parameters to take into account are the cut-off frequencies, transition band, ripple, processing power available, and whether linear phase is necessary. In this case the filter should allow frequencies on the range of [0, 1400] and [1900, 5,512.5] Hz with a tolerance of 0.5dB. The stopband is a region from [1600, 1700] Hz with a maximum gain of -100dB. The filters are then applied to a song with noise in the stopband region; the filtered song can then be heard. attenuation is usually expressed in terms of the logarithmic decibel scale (dB). The attenuation measured in decibels can be found using the following expression:

4 | Page

� = 20 log (�(�)) where H(f) is the of the filter. This transfer function tells how the filter behaves as it is defined as: �(�) �(�) = , �(�) where Y(f) is the output signal and X(f) is the input signal to the system in terms of their z- transforms when function is linear and discrete in time. The transfer function of all linear time-invariant filters generally share certain characteristics:

For filters which are constructed of discrete components, their transfer function must be the ratio of two polynomials in ‘f’, i.e. a rational function of ‘f’. The order of the transfer function will be the highest power of ‘f’ encountered in either the numerator or the denominator. The coefficients of the polynomials of the transfer function will be real or occur in complex conjugate pairs.

�� ∏ (1 − � � ) ( ) � � = = � ∏ (1 − �� ) �� where:

bi are the feedforward filter coefficients (non-recursive part) aj are the feedback filter coefficients (recursive part) H0 is a constant qi are the zeros of the transfer function pj are the poles of the transfer function.

5 | Page

Let us now define the three filters mathematically

The passband and stopband gains Gp, Gs and the corresponding attenuations in dB are de- fined in terms of the “ripple” parameters εp, εs as follows:

The magnitude responses of the analog Butterworth, Chebyshev, and elliptic filters are given as functions of the analog frequency Ω by:

where CN(x) is the order-N Chebyshev polynomial, that is, CN(x)= cos(N cos−1 x), and cd(x, k) denotes the Jacobian elliptic function cd with modulus k and real quarter-period K

6 | Page

Butterworth Filter

Butterworth filters[4] are designed to be maximally flat; when compared to other filters, it has a slower roll off, but no ripple near the corner frequencies. In this case the order comes out to be 18. Figure 2 displays the magnitude. Note how there is no ripple in the magnitude transition, just a smooth decay. The pole-zero diagram in Figure 3 illustrates how the Butterworth had 9 zeros on the unit circle at 1650 Hz surrounded by a semicircle of nine poles. Each zero and pole is accompanied by its complex conjugate mirrored across the real (x) axis. With a relatively low order, the Butterworth design only needs 37 (=2n+1 calculations, where n is the order of the transfer function) add/multiply operations per input sample.

Figure II: Butterworth magnitude versus frequency response

7 | Page

Figure III: Butterworth pole-zero plot

Figure IV: Butterworth impulse response with 100 data points

8 | Page

Chebyshev Filter (Type 1)

Chebyshev filters[5] are based on a concept called Chebyshev polynomials; put simply, these coefficients describe polynomials that are bounded to a one by one box centered at the origin and diverge elsewhere. Though these filters have a steeper roll off than Butterworth, they have ripple in the passband. The ripple is difficult to see in Figure 5, the magnitude as phase plot Note the difference between Figure 5 and Figure 2, the magnitude responses of the Chebyshev Type I and Butterworth filters, respectively. Though Chebyshev filters have a faster roll off, the rate of attenuation change seems similar here. The pole-zero diagram, Figure 6, is different than that of the Butterworth, but has the same idea: surround n zeros locally with n poles. The impulse response is shown in Figure 7 and is fairly similar in shape to the Butterworth. 25 add/multiply operations are required as order here goes 12.

Figure V: Magnitude of Chebyshev- 1 response (Notice ripples near the passband segment)

9 | Page

Figure VI: Chebyshev Type 1 pole-zero plot

Figure VII: Chebyshev Type 1 impulse response with 100 sample points

10 | Page

Chebyshev Filter (Type 2)

The Chebyshev Type II filter[5] is very similar to the Type I. However, instead of ripple in the passband, it occurs in the stopband. Figure 8, the magnitude, shows how the Type II filter rolls off smoothly (with no ripple), then ripples between 1600 and 1700 Hz before smoothly returning to the passband. The pole-zero diagram in Figure 9 more closely resembles the Butterworth; the zeros are not in one location, but the poles surround the zeros in a semi- circle fashion. The impulse response in Figure 10 takes a similar form to the previous two filters with different coefficient magnitudes. The order of this filter is the same as Chebyshev Type I, 12, and therefore requires 25 add/multiply operations.

Figure VIII: Magnitude response of Chebyshev filter (notice the ripples in stop band)

11 | Page

Figure IX: Chebyshev 2 plot for pole-zero

Figure X: Chebyshev 2 impulse response for 100 data points

12 | Page

Filter performance

Filter Order Quality Butterworth 18 Sound quality ok, slight in background Chebyshev Type I 12 Better than Butterworth, no background ringing Chebyshev Type II 12 Similar to Butterworth with background ringing

The below given plots show the response from three given filter, through which the signal is made to pass. Although output data value v/s time are similar in all three cases, but there is a change in FFT v/s frequency plot. As plot between 1500 Hz – 1800 Hz show some values in case of Chebyshev – 2 filter.

Frequency

Figure XI: Butterworth output signal

13 | Page

Frequency

Figure XII: Output for Chebyshev Type 1 filter

Frequency

Figure XIII: Output for Chebyshev Type 2 filter

14 | Page

Bibliography

[1] “index.” [Online]. Available: http://ecee.colorado.edu/~fmeyer/class/ecen4632/. [2] “MATLAB and Simulink for Technical Computing - MathWorks India.” [Online]. Available: http://in.mathworks.com/index.html?s_tid=gn_loc_drop. [3] “Filter (signal processing),” Wikipedia, the free encyclopedia. 08-Oct-2015. [4] I. W. Selesnick and C. S. Burrus, “Generalized digital Butterworth ,” IEEE Trans. Signal Process., vol. 46, no. 6, pp. 1688–1694, Jun. 1998. [5] J. D. Rhodes and S. A. Alseyab, “The generalized chebyshev low-pass ,” Int. J. Circuit Theory Appl., vol. 8, no. 2, pp. 113–125, Apr. 1980.

15 | Page

Appendix for ‘Audio Sieving using Signal Filters’ ​

Note: Setup, must be run before all else. It need only be run once per session. after that run any type function (like butter_function.m or chebyshev1_func.m or chebyshev2_func.m ), that filter you want to do. The filter should allow frequencies on the range of [0, 1400] and [1900, 5,512.5] Hz with a tolerance of 0.5dB. The stopband is a region from [1600, 1700] Hz with a maximum gain of -100dB. The noise signal is sound file named as noisy.wav is of duration 0.39 sec. ​ ​ ​ Now we have: ● nyquist frequency ● Passband ranges ● Stopband ranges ● Ripples in passband ● Ripples in stopband ● ● Magnitudes (stopband)

Now it’s time to plot and sing the noise free song of the filter Butterworth or Chebyshev1 or Chebyshev2 and to so, run the plot_output_func.m

Setup(setup.m) nyq = 11025 / 2; Wp = [1400 1900] / nyq; Ws = [1600 1700] / nyq; Rp = .5; Rs = 100; [noise, Fs] = audioread('noisy.wav'); sound(noise,Fs) n=length(noise)-1; f=0:Fs/n:Fs; wavefft=abs(fft(noise)); plot(f,wavefft);

Butterworth Filter (butter_func.m) type = 'Butterworth'; [n, Wn] = buttord(Wp, Ws, Rp, Rs); disp([type ' order: ' num2str(2*n)]); [z,p,k] = butter(n,Wn,'stop'); [sos,g] = zp2sos(z,p,k); Hd = dfilt.df2tsos(sos,g);

Chebyshev Type I Filter(chebyshev1_func.m) type = 'Chebyshev Type I'; [n, Wn] = cheb1ord(Wp, Ws, Rp, Rs); disp([type ' order: ' num2str(2*n)]); [z,p,k] = cheby1(n,Rp,Wn, 'stop'); [sos,g] = zp2sos(z,p,k); Hd = dfilt.df2tsos(sos,g);

Chebyshev Type II Filter(chebyshev2_func.m)

type = 'Chebyshev Type II'; [n, Wn] = cheb2ord(Wp, Ws, Rp, Rs); disp([type ' order: ' num2str(2*n)]); [z, p, k] = cheby2(n,Rs,Wn, 'stop'); [sos,g] = zp2sos(z,p,k); Hd = dfilt.df2tsos(sos,g);

Plotting of Filter and Output(plot_and_output.m)

xtick = (cumsum(ones(1,51)) - 1) * 100 * 2 / 11025; h = fvtool(Hd); set(gca, 'Fontsize', 14); set(gca, 'XTick', xtick); set(gca, 'XTickLabel', num2str(xtick' * 11025 / 2)); xlabel('Frequency (Hz)', 'FontSize', 14); title(' Magnitude Response'); xlim([.2431 .3556]); ylim([-110 10]); zplane(Hd); set(gca, 'FontSize', 14); title([type ' Pole-Zero Plot'], 'FontSize', 16); set(get(gca, 'XLabel'), 'FontSize', 14); set(get(gca, 'YLabel'), 'FontSize', 14); figure; hold on; set(gca, 'FontSize', 14); title([type ' Impulse Response (size 100)'], 'FontSize', 16); xlabel('n', 'FontSize', 14); ylabel('h[n]', 'FontSize', 14); y = filter(Hd,[1 zeros(1,99)]); stem(1:100, y); output = filter(Hd, noise); output = output / max(output); sound(output, Fs);