d = wavread('mpgr1_sx419-8k.wav')';
sr = 8000;
[ai,g,ex] = lpcfit(d);

% original signal
Ed = 10*log10(mean(d.^2))

r = lpcsynth(ai,g,ex);
% best case re-synthesis
Er = 10*log10(mean(r.^2))

p = lpcBHenc(ex);
exr = lpcBHdec(p);
rq = lpcsynth(ai,g,exr);
wavwrite(rq,sr,'d.wav');

% sound(rq);
% % sounds a little muffled.

% SNR
Errq = 10*log10(mean((r-rq).^2))
% and the comparison...
Er - Errq


% calculate bit rates again...
% how does the bit-rate ratio look for multi-pulse vs. excitation?
num_ex_bits = prod(size(ex))*4; % 4 bits/number
num_p_bits = log2(128)*length(p); % 128 bit window 

% figure out the original time scale
sr = 8000;
t = length(d)/sr; % 3.0656 seconds

ex_bit_rate = num_ex_bits/t % bits/second
p_bit_rate = num_p_bits/t  





