function fbank_features = calc_fbank(in,fs)
%function fbank_features = calc_fbank(in,fs)
%
% CALC_FBANK  --  Computes the logarithmic energy in six frequency bands of the 
%                 input vowel signals, with the bands centered at 600, 1200,  
%                 1800, 2400, 3000, and 3600 Hz.
%
% Input Parameters:
%   in        --  The input vowel signal.  If 'in' is a matrix, the function 
%                 assumes one signal per row and computes filter bank features
%                 for each signal.
%   fs        --  Sampling frequency of the input signals
%
% Output Parameters:
%   fbank_features -- A matrix of the filter bank features, with row per row of
%                     the matrix 'in'.  Each column corresponds

% Written by Mark Bartsch, Winter 2002
% Modification History:
%    8/16/02  --  Added modification history (MB)


if nargin < 2
    fs = 8192;
end
fft_size = 2048;
frqs = (0:fft_size-1)*fs/fft_size;

% Define the impulse response for spectral smoothing
h1 = hanning(100)'.^2;

% Define the filter bank locations
fbank = [600 1200 1800 2400 3000 3600];
fbank = round(fbank/fs*fft_size + 1);

% Make sure the input is oriented properly
if any(size(in)==1)
    in = in(:)';
end

for i=1:size(in,1);
    % Calculate the spectrum
    spec = abs(fft(in(i,:),fft_size));
    
    % Smoothing in the frequency domain gives us output of
    %   a bandpass filter at each point of the frequency spectrum... 
    sm_spec = 20*log10(filter2(h1,spec));
    
    % Normalize for signal energy
    sm_spec = sm_spec - mean(sm_spec);

    % The energy out of our filter banks is defined by the output
    %   of the spectral smoothing operation at the appropriate locations
    fbank_features(i,:) = sm_spec(fbank);
end
