Code covered by the BSD License  

Highlights from
spectral smoothing

image thumbnail

spectral smoothing

by

 

07 Feb 2014 (Updated )

This exercise smooths the log magnitude spectrum of a frame of voiced speech using liftering.

[X1s,X2s,X3s,L]=compute_spectra(xin,fs,ss,Lm,p,iwin_STFT,iwin_LPC,Lc,nfft)
function [X1s,X2s,X3s,L]=compute_spectra(xin,fs,ss,Lm,p,iwin_STFT,iwin_LPC,Lc,nfft)
%
% Comparison of STFT of a section of voiced speech with two spectral
% smoothing methods, namely low quefrency liftering of the cepstrum, and
% lpc analysis spectral fitting
%
% Inputs:
%   xin: speech array
%   fs: speech sampling rate
%   ss: starting sample in speech file
%   Lm: length of analysis frame in msec
%   p: lpc system order
%   iwin_STFT: STFT window type (1:Hamming, 2:Rectangular)
%   iwin_LPC: LPC window type (1:Hamming, 2:Rectangular)
%   Lc: maximum quefrency for cepstral lifter in samples
%   nfft: fft size
%
% Outputs:
%   X1s: lpc analysis log magnitude spectrum
%   X2s: STFT analysis log magnitude spectrum
%   X3s: real cepstral analysis log magnitude spectrum

% convert Lm (in msec) to L (in samples)
    L=round(Lm*fs/1000);
    
% compute window correction to log magnitude responses
    [window_STFT,window_LPC,Ulog_STFT,Ulog_LPC]=...
        get_window_correction(iwin_STFT,iwin_LPC,L);
    
% perform lpc analysis
    x=xin(ss:ss+L-1)*32767;
    xw=(x.*window_LPC');
    [A,G,a,r]=autolpc(xw,p);
    X1=abs(freqz(G,A,nfft,'whole',fs));
    X1s=20*log10(X1(1:nfft/2+1))-Ulog_LPC;
    
% measure STFT spectrum
    xw=(x.*window_STFT');
    X2=20*log10(abs(fft(xw,nfft)));
    X2s=X2(1:nfft/2+1)-Ulog_STFT;
    
% compute real cepstrum and lifter using L quefrency lifter
    Xm=log(abs(fft(xw,nfft)));
    Xc=ifft(Xm,nfft);
    Xc(Lc+1:nfft-Lc+1)=0;
    Xcf=fft(Xc,nfft);
    X3=abs(Xcf(1:nfft/2+1));
    X3s=20*log10(exp(X3))-Ulog_LPC;
end

Contact us