My project Noise reduction.
1.Here my code input from microphone and save to .wav
Read in the file
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');`
before recorded how can i plot a spectrogram graph
time = 10 frequency = 0 - 8000
2.how to plot a spectrogram graphs after of noise reduction between frequency 500 - 2000 Hz
Like this graphs spectrogram and spectrum
Here Link
Here my filter code.
n = 7;
beginFreq = 500 / (fs/2);
endFreq = 2000 / (fs/2);
[b,a] = butter(n, [beginFreq, endFreq], 'bandpass');
thank you.
Try this:
**** 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)|')