-1
我想從wav文件中移除噪聲。但是在運行腳本後我仍然收到以下錯誤。 我使用的wav文件是https://drive.google.com/file/d/0BzIyOj_KUKufTTNWMFlRMW9fT2c/view?usp=sharing噪聲在Matlab中取消
我使用的代碼從Remove noise from wav file, MATLAB。
>> run sample3
Index exceeds matrix dimensions.
Error in sample3 (line 17)
stem(1:N, f(:,2));
Error in run (line 96)
evalin('caller', [script ';']);
下面是代碼:
%% 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;