1

I have implemented an IIR low pass filter in direct form 2, the input to the filter is a unit impulse $\delta[n]$. I have calculated the output of the filter for the mentioned input using the difference equation of direct form 2, the equations are given below:

$$\begin{align}w[n] &= x[n] - a_1 w[n-1] - a_2 w[n-2] \\ y[n] &= b_0 w[n] + b_1 w[n-1] + b_2 w[n-2] \end{align}$$

  • How to plot the frequency response of the output with out using inbuilt commands in MATLAB? Also I want to implement the same in fixed point using 32 bit and plot the frequency reponse of it.
  • For plotting should I use freqz command or plot(abs(fft(my ouput))?. Both should give me same frequency response, but I am getting different responses,

command used is plot(abs(fft(my output)))

using freqz command

Gilles
  • 3,386
  • 3
  • 21
  • 28
sai priya
  • 125
  • 2
  • 6
  • 2
    Your question is now much clearer, but now it would be good to know where you're stuck, because right now you're just stating the (homework) problem and you expect people to solve it for you. We're here to answer concrete questions that show some effort, not to provide complete solutions to exercises. – Matt L. Feb 22 '15 at 14:43
  • 1
    i'm just responding to the title and the equations (that i modified slightly to make them conform to convention). the equations depict the Direct Form II filter structure, which i would not recommend, especially for fixed point. – robert bristow-johnson Feb 22 '15 at 16:56
  • @robertbristow-johnson: For a second-order filter with 32 bit fixed-point arithmetic we don't have to worry too much about using a Direct Form II structure. Or am I missing anything? – Matt L. Feb 22 '15 at 18:38
  • 1
    it depends on how many bits are to the left of the binary point (irrespective of the number of bits to the right). what you're missing is that, for the DF2, the poles come before the zeros. if the filter is highly resonant, with poles close to the unit circle and with zeros very close to the poles (say, a notch filter), then $w[n]$ above will saturate because of high gain due to the poles before the zeros have any chance to beat down the gain. for DF1 this problem does not happen. and if you have an accumulator that remains doubly-wide, the DF1 does not amplify the quantization noise. – robert bristow-johnson Feb 22 '15 at 19:14
  • 1
    @robertbristow-johnson: OK, I see that, but the OP asked about plotting the frequency response of the resulting filter (for both cases, float and fixed-point), so I concluded that we're talking about coefficient quantization, not signal quantization, otherwise there wouldn't be any frequency response because we're dealing with a non-linear system. Of course, poles very close to the unit circle will get us into trouble, but that's not specific to the DF2 structure. – Matt L. Feb 22 '15 at 19:54
  • 2
    well, @MattL., what the fixed-point DF2 suffers that the DF1 doesn't (let's assume the same $H(z)$ in both cases) is clipping due to the gain of the poles before that gain is mitigated by the gain reduction of the zeros. the counterpart problem the DF1 has if the accumulator is not double-wide, is that the quantization error due to the zeros is amplified by the gain of the poles. but if the DSP (or the code) maintains a double-wide accumulator, the DF1 does not suffer that problem and does not suffer the internal clipping problem specific to the DF2. – robert bristow-johnson Feb 22 '15 at 20:17
  • 1
    @robertbristow-johnson: I agree, but have you read my previous comment? I said that from the OP I conclude that we're talking about coefficient quantization only, not about signal quantization. You're always referring to issues of signal quantization, whereas the OP talks about an ideal implementation with quantized coefficients. – Matt L. Feb 22 '15 at 20:27
  • 1
    Matt, i'm reading your comments. i don't always buy into the premise of your comments. originally you said "we don't have to worry too much about using a Direct Form II structure", and i clarified why we do have to worry more about DF2 than DF1 in a fixed-point context. as far as coefficient quantization (and the quantization of intermediate variables when calculating frequency response), you might wanna take a peek at the earlier answer i refer to below. – robert bristow-johnson Feb 22 '15 at 20:36
  • 4
    so is your question why your first plot doesn't look exactly like your second plot? one is a linear:linear plot where half of it is above Nyquist and the other is a log:linear plot all below Nyquist. – robert bristow-johnson Feb 23 '15 at 05:46
  • 2
    @robertbristow-johnson: It doesn't make sense to talk about frequency response when taking overflow and round-off noise into consideration (since that "frequency response" will be input signal dependent). However, coefficient quantization is relevant to discuss in this context and there will be a well defined frequency response with quantized coefficients (unless the poles move outside of the unit circle). So I guess my vote goes to Matt L. With that said, for a practical implementation signal representation is highly relevant, but it doesn't relate to the frequency response. – Oscar Feb 23 '15 at 10:32
  • 1
    @Oscar, we don't know that overflow has happened and i am not assuming it. as far as quantization round-off noise is concerned, you can certainly discuss frequency response both of the input to the output (by setting the implied noise input to zero) and from quantization noise source to output. we audio guys do that all the time. we call it "noise shaping". – robert bristow-johnson Feb 23 '15 at 13:32
  • 1
    @robertbristow-johnson: I think I see your point. Clearly, there is a frequency response from a quantization noise source to the output. However, it only depends on the (quantized) coefficients and not on other quantization noise sources (although they sum up at the output). My (and I think Matt L.'s) point was that when looking at the input to output frequency response, the implementation structure (i.e. the position of the quanitzation noise sources, possible overflow nodes, etc) doesn't matter. As an implication one can not determine the frequency response by simulating with an impulse. – Oscar Feb 23 '15 at 14:08
  • Where the final sentence should be elaborated as "can in general not determine the impulse response/frequency response by simulating it with a finite word length model/realization of the filter as it will contain input dependent round-off noise". Easy to check by changing the magnitude of the impulse, you will get different "frequency responses" (not just the scaling, which should naturally be compensated for anyway), as each instance is the correct frequency response plus the input dependent noise. – Oscar Feb 23 '15 at 14:14

1 Answers1

1

setting aside the DF1 vs. DF2 issue (and we know there are several other forms besides those two, all with advantages and disadvantages), there is an answer, sans phase response, to the OP's original question here.

robert bristow-johnson
  • 20,661
  • 4
  • 38
  • 76