www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/ExtractLowFrequencySubbandFromSpeechExample.m

    %% Extract Low Frequency Subband From Speech 
% Use a halfband analysis filter bank and interpolation filter to extract
% the low frequency subband from a speech signal.

%%
% *Note*: This example runs only in R2016b or later. If you are using an 
% earlier release, replace each call to the function with the equivalent 
% |step| syntax. For example, myObject(x) becomes step(myObject,x).

%%
% Set up the audio file reader, the analysis filter bank, audio device writer,
% and interpolation filter. The sampling rate of the audio data is 22050 Hz.
% The order of the halfband filter is 52, with a transition width of 2 kHz.

hafr = dsp.AudioFileReader('speech_dft.mp3','SamplesPerFrame',1024);

filterspec = 'Filter order and transition width';
Order = 52;
TW = 2000;

firhalfbanddecim = dsp.FIRHalfbandDecimator(...
    'Specification',filterspec,'FilterOrder',Order,...
    'TransitionWidth',TW,'SampleRate',hafr.SampleRate);

firhalfbandinterp = dsp.FIRHalfbandInterpolator(...
    'Specification',filterspec,'FilterOrder',Order,...
    'TransitionWidth',TW,'SampleRate',hafr.SampleRate/2);

hap = audioDeviceWriter('SampleRate',hafr.SampleRate);
%%
% View the magnitude response of the halfband filter.
fvtool(firhalfbanddecim)
%%
% Read the speech signal from the audio file in frames of 1024 samples.
% Filter the speech signal into lowpass and highpass subbands with a
% halfband frequency of 5512.5 Hz. Reconstruct a lowpass approximation of
% the speech signal by interpolating the lowpass subband. Play the filtered
% output.
while ~isDone(hafr)
  audioframe = hafr();
  xlo = firhalfbanddecim(audioframe);
  ylow = firhalfbandinterp(xlo);
  hap(ylow);
end

%%
% Wait until the audio file is played to the end, then close the input
% file and release the audio output resource.
release(hafr);           
release(hap);