
% MATLAB script to simulate the usage of a (sptool-designed)
% FIR filter (filt1) in a 2 channel QMF analysis/synthesis 
% filterbank.
% It should show if the alias components are cancelled out
% (two possible realisations are compared: synchron/asynchron)
%
% Dec. 4, 2001     C. Feldbauer <feldbauer@inw.tugraz.at>




async = 1;    % 0 or 1


% TAKE A FIR FILTER IMPORTED FROM SPTOOL
ht = filt1.tf.num;
hh = (-1).^(0:length(ht)-1) .* ht;


% GENERATE CHIRP
t = 0:0.001/8:10;
y = chirp( t,0,10,4000);
figure(1), specgram(y)


% SYNTHESIS FILTER
yt = filter( ht,1,y);
yh = filter( hh,1,y);


% DECIMATION
yt_dec = yt( 1:2:end);
% 1:2:end or 2:2:end ???
if async
  yh_dec = [ yh( 2:2:end), 0]; % asynchronous decimation
else
  yh_dec = yh( 1:2:end); % synchronous decimation
end


figure(2), specgram(yt_dec)
figure(3), specgram(yh_dec)


% INTERPOLATION (ZERO-INSERTION)
yt_int = zeros( 1,80002);
yt_int( 1:2:end) = yt_dec;

yh_int = zeros( 1,80002);                    
if async
  yh_int( 2:2:end) = yh_dec;
else
  yh_int( 1:2:end) = yh_dec;
end


% SYNTHESIS FILTER
yt_ = filter( ht, 1, yt_int);
% hh or -hh ???
if async
  yh_ = filter( hh, 1, yh_int);
else
  yh_ = filter( -hh, 1, yh_int);
end


% SUM
y_ = yt_ + yh_;

figure(4), specgram(y_)
