Matlab 如何绘制wav文件的频谱图以及麦克风降噪输入前后的频谱图

Matlab 如何绘制wav文件的频谱图以及麦克风降噪输入前后的频谱图,matlab,noise,noise-reduction,Matlab,Noise,Noise Reduction,我的项目是减少噪音 1.这里是我从麦克风输入的代码,并保存到.wav 读入文件 clear all; close all; mic1= dsp.AudioRecorder; hmfw = dsp.AudioFileWriter('myspeech.wav','FileFormat','WAV'); disp('Speak into microphone now'); time_end = 10; tic; while toc <= time_end step(hmfw, ste

我的项目是减少噪音

1.这里是我从麦克风输入的代码,并保存到.wav

读入文件

clear all;

close all;

mic1= dsp.AudioRecorder;
hmfw = dsp.AudioFileWriter('myspeech.wav','FileFormat','WAV');
disp('Speak into microphone now');
time_end = 10;
tic;
while toc <= time_end
    step(hmfw, step(mic1));
end

release(mic1);
release(hmfw);`

disp('Recording complete');
[f,fs] = audioread('C:\Users\Admin\Documents\MATLAB\myspeech.wav');`
谢谢。

试试这个:

**** The previous part of your code goes here ***
disp('Recording complete');
[y,fs] = audioread('myspeech.wav');

y = y(:,1); % Take only one channel from the recording


n = 7;
beginFreq = 500 / (fs/2);
endFreq = 2000 / (fs/2);
[b,a] = butter(n, [beginFreq, endFreq], 'bandpass');

%
dt = 1/fs;
L = size(y,1);                    % Length of signal
t = (0:L-1)'*dt;                  % Time vector

figure(1)

plot(t,y(:,1))
title('Recording')
xlabel('time (milliseconds)')

NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y(:,1),NFFT)/L;
f = fs/2*linspace(0,1,NFFT/2+1);

% Plot spectrum of channel 1 from the original signal
figure()
plot(f,2*abs(Y(1:NFFT/2+1))); hold on
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')

% Filter the two channels
filt_y = filter(b,a,y);

filt_Y = fft(filt_y,NFFT)/L;

% Plot the filtered spectrum of channel 1 from the original signal
plot(f,2*abs(filt_Y(1:NFFT/2+1))) 
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
**** The previous part of your code goes here ***
disp('Recording complete');
[y,fs] = audioread('myspeech.wav');

y = y(:,1); % Take only one channel from the recording


n = 7;
beginFreq = 500 / (fs/2);
endFreq = 2000 / (fs/2);
[b,a] = butter(n, [beginFreq, endFreq], 'bandpass');

%
dt = 1/fs;
L = size(y,1);                    % Length of signal
t = (0:L-1)'*dt;                  % Time vector

figure(1)

plot(t,y(:,1))
title('Recording')
xlabel('time (milliseconds)')

NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y(:,1),NFFT)/L;
f = fs/2*linspace(0,1,NFFT/2+1);

% Plot spectrum of channel 1 from the original signal
figure()
plot(f,2*abs(Y(1:NFFT/2+1))); hold on
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')

% Filter the two channels
filt_y = filter(b,a,y);

filt_Y = fft(filt_y,NFFT)/L;

% Plot the filtered spectrum of channel 1 from the original signal
plot(f,2*abs(filt_Y(1:NFFT/2+1))) 
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')