LAB 7 F. A. Q.
LAB 7 F. A. Q.
0. Some of these questions don’t seem to make sense with respect to this semester’s lab.
ANSWER: Correct. The FAQs are based on the labs from Fall-99. Refer to that lab description when certain section numbers are cited.
3.1(a) Cascading Two Systems
1. When I plot the magnitude of Filter #1, shouldn’t there be 10 points of zero magnitude?
ANSWER: Not necessarily. Filter #1 is not a 10-point averager because all of its coefficients are NOT equal. Therefore, as a z-transform, its H(z) does not have all zeros on the unit circle. In fact, none are on the unit circle. There is a MATLAB function called zplane that will plot the zeros. (or zzplane() in the DSP First toolbox). Bottom line: not all 10-point FIR filters are 10-point averagers.
2. I understand how to get the coefficients, but could someone tell me how to go about getting the signal for the first filter; if I plan on using the conv2() or firfilt() function, how do I determine the signal to pass in for w[n]?
ANSWER: w[n] is the impulse response of the first filter, because you want to generate the overall impulse response of the cascade.
3.1(b) Cascading Two Systems
1. To get the frequency response of the overall system, do you convolve the filter coefficients and then run freekz on them, or can you just take the two frequency responses and multiply them?
ANSWER: For the lab report, multiply the H(w)’s, BUT, to see what’s going on, do it both ways. Is the result the same? This is a very important issue!
3.1(c) Cascading Two Systems
1. We found the overall frequency response for the cascade system in part (b). The two frequency responses of the two filters were multiplied to get the overall frequency response. In part (c), should we elaborate on how the two frequency responses were combined even though this is obvious from part (b), or do we explain something else here?
ANSWER: Part (c) is just there to make sure that you explain what was going on in part (b). Strictly speaking, part (b) is “just plot it.” Part (c) involves an explanation: you should be able to say how the frequency responses in part (a) were combined to get the frequency response in part (b). How are the phases combined? How are the magnitudes combined ?
3.3(d) Nulling Filters for Rejection
1. For clarification: part (d) asks for a mathematical formula that applies to the signal for n greater than 5; are they simply asking for the frequency response of the cascaded system to include magnitude, phase, and frequency?
ANSWER: Not the frequency response, which is a function of “omega-hat.” You should be able to get a formula for the SIGNAL y[n]. It is a function of “n.” The frequency response H(w) will make it easy to determine that formula for y[n]. Think about what the system "nulling filter" does to the input signal.
2. How are we supposed to show that the frequency and phase that we find mathematically are the same as the graph? The graph has the time index defined as (n). Also, the phase I calculated is positive. This appears to make y[n] have a positive delay…non-causal?
ANSWER: Remember the first week of the course; you took a plot of a sinusoid and found the magnitude and phase from the plot. Same thing here, BUT it’s harder because you have a discrete-time sinusoid. Still, you should be able to measure the period and the location of a positive peak from which you can calculate phase. Phase can be changed by adding/subtracting 2*pi. (Maybe this is the problem.) Use the peak that is delayed to get
3. When I filter the sum of sinusoids using the bandpass filter or the nulling filter, the magnitude of the remaining component does not stay the same. Am I doing something wrong? My plots of the frequency response do have a gain of 1 for .25*pi.
ANSWER: It should obey the gain of the frequency response, so if you have H(w) = 1, you should get the same size. There are two possible “gotchas”:
- You have to ignore the first L-1 points because they are the “start-up” of the FIR filter ( a.k.a. the “transient” ).
- A discrete-time signal with a non-zero phase might not have a sample at the peak of the cosine, so the signal amplitude could seem low. You would have to imagine a continuous envelope in order to measure the true gain.
4. I expected my bandpass to have a gain of exactly 1 (at desired frequency). But when I use the zoom, I see that it actually has a gain of 1.05. This means that when I filter out my 0.25pi frequency component with a magnitude of 5, the resulting magnitude is actually 5.25. Not a big change, but a noticeable one. Is this a problem?
ANSWER: This would be a 3rd "gotcha." The filter is not yet scaled so that its maximum gain is equal to one. In the next lab, we’ll worry about this scaling. So, the most important thing is that the other two sinusoids get reduced by 1/10 or more.
5. We are asked to manually calculate the mathematical formula for the output. When I plug in 0.1*pi and 0.4*pi in the overall frequency response of the system, I do not get zero, but something very small, close to zero. Shouldn’t these frequency components be nulled?
ANSWER: Yes it should be EXACTLY zero, because you have designed it to be zero by using the nulling filter formula. I assume you are evaluating the overall frequency response. Remember that it should be the product of two frequency responses – one for each nulling filter. Maybe that can serve as a cross check. Also, you can use MATLAB to do the evaluation because freqz() can evaluate H(w) at specific frequencies.
6. How do you find the phase and period of a discrete time signal? Should Ts be the number of indexes between the peaks, and can the phase be calculated from measuring the discrete index shift?
ANSWER: YES. If the period is an integer number, then it is relatively easy. Also you need the “index shift” to be an integer to measure it quickly. If it is not an integer, then estimate the location between integers (works for low frequency cosines). Alternative: If the period is not an integer, then you can use a method that is developed in Problem 4.41 on the DSP-First CD. This method uses 3 successive data points to find A, phi and omega-hat.
3.4 (a) Simple Bandpass Filter Design
1. How do you go about measuring the gain of the filter; is it simply measuring the magnitude of the frequency response? Do we compare the graphs to see which one has the highest peak, and is that the gain? It appears that all of them go to one.
ANSWER: Yes, the magnitude is usually called the “gain” or “attenuation”. Gain implies that it is bigger than one, attenuation implies less than one, but the terms are used interchangeably. In part (a) you just measure the value of H(w) at 3 places. You should verify that your filter has a larger gain at the frequency located in the passband. At the other 2 frequencies, the gain should be less. If all of them are “going to one” then something is buggy. The passband is centered around the highest peak. In part (c) you will compare frequency responses.
2. Should we measure the gain directly from the magnitude on the graph, or is there another way?
ANSWER: Two ways: use the plot to find the magnitude by zooming (probably an estimate), or have MATLAB give you the numerical values at the frequencies of interest (direct calculation with freekz or freqz(). See help freqz.
3. I understand how to create the impulse response for the bandpass filter. I do not understand how to “measure the gain” at the specified values of omega–hat, nor do I understand what that means. Also, how would I graph the frequency response of this filter?
ANSWER: To find the gain use freekz or freqz or extend the gain from the plot of H(w). Follow the example at the beginning of the lab forplotting H(w). Remember how h[n] is related to the filter coefficients for an FIR filter.
Measuring the gain means finding values of the frequency response.
4. I don’t understand the question.
ANSWER: “Measure the gain” means evaluate H(w) at the 3 frequencies. So, you should use freqz to make a plot of the frequency response vs. omega-hat. You have h[n], so follow the example in Section 1.1 on using freqz. You can also use freqz() or freekz to evaluate at specific frequencies.
5. I plotted the function for this portion of the lab, and I used the round function on the omega hat vector to find the indices for 0.25pi, 0.1pi, 0.4pi. I can never get a value for 0.4pi. I increased the number of points between -pi and pi to 1000 and am still having same problem. Is there a way I can get find( ) to give a close enough value?
ANSWER: There are two possibilities:
1. If you want something close, use abs(omega-0.4*pi) and find the minimum. I assume you are using the find() function.
2. You can get freqz() to evaluate a specific frequency. Just use the frequency as a vector for the third input.
6. Are we supposed to use the equation h[n] = 2/L cos(w*n) to make the plot? If so, when I replace ‘w’ with 0.25*pi, it gives me the peak at 0.8 rather than at 0.25 which is what would be expected.
ANSWER: h[n] is the TIME domain. You need to generate the FREQUENCY response, H(w), and plot it.
7. I have made a vector of filter coefficients using the formula given (h[n]=2/Lcos(wn)), then I used freqz to get the frequency response, and plotted it using the abs function as instructed in the beginning of the lab. For some reason, I am NOT getting a peak at 0.25pi, I am getting it at ZERO. Also, when I try to find the values for the gain at the specified frequencies using freqz, I get the error "using lcm, input arguments must contain positive integers."
ANSWER: This sounds correct, but you should be using w_c for w in the formula for h[n] (w_c is a constant). And, w_c should be the desired center frequency. Are you calling freqz() with 3 arguments? The lcm() error check comes from the 3rd argument being a scalar. Make the 2nd argument equal to one. The 3rd argument should be the frequency grid:
ww = -pi: pi/100 : pi;
HH = freqz( bb, 1, ww )
or something like that. The 3rd argument should be a vector.
8. How do I find the frequency response for a specific value? If the third argument has to be a vector, how do you input for a specific value of omega? I tried putting in a single value into a vector, is that correct?
ANSWER: Put in at least two. If you want to evaluate at w = 0.2*pi, then make ww = [0, 0.25*pi]; You’ll get two output values. Ignore the first one. freqz() has a bug that interprets a third argument as a length rather than a frequency when the 3rd argument is a scalar. Make the 3rd argument be a vector with at least 2 elements.
9. I have no idea where to get started. Do I get a separate h[n] for each frequency (0.25*pi, 0.1*pi, 0.4*pi), or just one h[n] using 0.25*pi? I know I should put them into freekz(), but what do I use as ww? Do we use -pi:pi/100:pi as in the example in 1.1, or the three frequencies at the end of the problem?
ANSWER: ww = -pi:pi/100:pi when you are making a grid for the plot. ww = small vector when you want numbers. Only one filter is designed, so there is one h[n].
10. When I am attempting to find the gain at the specified frequencies, 0.25pi works fine, but when I use the following code for 0.1pi and 0.4pi, I get a empty set, and the same thing occurs for 0.4pi. Any ideas?
find(ww == 0.1*pi)
ans = 
ANSWER: What is probably happening is that the equality test (ww==0.1*pi) doesn’t find any points that EXACTLY equal 0.1*pi. This will depend on the step size and endpoints you used when you created ww. Remember that ww is not really continuous although we pretend it is. Instead, look for a point that is close to 0.1*pi with the code:
find( abs(ww-0.1*pi) < TOL )
where TOL is some small number. Making TOL equal to half the step size should probably work (why?). This issue about the equality test is common to all numerical analysis, whether you use Matlab, C++, java, or any other computer language!
3.4 (b) Simple Bandpass Filter Design
1. When I did this, I did not notice a change in the width of the passband, but I did notice a change in the height of the passband. Is this wrong?
ANSWER: The bandwidth has to change. Review the notes and examples. The peak height changes, but not very much.
1. I was just wondering how we are supposed to find the width of the bandpass filter? The lab states “typically, the passband width is defined as the length of the frequency region where |H(w)| is greater than 0.707.” What does this mean?
ANSWER: Make a plot. It will have a peak like the L-point averager. The peak value should be near 1. On either side of the peak find where the magnitude value is 0.707. Look at Fig 6.9 in the book. The peak is at w=0. The magnitude is equal to 0.707 at frequencies that are approximately w=+0.25 and w = -0.25 radians. So the bandwidth in that case is 0.5 radians (approximately).
2. When I try to find the values of the frequency response for 0.1pi and 0.4pi, I get zero. This is wrong because in part (c) they want us to reduce the components at those frequencies by a factor of 10. Also, when I try to double the filter length, the plot doesn’t change.
ANSWER: You might get zero, because the frequency response of the BFP has zeros. They might land at 0.1pi and 0.4pi, but it would be luck. Are you changing both L and also regenerating the impulse response vector? h[n] has to be twice as long.
3. Is there an obvious reason why my magnitude graph has a peak at both positive and negative 0.25*pi? I was under the impression that there should be a peak at positive 0.25*pi.
ANSWER: SYMMETRY. When the filter coefficients are real, the H(w) will be “conjugate symmetric” [ i.e., H(-w) = H*(w) ]. So the magnitude is even: |H(-w)| = |H(w)|.
3.4 (d) Simple Bandpass Filter Design
1. When I multiply H, which I know is correct from the plot, I get a flat sinusoid until it makes a giant leap in amplitude and it then falls back to the flat sinusoid. Does this sound correct?
ANSWER: In part (d) you should be using the firfilt() function. You should not be multiplying by H(w). Use H(w) to explain what is happening. Use firfilt() to do the actual filtering.
2. When I use my filter on the sinusoids, I don’t get anything but a changed version of the original. It doesn’t look far from the original, but I am almost positive my filter is being set up correctly. Does the final filtered sinusoid really look like a single sinusoid?
ANSWER: It should if you really have a gain of less than 1/10 at the two frequencies that you are trying to eliminate. You can predict (mathematically) what the output should be. Linearity might be useful. Filter each sinusoid separately to see that the output amplitude is what you expect. Then do them all together.
3. How exactly do you calculate by hand the mathematical formula for the output signal?
ANSWER: Doing it by hand is actually part 3.4(e). It would be hard to get a formula for the entire output, but IF you ignore the first L-1 points of the output, then the output is a sum of sinusoids (sinusoid in —> sinusoid out). Evaluate H(w) to determine the output sinusoids. Recall the LTI-demo GUI. Read Example 6.4 on page 163 in the book.
4. When I filter the function I get a sinusoid that grows as time goes along. When I did filter the function, I got a warning that said it was ignoring the imaginary parts. Is this ok?
ANSWER: You have to ignore the first L-1 points. If L=100, that’s a lot. So focus your attention on the part of the signal After L-1. If I recall, with L=100 and a total length of 150, that means look at “n” from n=100 to n=150. In that region you should see a sinusoid. In the first L-1 points you are seeing the start-up “transient”.
5. For the plot of the output after the sinusoid is put through the filter, should it look similar to the output for the nulling frequency? Mine doesn’t, but maybe that’s because when I double the length of L, the width of the passband doesn’t change.
ANSWER: It should have only one frequency component, because the other two components are reduced. WARNING: The first L-1 points have to be ignored. This is the start-up TRANSIENT. After n=L the output should look sinusoidal. In the nulling case, L was a very small integer, so you don’t tend to see the start-up effect. In the BPF case, L is rather large, and the start-up might dominate the stem plot.
6. Are we supposed to use stem plots for this portion? If so, for which graphs should we use stem plots?
ANSWER: Whenever you plot a discrete-time signal like x[n] which is a function of a discrete variable “n,” use stem. Use plot for frequency responses where the variable “omega-hat” is continuous.
7. Is the magnitude of the output sinusoid supposed to increase and decrease as it goes along?
ANSWER: MIGHT HAPPEN. Once you get past the start-up region (the first L-1 points) the magnitude should stay (nearly) the same if you have only one sinusoid in the output. If the filter didn’t remove the other two components sufficiently, you might see an amplitude variation. Remember that the filter is supposed to reduce the amplitude of the other sinusoids by a factor of 0.1. So you might have a little variation due to the presence of the other two components. You can predict how big those components are for your particular filter by doing the math.
8. The two plots we are supposed to make should be sinusoids from which we can determine the frequency, rather than the frequency response plots, correct?