消除mp3文件中的噪音,MATLAB

时间:2018-12-31 22:52:48

标签: matlab audio noise-reduction

我在下面的链接中有一个mp3文件,该文件中的背景是人的嗓音和嗡嗡声。我要消除嗡嗡声。有谁可以告诉我如何在MATLAB中进行操作? https://www.dropbox.com/s/h95y1oelbzvcgkc/allthatbass.mp3?dl=0

%% Read in the file
clearvars;
close all;
[f,fs] = audioread('allthatbass.mp3');
%% Play original file
pOrig = audioplayer(f,fs);
N = size(f,1);
%% Plot the spectrum
df = fs / N;
w = (-(N/2):(N/2)-1)*df;
y = fft(f(:,1), N) / N; % For normalizing, but not needed for our analysis
y2 = fftshift(y);
figure;
plot(w,abs(y2));
%% Design a bandpass filter that filters out between 700 to 12000 Hz
n = 7;
beginFreq = 700 / (fs/2);
endFreq = 12000 / (fs/2);
[b,a] = butter(n, [beginFreq, endFreq], 'bandpass');
%% Filter the signal
fOut = filter(b, a, f);
%% Construct audioplayer object and play
p = audioplayer(fOut, fs);
p.play;

我希望能消除嗡嗡声,但输出声音像原始声音一样。

enter link description here

2 个答案:

答案 0 :(得分:1)

我已经下载了您在问题中链接的原始文件,并在末尾添加了以下行:

audiowrite('filtered.wav', fOut, fs);

生成的文件“ filtered.wav”听起来与我的耳朵非常不同(我使用头戴式耳机收听)。例如,如果您在Audacity中打开“ filtered.wav”并查看频谱,则它的确与原始频谱有所不同(如预期的那样,将删除700 Hz以下和12 kHz以上的频率)。

让我们尝试在matlab中对此进行验证。以下脚本读取两个文件并绘制两个fft的dB值。下方的曲线表示滤波后的信号,可以清楚地看到低音频率已被消除。超过12 kHz的切口也是可见的,但似乎这些频率已经在原始信号中衰减了,而带通滤波器对此起到了增强作用。

%% Read in both files
clearvars;
close all;
[f,fs] = audioread('allthatbass.mp3');
[fflt, fsflt] = audioread('filtered.wav');
N = size(f,1);
%% Compute the ffts
df = fs / N;
n = N / 2; % plot only the second half of the spectrum
w = (0:(n)-1)*df;
y = fft(f(:,1), N) / N;
y2 = fftshift(y);
yflt = fft(fflt(:,1), N) / N;
y2flt = fftshift(yflt);
%% Plot the spectrum of both files (use the dB value, i.e. 10 * log(abs(x)) )
figure;
ax1 = subplot(2,1,1);
plot(w,10*log(abs(y2(n:end-1,1))));
ax2 = subplot(2,1,2);
plot(w, 10*log(abs(y2flt(n:end-1,1))));
linkaxes([ax1, ax2], 'y'); % link the axes (this makes it easier to visually compare the plots)

答案 1 :(得分:0)

尝试在MATLAB中使用低通滤波器。它们相对容易实现。您可以找到文档以及示例here