Last active
March 18, 2022 02:19
-
-
Save RisingInIris2017/730e80eaf23e08c7c3744ae5006091e7 to your computer and use it in GitHub Desktop.
MATLAB实现回声加入和消除
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[yuanshi,fs]=audioread('文件名.wav'); %提取原始声音信号 | |
sound(yuanshi,fs);%听原始声音 | |
yuanshichangdu=length(yuanshi); | |
yuanshidanshengdao=yuanshi(1:yuanshichangdu);%取原始声音的一个声道 | |
subplot(1,3,1);plot(yuanshidanshengdao);title('原始信号波形'); | |
%yuanshifft=fft(yuanshi,N);% 对原始信号进行傅立叶变化 | |
%subplot(2,3,4);plot(abs(yuanshifft));title('原始信号幅值'); | |
yanchi=input('回声间隔时长:'); | |
shuaijian=input('回声衰减系数:'); | |
cishu=input('输入回声次数:'); | |
chongji=[1]; | |
jiange=zeros(1,fs*yanchi); | |
for count=1:cishu | |
chongji=[chongji jiange shuaijian]; | |
end | |
huiyin=conv(yuanshidanshengdao,chongji);% 原始声音信号与延迟声音信号的卷积 | |
subplot(1,3,2);plot(huiyin);title('含回音信号的波形'); | |
% huiyinfft=fft(huiyin);% 对回音信号进行傅立叶变化 | |
% subplot(2,3,5);plot(abs(huiyinfft));title('含回音信号的幅值'); | |
sound(huiyin,fs);% 听有回音信号 | |
pause(3); | |
changdu=[0:yuanshichangdu]; | |
nixitongchongji=impz(1,chongji,changdu);% 离散时间系统单位脉冲响应 | |
quhuiyin=conv(huiyin,nixitongchongji);% 脉冲与有回音的函数卷积去掉回音 | |
jieduanquhuiyin=quhuiyin(1:yuanshichangdu); | |
%MATLAB数组的下标从1开始,是可以用double类型的整数做下标的 | |
%这里为什么要截断信号? | |
subplot(1,3,3);plot(jieduanquhuiyin);title('还原信号的波形'); | |
% quhuiyinfft=fft(quhuiyin);% 对恢复声音信号进行傅立叶变化 | |
% subplot(2,3,6);plot(abs(quhuiyinfft));title('还原信号的幅值'); | |
sound(jieduanquhuiyin,fs);% 听恢复后声音信号 | |
if 0 %提问前把这里的0改为1 | |
quhuiyin=conv(huiyin,nixitongchongji); | |
figure(2); | |
plot(quhuiyin);title('不截断的信号波形'); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment