Granger Obliviate
Granger Obliviate

Reputation: 151

How to compute an IIR Filter frequency response in Octave/MATLAB

I'm trying to compute the frequency response of an IIR filter.

The transfer function of the filter is:

          

The value of a is computed as:

f     = 1000;
fsamp = 16000;
a     = 1 / (1 + (2 * pi * f) / fsamp); 

Ok so now I have the transfer function of my IIR filter. How should I now compute the frequency response? I thought about using the freqz function, but I need help defining the arguments, how do i define the numerator and denominator polynomials?

Upvotes: 1

Views: 2609

Answers (2)

Elina_syr
Elina_syr

Reputation: 76

f=1000; fsamp=16000; a=1/(1+(2*pi*f)/fsamp);
a = [1 -a];
b = [(1-a) 0];
w = logspace(-1,1);

h = freqs(b,a,w);
mag = abs(h);
phase = angle(h);
phasedeg = phase*180/pi;

subplot(2,1,1)
loglog(w,mag)
grid on
xlabel('Frequency (rad/s)')
ylabel('Magnitude')

subplot(2,1,2)
semilogx(w,phasedeg)
grid on
xlabel('Frequency (rad/s)')
ylabel('Phase (degrees)')

This is based on this solution https://www.mathworks.com/help/signal/ref/freqs.html by Mathworks. And I get this outcome:

          

Upvotes: 3

Luis Mendo
Luis Mendo

Reputation: 112699

The first two inputs of freqz are respectively the numerator and denominator of the transfer function expressed as polynomials of the variable z−1:

a = 0.7; % example value
num = 1-a;
den = [1, -a];
freqz(num, den, 1001)

enter image description here

Upvotes: 1

Related Questions