%% IIR coefficient quantization example
clear, clc, close all

%addpath('D:\Jose\Dropbox\research\codes\f')
addpath('C:\Users\Joe\Dropbox\research\codes\f')

b = [0.010046712776130
-0.049403687598540
0.150473361914200
-0.319871360898680
0.533358728622120
-0.711330379244980
0.784624125948800
-0.711330379244980
0.533358728622120
-0.319871360898680
0.150473361914200
-0.049403687598540
0.010046712776130];

a = [1.000000000000000
-5.222950000000000
16.765882437384999
-36.820566767839011
62.254446733092003
-82.416404610369369
88.366825983839149
-76.161563614790566
53.160123847723952
-29.047737472114161
12.218071793450189
-3.514525133785270
0.621789847728520];


figure, zplane(b.', a.');

m = matlab2tikz(gca, 1);
m.write('pole-zero.tex')

[H, w] = freqz(b, a);
figure, plot(w/pi, 10*log10(abs(H).^2))
m = matlab2tikz(gca);
m.write('mag.tex')

B = 14;
bq = floor(b*2^B)/2^B;
aq = floor(a*2^B)/2^B;

figure, zplane(bq.', aq.');

figure, freqz(bq, aq)