代码如下
clear
Fs = 44100 ;
nBits = 16 ;
nChannels = 2 ;
ID = -1;
recObj = audiorecorder(Fs,nBits,nChannels,ID);
%用麦克风采集一个时长为五秒钟的演讲样本
disp('Start speaking.')
recordblocking(recObj,5);
disp('End of Recording.');
%冲击响应函数h(t)
a0=1;%反射系数
a1=0.8;
a2=0.6;
T=1/Fs;
t=0:T:3;
h=a0*my_delta(t-0.2)+a1*my_delta(t-0.4)+a2*my_delta(t-0.6);
%卷积得到回音
y=conv(recObj,h);
y=y';
player = audioplayer(y,fs);
play(player);%播放回音
subplot(2,1,1);
plot(recObj);%画原始音
title('原始音');
subplot(2,1,2);
plot(y(1:length(y)));%画回音
title('经过回音系统');