Matlab中的噪声消除
我试图从wav文件中去除噪声。但是在运行脚本之后,我一直会遇到以下错误。 我使用的wav文件是 我使用来自的代码 代码如下:Matlab中的噪声消除,matlab,audio,filter,noise,Matlab,Audio,Filter,Noise,我试图从wav文件中去除噪声。但是在运行脚本之后,我一直会遇到以下错误。 我使用的wav文件是 我使用来自的代码 代码如下: %% Read in the file clearvars; close all; [f,fs] = audioread('noise.wav'); %% Play original file pOrig = audioplayer(f,fs); pOrig.play; %% Plot both audio channels N = size(f,1); % Dete
%% Read in the file
clearvars;
close all;
[f,fs] = audioread('noise.wav');
%% Play original file
pOrig = audioplayer(f,fs);
pOrig.play;
%% Plot both audio channels
N = size(f,1); % Determine total number of samples in audio file
figure;
subplot(2,1,1);
stem(1:N, f(:,1));
title('Left Channel');
subplot(2,1,2);
stem(1:N, f(:,2));
title('Right Channel');
%% 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));
[B,A] = butter(n, [beginFreq, endFreq], 'bandpass');
%% 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;
代码假定信号为立体声(也称为两个通道)。您的声音文件很可能是mono(从声音的方式判断…也称为一个通道),因此代码中使用正确通道的任何引用都应该删除 简单地说,代码中唯一受影响的部分是在时域中显示正确的通道。代码的其余部分应该在访问立体声中的左声道时工作,该声道恰好是声音文件的第一列,也是单声道文件中的唯一一列 替换此代码:
N = size(f,1); % Determine total number of samples in audio file
figure;
subplot(2,1,1);
stem(1:N, f(:,1));
title('Left Channel');
subplot(2,1,2);
stem(1:N, f(:,2));
title('Right Channel');
与:
以后,请尝试更仔细地阅读MATLAB错误。它们对于代码中的问题是什么非常详细和描述性。在本例中,它抱怨您试图访问声音文件f
中不存在的列
注意:我是您链接的答案的原始作者
N = size(f,1); % Determine total number of samples in audio file
figure;
subplot(2,1,1);
stem(1:N, f(:,1));
title('Left Channel');
subplot(2,1,2);
stem(1:N, f(:,2));
title('Right Channel');
N = size(f,1); % Determine total number of samples in audio file
figure;
stem(1:N, f(:,1));
title('Mono Channel');