从音频信号中去除噪音

时间:2018-02-07 20:57:04

标签: matlab audio signals noise

下面的人是我的代码。我想从我自己使用随机函数添加的音频信号中去除噪音。下面的代码消除了某种噪音,但它仍然太嘈杂,我听不到声音。我还想为此代码添加音频文件,但在发布问题时我没有找到任何选项,因此您可以添加任意两个频道.wav声音文件。任何评论或提示都将有所帮助谢谢。

close all
clear 
clc 


[x,fs] = audioread('cello.wav');             
whos x;                                         
 pOrig = audioplayer(x,fs);                %Signal Play
 pOrig.play;

N = size(x,1);                            
figure;
subplot(2,1,1);
stem(1:N, x(:,1));
title('Left Channel of Origional signal');
subplot(2,1,2);
stem(1:N, x(:,2));
title('Right Channel of origional signal');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 df = fs/N;
 w = (-(N/2):(N/2)-1)*df;
 y1= fft(x(:,1),N)/N;
 y2 = fftshift(y1);
 figure;
 plot(w,abs(y2));
title('Fast Fourier Transform of Origional Signal')

   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
pause
 y=x;
 y = y + randn(size(y));
 pOrig = audioplayer(y,fs);
 pOrig.play;

figure;
subplot(2,1,1);
stem(1:N, y(:,1));
title('Left Channel with Noise');  
subplot(2,1,2);
stem(1:N, y(:,2));
title('Right Channel with Noise');                     




 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 df = fs/N;
 w = (-(N/2):(N/2)-1)*df;
 y1= fft(y(:,1),N)/N;
 y2 = fftshift(y1);
 figure;
 plot(w,abs(y2));
 title('Fast Fourier Transform of Noisy Signal')
 pause  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% filter design 
 n = 10;
beginFreq = 100 / (fs/2);
endFreq =  2000  / (fs/2);
%[b,a] = butter(n,  endFreq, 'low');
%fout = filter(b,a,y);                         % input y(noisy signal)

[b,a] = butter(n,  endFreq, 'low');
fout = filter(b,a,y);                         % input y(noisy signal)



figure;
subplot(2,1,1);
stem(1:N, fout(:,1));
title('Left channel after filtering');  
 subplot(2,1,2);
 stem(1:N, fout(:,2));
 title(' Right channel after filtering');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%plot(fout); 

 df = fs/N;
 w = (-(N/2):(N/2)-1)*df;
 y1= fft(fout(:,1),N)/N; 
 y2 = fftshift(y1);
 figure;
 plot(w,abs(y2));
title('Fast Fourier Transform  after filtering');

 pOrig = audioplayer(fout,fs);
 pOrig.play;

1 个答案:

答案 0 :(得分:2)

您正在使用 randn()函数添加噪声,该函数会产生高斯噪声,即白噪声。白噪声在频谱上具有恒定功率,这意味着您要添加0到20kHz的噪声(仅考虑音频频谱)。

您的滤波器是0.1-2 kHz之间的带通滤波器,因此根据我上面提到的,您仍然在这些频段中有噪声成分。理论上,无法过滤所有噪声成分,但您可能需要查看维纳滤波器以获得更好的结果。实际上,如果您了解高斯噪声参数,它就是最佳滤波器,这只是您的情况下噪声的方差。

如果要查看删除所有噪声的示例,可以在原始信号上添加带外噪声。这可以通过rand()生成随机序列并使用过滤器使其具有带宽限制。例如,使用3-10kHz带通滤波器对生成的噪声序列进行滤波,然后添加到原始音频序列。最后,在脚本中应用相同的黄油过滤器,以查看所有噪音已被删除。