当前位置:首页 > DSP语音信号处理论文
DSP语音信号处理课程设计论文
function f=enframe(x,win,inc) nx=length(x(:));nwin=length(win); if (nwin == 1)len = win; else len = nwin; end
if (nargin < 3) inc = len; end
nf = fix((nx-len+inc)/inc);f=zeros(nf,len); indf= inc*(0:(nf-1)).';inds = (1:len);
f(:) = x(indf(:,ones(1,len))+inds(ones(nf,1),:));if (nwin > 1) w = win(:)';f = f .* w(ones(nf,1),:); end
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles) [our]=wavread('3.wav');
specgram_hw3p20(our,128,64,10000); specgram_hw3p20(our,256,512,10000);
function [spec] = specgram_hw3p20(x, winlgh, frmlgh, sampling_rate); % specgram_hw3p20(x, winlgh, frmlgh, sampling_rate) %
% function to compute a spectrogram %
% x = input waveform
% winlgh = window length in samples % frmlgh = frame length in samples % sampling_rate = samples/sec % PARAMETERS
%sampling_rate = 10000; % sampling rate lfft = 1024; % FFT length lfft2 = lfft/2;
%winlgh = 200; % (128) window length (in samples) %frmlgh = 10; % frame interval (in samples) noverlap = winlgh - frmlgh; % x = x(1:4500); x = 2.0*x/max(abs(x));
etime = length(x)/sampling_rate;
%--------------------------------------------------------------------%
spec = abs(specgram(x, lfft, sampling_rate, winlgh, noverlap));
20
DSP语音信号处理课程设计论文
subplot(211);
plot((1:length(x))/sampling_rate,x)
xlabel('Time (s)');title('SPEECH');axis([0 etime -2.5 2.5]);grid; subplot(212)imagesc(0:.010:etime,
0:1000:(sampling_rate/2),log10(abs(spec)));axis('xy') xlabel('Time (ms)'),ylabel('Frequency (Hz)'); title('SPECTROGRAM');
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles) clc; clear;tic,
[y,fs]=wavread('3.wav');L=length(y); fw=y.*hamming(L);r=real(log(fft(fw,L))) pfw=cceps(fw);rpfw=rceps(fw);z=rpfw(1:30); p=pfw(31:L)logz=real(exp(fft(z,L))); logp=real(fft(p));
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
speech1_10k=wavread('3.wav',[1024 1273]);sw=speech1_10k.*hamming(250); Rsw=xcorr(sw');t=0.1:0.1:25;subplot(1,2,1);plot(t,sw);xlabel('ms'); Rsw4=[Rsw(250:253);Rsw(249:252);Rsw(248:251);Rsw(247:250)];Rsw6=[Rsw(250:255);Rsw(249:254);Rsw(248:253);Rsw(247:252);Rsw(246:251);Rsw(245:250)]; rea4=inv(Rsw4)*Rsw(251:254)'
rea6=inv(Rsw6)*Rsw(251:256)'; A4=sqrt(Rsw(250)-Rsw(251:254)*rea4); A6=sqrt(Rsw(250)-Rsw(251:256)*rea6); w=pi/512:pi/512:pi; j=sqrt(-1); FW4=rea4'*[exp(-j*w);exp(-j*w*2);exp(-j*w*3);exp(-j*w*4)];FW6=rea6'*[exp(-j*w);exp(-j*w*2);exp(-j*w*3);exp(-j*w*4);exp(-j*w*5);exp(-j*w*6)]; HW4=A4./(1-FW4); HW6=A6./(1-FW6);FW2=fft(sw,1024); FW3=FW2(1:512);
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles) clear
Y=wavread('3.wav',[1 1800]);
x1=Y(271:510);x2=Y(271:510);x3=Y(271:510);
21
DSP语音信号处理课程设计论文
%×??à1?·¨ r=zeros(1,240); for k=1:240 for n=1:240-k
r(k)=r(k)+x1(n)*x1(n+k); end end
for k1=1:1:240 if x2(k1)>0 x2(k1)=1; else if x2(k1)==0 x2(k1)=0; else if x2(k1)<0 x2(k1)=-1; end end end end j=1:240; for k1=1:1:240 ma=abs(max(x3)); tc=0.6*ma; if x3(k1)>tc
x3(k1)=x3(k1)-tc; else if x3(k1)<-tc x3(k1)=x3(k1)+tc; else
x3(k1)=0; end end end j=1:240;
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles) clear clc
winsize=256; % ′°3¤ winsize=256; % ′°3¤
[speech,fs,nbits]=wavread('3.wav'); size=length(speech); numofwin=floor(size/winsize);
ham=hamming(winsize)';hamwin=zeros(1,size); enhanced=zeros(1,size);
22
DSP语音信号处理课程设计论文
x=speech'+ n*randn(1,size);
noisy=n*randn(1,winsize); N = fft(noisy); nmag= abs(N); for q=1:2*numofwin-1
frame=x(1+(q-1)*winsize/2:winsize+(q-1)*winsize/2);hamwin(1+(q-1)*winsize/2:winsize+(q-1)*winsize/2)=hamwin(1+(q-1)*winsize/2:winsize+(q-1)*winsize/2)+ham; y=fft(frame.*ham); mag = abs(y);
phase = angle(y);for i=1:winsize if mag(i)-nmag(i)>0 clean(i)= mag(i)-nmag(i); else;clean(i)=0; end end
fff=exp(j*phase); spectral=clean.*fff;
enhanced(1+(q-1)*winsize/2:winsize+(q-1)*winsize/2)=enhanced(1+(q-1)*winsize/2:winsize+(q-1)*winsize/2)+real(ifft(spectral)); end
for i=1:size if hamwin(i)==0 enhanced(i)=0; else
enhanced(i)=enhanced(i)/hamwin(i); end end
SNR1 = 10*log10(var(speech')/var(noisy));SNR2 =
10*log10(var(speech')/var(enhanced-speech'));wavwrite(x,fs,nbits,'noisy.wav');wavwrite(enhanced,fs,nbits,'enhanced.wav'); subplot(3,1,1);plot(speech');title(['Original Voice (n=',num2str(n),')' ]);
specgram(speech'); title(['Original Voice (n=',num2str(n),')' ]); subplot(3,1,2); plot(x);
title(['Noise Added (SNR=',num2str(SNR1),'dB)']);
specgram(x);title(['Noise Added (SNR=',num2str(SNR1),'dB)']); subplot(3,1,3);plot(enhanced);
title(['Improved Voice (SNR=',num2str(SNR2),'dB SNR=',num2str(SNR2-SNR1),'dB)']); specgram(enhanced);
title(['Improved Voice (SNR=',num2str(SNR2),'dB SNR=',num2str(SNR2-SNR1),'dB)']); pause; sound(speech);pause; sound(x);pause; sound(enhanced);
23
DSP语音信号处理课程设计论文
参考文献
【1】 楼顺天,李博菡. 基于MATLAB的系统分析与设计-信号处理[M]. 西安:
西安电子科技大学出版社,1998.
【2】程佩青.数字信号处理教程[M].北京:清华大学出版社,2002.
【3】刘庆华,陈紫强,基于MATLAB和DSP的语音信号处理课程的建设,电气电子教学学报,Vol.28,No.4,26-28,2006.
【4】 张力,MATLAB在语音信号处理辅助教学中的应用,电气电子教学学报,2005年27卷2 期,96-99.
【5】 胡航,语音信号处理,哈尔滨工业大学出版社,2005年2月.
24
共分享92篇相关文档