使用低通滤波给音频降噪

权当做个记录

#author: ly
#参数含义:分别是输入文件名称,输出文件名称,低通滤波的阈值
function dealAudio(inputfilename,ouputfilename,lowbound)
[x1,fs]=audioread(inputfilename);
figure(1);
plot(x1);
title('original signal');
xlabel('t');
ylabel('n');
figure(2);
y1=fft(x1);
y1=fftshift(y1);
derta_fs=fs/length(x1);
plot([-fs/2:derta_fs:fs/2-derta_fs],abs(y1));
title('original w');
grid on;

%低通滤波,截至频率1500;阻带衰减20db,过度带宽0.001pi
fc1=lowbound;
N1=2*pi*0.9/(0.001*pi);
wc1=2*pi*fc1/fs;
if rem(N1,2)==0
    N1=N1+1;
end
Window=boxcar(N1+1);
b1=fir1(N1,wc1/pi,Window);
figure(3);
freqz(b1,1,512);
title('低通滤波器频率响应');
x1_low=filter(b1,1,x1);
figure(4);
plot(x1_low);
title('低通滤波器处理过的时域');
figure(5);
plot([-fs/2:derta_fs:fs/2-derta_fs],abs(fftshift(fft(x1_low))));
title('经过处理的频域');
%sound(x1,fs);%original

%高通滤波,截至频率4000;阻带衰减40db,过度带宽0.1pi
fc2=4000;
N2=2*pi*3.1/(0.1*pi);
wc2=2*pi*fc2/fs;
N2=N2+mod(N2,2);
Window=hanning(N2+1);
b2=fir1(N2,wc2/pi,'high',Window);
figure(6);
freqz(b2,1,512);
title('高通滤波器频率响应');
x1_high=filter(b2,1,x1);
figure(7);
plot(x1_high);
title('高通滤波器处理过的时域');
figure(8);
plot([-fs/2:derta_fs:fs/2-derta_fs],abs(fftshift(fft(x1_high))));
title('经过处理的频域');

%带通滤波,下至频率4000,上截至频率8000;阻带衰减20db,过度带宽0.1pi
f1=40;
f2=3400;
w1=2*pi*f1/fs;
w3=w1+0.1*pi;
w2=2*pi*f2/fs;
w4=w2-0.1*pi;
w=[(w1+w3)/2,(w2+w4)/2];
B=0.1*pi;
N3=ceil(2*0.9*pi/B);
N3=N3+mod(N3,2);
Window=boxcar(N3+1);
b3=fir1(N3,w/pi,'stop',Window);
figure(9);
freqz(b3,1,512);
title('带通滤波器频率响应');
x1_daitong=filter(b3,1,x1);
figure(10);
plot(x1_daitong);
title('带通滤波器处理过的时域');
figure(11);
plot([-fs/2:derta_fs:fs/2-derta_fs],abs(fftshift(fft(x1_daitong))));
title('经过处理的频域');
%sound(x1,fs);%original
sound(x1_low,fs);
%sound(x1_high,fs);
%sound(x1_daitong,fs);
audiowrite(ouputfilename,x1_low,fs);

你可能感兴趣的:(数字媒体技术)