$25
Lab 3: Continuous-Time Filter Design and Analysis Files necessary to compute this assignment: clean.wav, noisy.wav Equipment necessary to compute this assignment: A filter board that can be checked-out from the stockroom (do not check out until you need it), resistors (1: 29 kΩ, 6: 16 kΩ, 1: 68 kΩ, 1: 24 kΩ, and any others needed for your final design), and capacitors (1: 0.001 µF, 2: 0.01 µF, and any others needed for your final design). Introduction Many traditional analog circuits are designed through the principles of Fourier analysis. Common types of analog circuits are lowpass filters, highpass filters, bandpass filters, bandstop filters, and allpass filters. Lowpass filters remove high frequency content from a signal. Highpass filters remove low frequency content from a signal. Bandpass filters retain small sections (bandwidths) of frequencies and remove all other frequency content. Bandstop filters remove small sections (bandwidths) of frequencies and retain all other frequency content. Allpass filters distort signals while not affecting the magnitude response of the signal. In this lab, we will focus on developing lowpass analog filters. These filters are frequently used in systems to remove high frequency noise and aliasing effects. Specifically, we will design and build a lowpass filter with operational amplifiers (op-amps). We will use this lowpass filter to remove noise from a music signal. This lab assignment has three learning objectives: 1. To analyze a complex op-amp filter design using continuous-time Fourier analysis 2. To design a op-amp filter for a specific noise removal application 3. To experimentally build that design with op-amps and test its effectiveness Your experiment will be divided into three parts. In your lab report, you should address each part in separate subsections. See the lab report guidelines on the class website for more information. Deliverables This lab assignment has three deliverables: 1. One (1) lab report (see the “Lab Report Guidelines” on how to write it) 2. One (1) name processed.wav file with your digitally filtered version of name processed.wav 3. One (1) demonstration of you analog filter system to your lab instructor Please submit a hard copy of the paper deliverables and e-mail the electronic deliverables to your lab instructor before your assigned lab session between Nov. 18th – Nov. 24th. 1 Part 1: Analyzing a high-order filter system In this part of the lab, we will analyze filter system with operational amplifiers (op-amps) and continuous-time Fourier analysis. First, we will analyze a bi-quad filter systems, which is based on an collection of inverting op-amp systems. We will then analyze a first-order noninverting low-pass filter system. Finally, we will combine one first order noninverting low-pass filter system with two bi-quad filter systems. This is the system that will experimental with in the rest of the lab. In this part lab, you will use MATLAB to analyze the low-pass filter system and bi-quad filter systems. In the next section, we will experimental validate your analysis. Analyzing inverting op-amp systems: The inverting op-amp system: − + Z2(ω) x(t) y(t) Z1(ω) x(t) − Z1(ω) Z2(ω) y(t) Figure 1: An inverting op-amp circuit (left) and it block diagram representation (right) The op-amp realization as shown in Figure 1 is of an inverting amplifier. The transfer function of the inverting amplifier is defined by H(ω) = Y (ω) X(ω) = − Z1(ω) Z2(ω) . If you are familiar with impedances in terms of s, i.e. Z1(s) and Z2(s), assume s = jω. On the left side of Figure 1, we see the circuit diagram for the inverting amplifier. On the right side of Figure 1, we see the equivalent block diagram system representation of the operational amplifier system. We will use these block diagrams to simplify our filter representations when build a bi-quad filter from inverting amplifier circuits. In the following sections, we will analyze specific realizations of the inverting amplifier. These realizations will gradually lead to building a bi-quad filter system. Analyzing analog filters in MATLAB: Throughout this lab, we will be analyzing analog filters. We will want to plot their transfer function magnitude and phase characteristics. We will do this using the MATLAB function freqs(num, den). When given no output, freqs plots the magnitude and phase of the transfer function is with numerator num(1)sN+num(2)sN−1+···+num(N-1)s+num(N) and denominator den(1)sM + den(2)sM−1 +···+ den(M-1)s + den(M), where N = length(num) and M = length(den) and s = jω. 2 A classic inverting op-amp system: − + R2x (t) y(t) R1 x(t) − R1 R2 y(t) Figure 2: An classic inverting op-amp circuit (left) and it block diagram representation (right) For the inverting op-amp system in Figure 1, when Z1(ω) is a resistor R1 and Z2(ω) is a resistor R2, we have an inverter. This is shown in Figure 2. In the frequency domain, the transfer function for this system can be expressed as H(ω) = Y (ω) X(ω) = −R1 R2 . MATLAB Exercise: Let R1 = 16 kΩ and R2 = 16 kΩ. Use the MATLAB function freqs (with no outputs and s = jω) to analyze this circuit and its transfer function H(ω). An integrator system: − + R4x (t) y(t) C3 x(t) − 1 jωR4C3 y(t) Figure 3: An integrator op-amp circuit (left) and it block diagram representation (right) In Figure 1, when Z1(ω) and Z2(ω) represents a resistor and capacitor, respectively, we generate an inverting integrator. This is shown in Figure 3. We call this system an inverting integrator because the input-output relationship for the system (assuming x(0) = 0) is y(t) = − 1 R4C3Zt1 0 x(τ)dτ . The time-domain impulse response h(t) and the frequency-domain transfer function H(ω) of the integrator system is given by h(t) = − 1 R4C3 u(t) , H(ω) = Y (ω) X(ω) = − 1 jωC3 R4 = −1 jωR4C3 MATLAB Exercise: Let C3 = 0.01 µF and R4 = 16 kΩ. Use the MATLAB function freqs (with no outputs and s = jω) to analyze this circuit and its transfer function H(ω). 3 An integrator system with decay: − + R8x (t) y(t) R7 C7 x(t) −R7 R8(1 + jωR7C7) y(t) Figure 4: An integrator with decay op-amp circuit (left) and it block diagram representation (right) In Figure 1, when Z1(ω) and Z2(ω) represents a resistor and a parallel resistor-capacitor, respectively, we generate an inverting integrator with decay. When integrating, this system adds recent values with greater weight than older values. The time-domain impulse response h(t) and the frequency-domain transfer function H(ω) of the integrator with decay system is given by h(t) = − 1 R8C7 e−1/(R7C7)u(t) , H(ω) = Y (ω) X(ω) = −R7 R8(1 + jωR7C7) . MATLAB Exercise: Let R7 = 68 kΩ, C7 = 0.01 µF, and R8 = 1 kΩ. Use the MATLAB function freqs (with no outputs and s = jω) to analyze this circuit and plot its transfer function H(ω). A summation system: − + Z3(ω) x2(t) Z2(ω) x1(t) y(t) Z1(ω) x1(t) Z−1 2 (ω) P −Z1(ω) y(t) Z−1 3 (ω) x2(t) Figure 5: An summation op-amp circuit (left) and it block diagram representation (right) In Figure 1, when a new input is added with input impedance Z3(ω), we generate summation system. This is shown in Figure 5. A summation system allows us to add multiple inputs together. The frequency-domain transfer function H(ω) of the summation system is given by Y (ω) = −Z1(ω)?X1(ω) Z2(ω) + X2(ω) Z3(ω)? . 4 Combining systems: In this previous subsections, we analyzed fundamental inverting amplifier circuits. Now we will demonstrate how to combine these circuits together through system analysis and the properties of the Fourier trasnform. A cascaded system: x(t) H1(ω) H2(ω) y(t) Figure 6: A cascade system. Figure 6 shows a cascaded system where the output of one system become the input of the next. In Part 1 of the course, we learned that the time-domain impulse response of the overall system is given by the convolution of the two impulse responses. The frequency-domain transfer function of the overall circuit is given by the convolution property of the Fourier transform h(t) = h1(t)∗h2(t) F ←→ H(ω) = H1(ω)H2(ω) . This implies that if we can easily combine our systems to build better filters by feeding the output of one filter into the input of the next. A feedback system: x(t) P H1(ω) H2(ω) y(t) Figure 7: A feedback system. Figure 7 shows a feedback system where the output overall system is manipulated and then added back to the input. In a feedback system, the system H1(ω) is often known as the “plant” or “process” that modifies a signal over time. The system H2(ω) is often known as the “controller” that steers your output y(t) to a particular value. The frequency-domain transfer function for a feedback system is defined by H(ω) = Y (ω) X(ω) = X(ω)H1(ω) + Y (ω)H1(ω)H2(ω) X(ω) H(ω) = H1(ω) + H(ω)H1(ω)H2(ω) H(ω)(1−H1(ω)H2(ω)) = H1(ω) H(ω) = H1(ω) 1−H1(ω)H2(ω) This shows that we can use the Fourier transform to analyze a rather complex process, such as a feedback. 5 A bi-quad filter system: − + R8x (t) R7 C7 − + R4 y(t) C3 − + R2 R9 R1 x(t) H1(ω) P H2(ω) H3(ω) H4(ω)H 5(ω) y(t) Figure 8: An bi-quad op-amp circuit (top) and it block diagram representation (bottom) Figure 8 shows a bi-quad filter. The top part of Figure 8 shows the circuit representation and the bottom part of Figure 8 shows the equivalent block diagram which corresponds to each of the circuits and properties discuss in the previous subsections. Use everything we previously learned about to derive the transfer function of this system. You will find that the transfer function for the bi-quad circuit is defined as H(ω) = (R2R9R7/R8) R7R1 + R2R9(1 + jωR7C7)R4C3jω Furthermore, this can be simplified into the form H(ω) = Kω2 c −ω2 + jBωcω + Aω2 c where K = (R9/R8), ω2 c = 1/(R4R9C3C7), Bωc = 1/(R7C7), and A = R1/R2. MATLAB Exercise: Let R1 = 16 kΩ, R2 = 16 kΩ, C3 = 0.01 µF, R4 = 16 kΩ, R7 = 68 kΩ, C7 = 0.01 µF, R8 = 1 kΩ, R9 = 1 kΩ. Use the MATLAB function freqs (with no outputs and s = jω) to analyze this circuit and plot its transfer function H(ω). Repeat this analysis for R1 = 16 kΩ, R2 = 16 kΩ, C3 = 0.01 µF, R4 = 16 kΩ, R7 = 24 kΩ, C7 = 0.01 µF, R8 = 1 kΩ, R9 = 1 kΩ. What changed? 6 A first-order noninverting low-pass filter: − + R1x (t) y(t) R2 R3 C1 Figure 9: A first-order low-pass filter circuit (left) and it block diagram representation (right) Figure 9 shows a first-order noninverting low-pass filter made with op-amps (note: the bi-quad filter system is a second-order filter). In our experimental setup, we use this system and two bi-quad filters. The frequency-domain transfer function for the first-order noninverting low-pass filter is H(ω) = 1 + (R3/R2) 1 + jωR1C1 MATLAB Exercise: Let R1 = 29 kΩ, R2 = 1 kΩ, R3 = 1 kΩ, and C1 = 0.001 µF. Use the MATLAB function freqs (with no outputs and s = jω) to analyze this circuit and its transfer function H(ω). Our experimental setup (putting everything together): x(t) First-order low-pass filter Bi-quad filter # 1 Bi-quad filter # 2 y(t) Figure 10: A block diagram of our complete filter system. Figure 10 illustrates the system we will be designing and testing throughout the rest of this lab. It consists of a first-order low-pass filter in series with two bi-quad filters. When cascaded together, we build a 5th-order filter (one 1st-order filter and two 2nd-order filters). Use the properties you previously learned in this lab to derive the transfer function for the entire filter system in Figure 10. You may want to use the function tf in MATLAB to help you. MATLAB Exercise: • For the first-order non-inverting low-pass filter, let R1 = 29 kΩ, R2 = 1 kΩ, R3 = 1 kΩ, and C1 = 0.001 µF. • For the first bi-quad filter, let R1 = 16 kΩ, R2 = 16 kΩ, C3 = 0.01 µF, R4 = 16 kΩ, R7 = 68 kΩ, C7 = 0.01 µF, R8 = 1 kΩ, R9 = 1 kΩ. • For the second bi-quad filter, let R1 = 16 kΩ, R2 = 16 kΩ, C3 = 0.01 µF, R4 = 16 kΩ, R7 = 24 kΩ, C7 = 0.01 µF, R8 = 1 kΩ, R9 = 1 kΩ. Use the MATLAB function freqs (with no outputs and s = jω) to analyze this complete system and plot its transfer function H(ω). 7 Include in Lab Report “Experimental Design” Section: Include: A block diagram of your bi-quad filter similar to bottom plot of Figure 8, but with the transfer functions H1(ω), H2(ω), H3(ω), H4(ω), and H5(ω) identified (in terms of resistances, i.e., R1, R2, etc., and capacitances, i.e., C3,C7). Include: A block diagram of the of the entire filter system, similar to Figure 10. Include in Lab Report “Analytical Methods” Section: Include: Your derivation of the bi-quad filter (using the other transfer functions and properties discussed in this lab). Include in Lab Report “Results and Discussion” Section: Include: Your MATLAB plots of the each bi-quad circuit’s transfer function. Include: Your MATLAB plot of the first-order non-inverting low-pass filter circuit’s transfer function. Include: Your MATLAB plot of the entire system’s transfer function Answer: With the given configuration, would you consider each of the stages (and the system as a whole) low pass filters? 8 Part 2: Validate your analysis Check out a customized filter board from the stockroom. The diagrams in Figure 11 and Figure 12 illustrate the circuit board that we will use. Note that some of the boards differ slightly from the diagram. To power the board, attach a +15 V line to the red input, attach a -15 V line to the blue input, and attach the ground to the green input. Before inputting a signal the board, verify your setup with your lab instructor. R1 C1 R1 R2 C3R4R7 R1 R2 C3R4R7 Figure 11: Block diagram of the circuit board. Figure 12: Block diagram of the circuit board. Our goal is to verify our analyses from part one. Collect the necessary resistors and capacitors specified at the end of Part I to build the system. Note that several capacitors and resistors are already on the board. Specifically, R2 and R3 for the first-order noninverting low-pass filter are already on the board. Also, C7 R8, and R9 for each of the bi-quad filters are already on the board. Place the remaining resistors and capacitors into the appropriate locations. Using the equipment available to you, measure the magnitude response of each block (the firstorder low-pass filter and each of the bi-quad filters). Measure the frequency responses by inputting sinusoids at different frequencies and measuring the amplitude of the response. Estimate the phase response by estimating the time lag between the input and output signals and converting the lag to radians. First measure the response for each stage separately and then measure the response for the entire system. 9 Plot the frequency response on log-log graphes for magnitude and phase similar to that generated by the freqs MATLAB function. You must have at least 20 measurements from 100 Hz to 20 kHz. Choose your frequencies so that they are uniformly (at least approximately) distributed on the log-log graph. Compare your measurements with the MATLAB plots results from Part I. Include in Lab Report “Results and Discussion” Section: Include: Your frequency response plots of the each bi-quad circuit’s transfer function. Include: Your frequency response plots of the first-order non-inverting low-pass filter circuit’s transfer function/ Include: Your frequency response plots of the entire system’s transfer function. Answer: Does your analysis from Part I match your experimental results? If not, why? Answer: Do these results illustrate a low pass filter? Is it a “good” low pass filter? What makes a filter “good?” 10 Part 3: Designing and implementing an analog filter Analyze the music: In this part of the lab, we will combined everything we previously learned to design our own analog filter and implement it with our filter board. Two pieces of music should be included with the lab. One file (clean.wav) is a clean segment of Christopher Tin’s “Baba Yetu.” The other file (noisy.wav) was obtained by adding noise to the clean signal. These digital signals are sampled at fs = 44100 samples/s. Our goal is to design an analog filter that will remove the noisy components from (noisy.wav). We will use clean.wav to determine the low frequency range containing all the significant the components for the clean signal. Note that, in practice, we usually do not have the clean signal. In this case, however, the clean signal will help to design the best possible filter. Load clean.wav using the functions you learned in Lab 2. Estimate the frequency components of the clean signal with the power spectrum estimation function pwelch(x,hann(1024),512,2048,fs) with the parameters given above. This is similar to the fanalysis function used in Lab 2, but slightly more sophisticated. We will not get into the details in course (if you want to learn more, look up “Welch’s method”). From the resulting plot generated by pwelch, identify a continuous range of frequencies for which the signal spectrum is within 20 dB of the frequency component with the maximum strength. This represents the dominate frequencies in the music. Design the analog filter: Using MATLAB and the freqs function, choose component values to design a filter (based on the 3-stage filter system we are using experimentally) that retains frequency components within the range of the music (determined in the previous subsection) and removes frequency components outside the range of the music. Try to make the best filter possible. Load noisy.wav using the functions you learned in Lab 2. To test your filter, run [numd,dend] = bilinear(num,den,fs); % Convert analog filter to discrete filter x_filtered = filter(numd,dend, x_noisy); % Implement discrete filter The first function approximates our analog filter as a discrete filter (we cannot perfectly implement an analog filter in a computer). The second function performs the filtering. The variables num and den are the same as used for freqs. Use this code to test your custom filter on the noisy data in noisy.wav. You should be able to remove most of the noise and retain only the singing without distortion. Save a new wave file called name processed.wav with you filtered result. Implement the analog filter: Identify and retrieve the resistors and capacitors needed to implement the filter you designed with the filter board. Build your design. After Fall break, the lab instructors will have a portable music player with which you can test your filter. Listen to the noisy audio and the processed audio (processed with your filter) and verify if the noise levels are smaller for the processed signal than the original noisy signal. You should also listen for any change in the quality of the music itself because of the filtering (i.e. distortion). Remember that low-strength components in the audio signal will be removed by your filter. If necessary, make adjustments to the filter design and repeat the testing process. 11 Include in Lab Report “Results and Discussion” Section: Include: The power spectrum estimation plot from pwelch. Include: The frequency range containing the dominant frequency components in the clean music. Include: All the resistor and capacitor component values in your final filter design. Include: A MATLAB plot of the frequency response (from freqs) for your designed filter. Answer: Does your final filter introduce any distortions into the signal? Why or why not? Answer: Does your final experimental system sound like your final digital system? Explain. Submit: The .wav file name processed.wav, which contains your digitally filtered version of “Baba Yetu.” Demonstrate: When your filter design is finalized, present the final result to your lab instructor who will grade it on filtering quality.