![](https://csdnimg.cn/release/download_crawler_static/86635063/bg1.jpg)
ams.m
Kamil Wojcicki
December 19, 2010
Usage:
1. Start Matlab
2. Run demo by typing: test
ams
3. Get help by typing: help ams
%
% Short−time Fourier analysis−modificat i o n−synthesis (AMS) test framework by Kamil Wojcicki, 2010 (test ams.m)
clear all; close all; % clc;
SNR = @(x,y) (10
*
log10((sum(x.ˆ2)))/(sum((x(:)−y(:)).ˆ2))); % in−line function for SNR computation
file.original = 'sp10.wav'; % specify the input fi le
[speech.original, fs, nbits] = wavread(file.or ig i n al); % read audio samples from th e input file
time = [0:length(speech.original)−1]/fs; % create time vector
Tw = 32; % analysi s frame duration (ms)
Ts = Tw/8; % analysi s frame shift (ms)
[speech.processed] = ams(speech.original, fs, Tw, Ts); % p r oc e ss speech through AMS framework without modification
% ADD OTHER PROCESSING HERE ... e.g.,
% [speech.proce s s ed 2] = ams(speech.original, fs, Tw, Tw/4, 'Allen & Rabiner');
% [speech.proce s s ed 3] = ams(speech.original, fs, Tw, Tw/4, 'Griffin & Lim');
methods = fieldnames(speech); % treatme n t names
M = length(methods); % number of treatments
system(sprintf('rm −f ./%s.txt', mfilename));
diary(sprintf(
'%s.txt', mfilename)); diary on;
for m = 1:M % loop through tre a tm e n t types and com pu t e SNR (dB)
method = methods{m};
snr.(method) = SNR(speech.original, speech.(method));
fprintf(
'SNR [ %12s ]: %4.2e dB\n', method, snr.(method));
end
diary off;
figure(
'Position', [20 20 1000 150
*
M], 'PaperPosit i o nM o d e', 'auto', 'Visible', 'on');
for m = 1:M % loop through tre a tm e n t types and plo t spectrograms
method = methods{m};
subplot(M,2,2
*
m−1);
% time domain plots
plot(time,speech.(method),'k−');
xlim([min(time) max(time)]);
title(sprintf(
'Waveform: %s SNR=%0.2e dB', method, snr.(method)), 'inter pr e t er', 'none');
xlabel(
'Time (s)');
ylabel(
'Amplitude');
subplot(M,2,2
*
m);
% spectrogram plots
myspectrogram(speech.(method), fs);
set(gca,
'ytick',[0:1000:16000],'yticklabel',[0:16]);
title(sprintf(
'Spectrogram: %s SNR=%0.2e dB', method, snr.(method)), 'inter p r et e r', 'none');
xlabel(
'Time (s)');
ylabel(
'Frequency (kHz)');
end
print('−depsc2', '−r250', sprintf('%s.eps', mfilename));
print(
'−dpng', sprintf('%s.png', mfilename));
for m = 1:M % loop through tre a tm e n t types and wri te audio to w av files
method = methods{m};
audio.(method) = 0.999
*
speech.(method)./max(abs(speech.(method)));
wavwrite(audio.(method), fs, nbits, sprintf(
'%s.wav',method));
end
%
% EOF
1