2015-05-24 65 views
0

我的項目降噪。如何繪製麥克風降噪輸入前後的wav文件和曲線圖譜圖

1.Here從我的麥克風輸入代碼,並保存爲.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');` 

之前記錄我如何可以繪製一個頻譜圖

時間= 10 頻率= 0 - 8000

2.如何在頻率500-2000Hz之間的降噪之後繪製頻譜圖圖

像這樣的圖形頻譜和頻譜

此處鏈接

https://www.google.co.th/search?q=spectrogram+matlab&newwindow=1&rlz=1C1JPGB_enTH637TH637&espv=2&source=lnms&tbm=isch&sa=X&ei=PZliVf3GMcuIuATCroIg&ved=0CAcQ_AUoAQ&biw=1920&bih=979#imgrc=s05zemtY2IFy7M%253A%3BBgWyAcO6UJomJM%3Bhttp%253A%252F%252Fwww.aquaphoenix.com%252Flecture%252Fmatlab10%252Fimages-large%252Fmatlab_audio_funky_plot_spectrogram.jpg%3Bhttp%253A%252F%252Fwww.aquaphoenix.com%252Flecture%252Fmatlab10%252Fpage4.html%3B960%3B768

這裏我的過濾代碼。

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

謝謝。

回答

0

試試這個:

**** 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)|') 
+0

哦,太感謝你了。 – KKI