Code covered by the BSD License  

Highlights from
Subband coders

image thumbnail

Subband coders

by

 

07 Feb 2014 (Updated )

This MATLAB exercise implements a two-band subband coder.

plotresp(h0,N,fs,fname)
function plotresp(h0,N,fs,fname)
%
% function to plot impulse and frequency responses of 2-band QMF filters
%
% Inputs:
%   h0: lower band impulse response
%   N: length of lower band impulse response
%   fs: sampling rate of input signal
%   fname: file with lower band impulse response

% form upper band impulse response from lower band response
    h1=(-1).^(0:N-1)'.*h0;
    
% use fft size of 1000
    nfft=1000;
    
% plot lower band responses at left and upper band responses at right
    hfig=figure;orient landscape;
    set(hfig,'Position',[80 78 990 660]);
    
    subplot(421),plot(0:N-1,h0,'k','LineWidth',2);grid on,axis tight;
        xlabel('time in samples'),ylabel('h0');
    subplot(422),plot(0:N-1,h1,'k','LineWidth',2);grid on,axis tight;
        xlabel('time in samples'),ylabel('h1');
    h0log=20*log10(abs(fft(h0,nfft)));
    h1log=20*log10(abs(fft(h1,nfft)));
    h0lin=abs(fft(h0,nfft));
    h1lin=abs(fft(h1,nfft));
    h0linsq=h0lin.*h0lin;
    h1linsq=h1lin.*h1lin;
    hsum=h0linsq+h1linsq;
    % fprintf('h0linsq: %6.2f %6.2f %6.2f %6.2f %6.2f \n',h0linsq(nfft/4-2:nfft/4+2));
    % fprintf('h1linsq: %6.2f %6.2f %6.2f %6.2f %6.2f \n',h1linsq(nfft/4-2:nfft/4+2));
    % fprintf('hsum: %6.2f %6.2f %6.2f %6.2f %6.2f \n',hsum(nfft/4-2:nfft/4+2));
    subplot(423),plot(0:fs/nfft:fs/2,h0log(1:nfft/2+1),'k','LineWidth',2);
        grid on,axis ([0 fs/2 -50 10]);xlabel('frequency (Hz)'),ylabel('(dB)');
    subplot(424),plot(0:fs/nfft:fs/2,h1log(1:nfft/2+1),'k','LineWidth',2);
        grid on,axis ([0 fs/2 -50 10]);xlabel('frequency (Hz)'),ylabel('(dB)');
    subplot(425),plot(0:fs/nfft:fs/2,h0lin(1:nfft/2+1),'k','LineWidth',2);
        grid on,axis ([0 fs/2 0 1]);xlabel('frequency (Hz)'),ylabel('mag');
    subplot(426),plot(0:fs/nfft:fs/2,h1lin(1:nfft/2+1),'k','LineWidth',2);
        grid on,axis ([0 fs/2 0 1]);xlabel('frequency (Hz)'),ylabel('mag');
    subplot(4,2,[7 8]),plot(0:fs/nfft:fs/2,hsum(1:nfft/2+1),'k','LineWidth',2);
        grid on,axis ([0 fs/2 min(hsum) max(hsum)]);xlabel('frequency (Hz)'),ylabel('mag');
    stitle=sprintf('QMF Filter:%s, composite response',fname);
    title(stitle);
end

Contact us