# Why is the gain of my IIR filter positive?

Sorry, two questions in one day!

I'm struggling to understand what I'm doing wrong in this very simple filter design. I want to design a simple, single pole low pass filter and implement it as an IIR in an embedded system.

I was looking at the DSP book online at recursive filters, and using their single-pole example to get started: http://www.dspguide.com/ch19/1.htm

According to the next page the coefficients I should need for the IIR single pole low pass filter are: $a_0=1-x$ and $b_1=x$

In order to get $x$ they give the equation (19-5) of $x=\epsilon^{-2\pi f_c}$

Given an fc of 0.125, I calculate x = 0.455938. Is this correct?

An fc of 0.125 at a sampling rate of 8kHz is 1kHz.

I don't see why when I try to get the frequency response of this filter I end up with entirely positive gain, as shown below:

Here is the code I've been using:

%Start from nothing!
clear;

% Set the sampling frequency used by our digital filtering system:
fs=8000;

% Set the coefficients up (As already worked out!) for a single-pole low pass
% filter. This should give us -3dB @ 1kHz with -6dB/Octave roll off
a = [ 0.544062 ];
b = [ 1, 0.45594 ];

% Determine the frequency response of the filter design above. Get the output
% in frequency rather than rad/s. Use 64 plot points.
[H,f] = freqz(b, a, 64, fs);

% Show our cutoff frequency
cutoff = -3 * ones(64);

% Plot the result so that we can see if it is correct:
figure(1);
plot(f, 20*log10(abs(H)), f, cutoff);
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');

I'm again, just stumped as to what's going on, and don't know how to solve the issue.

-
You have your a and b vectors reversed. For a first-order IIR filter, the a vector should have two elements (and you almost always want the first element to be unity). So, you're plotting the frequency response of the filter with difference equation $0.544062y[n] = x[n] + 0.45594 x[n-1]$, which is not what you want. – Jason R Jan 9 at 16:11

You have your a and b vectors reversed. For a first-order IIR filter, the a vector should have two elements (and you almost always want the first element to be unity). So, you're plotting the frequency response of the filter with difference equation $0.544062y[n]=x[n]+0.45594x[n−1]$, which is not what you want.