语⾳信号处理实验报告【实验⼀】⼀、实验题⽬Short time analysis⼆、实验要求
Write a MA TLAB program to analyze a speech and simultaneously, on a single page, plot the following measurements:1. the entire speech waveform2. the short-time energy, En3. the short-time magnitude, Mn4. the short-time zero-crossing, Zn5. the narrowband spectrogram6. the wideband spectrogram
Use both the speech waveforms in the wznjdx_normal.wav. Choose appropriate window sizes, window shifts, and windowfor the analysis. Explain your choice of these parameters.三、实验程序clear
[x,fs]=wavread('wznjdx_normal.wav');n=length(x);N=320;
subplot(4,1,1);plot(x);h=linspace(1,1,N);En=conv(h,x.*x);subplot(4,1,2);plot(En);Mn=conv(h,abs(x));subplot(4,1,3);plot(Mn);for i=1:n-1if x(i)>=0 y(i)=1;else y(i)=-1;end
if x(i+1)>=0 y(i+1)=1;else y(i+1)=-1;end
w(i)=abs(y(i+1)-y(i));end
k=1;j=0;
while (k+N-1)Zm(k)=0;for i=0:N-1
Zm(k)=Zm(k)+w(k+i);endj=j+1;k=k+N/2;endfor w=1:j
Q(w)=Zm(160*(w-1)+1)/(2*N);end
subplot(4,1,4);plot(Q);grid;figure(2);
subplot(2,1,1);spectrogram(x,h,256,200,0.0424*fs); subplot(2,1,2);spectrogram(x,h,256,200,0.0064*fs);四、实验结果
语谱图:(Matlab 7.0 ⽤不了spectrogram)
【实验⼆】⼀、实验题⽬
Homomorphic analysis⼆、实验要求
Write a MATLAB program to compute the real cepstrums of a section of voiced speech and unvoiced speech.Plot the signal, the log magnitude spectrum, the real cepstrum, and the lowpass liftered log magnitude spectrum.三、实验程序nfft=256;
[x,fs] = wavread('wznjdx_normal.wav');fx=x;
Xvm=log(abs(fft(fx,nfft)));xhv=real(ifft(Xvm,nfft));lifter=zeros(1,nfft);lifter(1:30)=1;lifter(nfft-28:nfft)=1;fnlen=0.02*fs; % 20ms
win=hamming(fnlen);%加窗n=fnlen;%窗宽度赋给循环⾃变量nnoverlap=0.5*fnlen;while(n<=length(x)-1)fx=x(n-fnlen+1:n).*win;n=n+noverlap;end
xhvp=xhv.*lifter';figure;subplot(4,1,1)plot(lifter);title('倒谱滤波器');subplot(4,1,2)plot(x);
title('语⾳信号波形');subplot(4,1,3)plot(Xvm);title('Xvm');subplot(4,1,4)plot(xhv);title('xhv');四、实验结果
【实验三】⼀、实验题⽬LP analysis⼆、实验要求
Write a MATLAB program to convert from a frame of speech to a set of linear prediction coefficients. Plot the LPC spectrumsuperimposed on the corresponding STFT.三、实验程序clear;
[x,fs]=wavread('wznjdx_normal.wav');fx=x(4000:4160-1);p=10;
[a,e,k]=aryule(fx,p);G=sqrt(e*length(fx));
f=log(abs(fft(fx)));h0=zeros(1,160);
h=log(G)-log(abs(fft(a,160)));figure(1);
subplot(211);plot(fx);subplot(212);plot(f);hold on;
plot((0:160-1),h,'r');四、实验结果
【实验四】⼀、实验题⽬Pitch estimation⼆、实验内容
Write a program to implement the pitch estimation and the voiced/unvoiced decision using the LPC-based method.三、实验程序clear
[x,fs]=wavread('wznjdx_normal.wav');n=length(x);Q = x';NFFT=512;N = 256;
Hamm = hamming(N);frame = 30;
M = Q(((frame -1) * (N / 2) + 1):((frame - 1) * (N / 2) + N)); Frame = M .* Hamm';% lowpass filter
[b2,a2]=butter(2,900/4000);
speech2=filter(b2,a2,Frame); % filter% residual
[a,e] = lpc(speech2,20);
errorlp=filter(a,1,speech2); % residual% Short-term autocorrelation.re = xcorr(errorlp);
% Find max autocorrelation for lags in the interval minlag to maxlag. minlag = 17; % F0: 450Hzmaxlag =160; % F0: 50Hz
fnlen=256;
[remax,idx] = max(re(fnlen+minlag:fnlen+maxlag));figure
subplot(3,1,1);plot(Frame);subplot(3,1,2);plot(speech2);subplot(3,1,3);plot(re);text(500,0,'idx');idx=idx-1+minlagremax四、实验结果
【实验五】⼀、实验题⽬Speech synthesis⼆、实验内容
Write a program to analyze a speech and synthesize it using the LPC-based method.三、实验程序主程序clear;
[x,sr] = wavread('wznjdx_normal.wav');p=[1 -0.9];x=filter(p,1,x);N=256;inc=128;
y=lpcsyn(x,N,inc);wavplay(y,sr);⼦程序lpcsyn
function y=lpcsyn(x,N,inc)
%[x,sr] = wavread('wznjdx_normal.wav');%pre = [1 -0.97];%x = filter(pre,1,x);%N=256;%inc=128;
fn=floor(length(x)/inc);y=zeros(1,50000);for (i=1:fn)
order=16;
x(1:N,i)=x((i-1)*inc+1:(i+1)*inc);
[A(i,:),G(i),P(i),fnlen,fnshift] = lpcana(x(1:N,i),order);if (P(i)) % V oiced frame.e = zeros(N,1);
e(1:P(i):N) = 1; % Impulse-train excitation.else % Unvoiced frame.
e = randn(N,1); % White noise excitation.end
yt=filter(G(i),A(i,:),e);j=(i-1)*inc+[1:N];y(j) = y(j)+yt';end;end
⼦程序lpcana
function [A,G,P,fnlen,fnshift] = lpcana(x,order)fnlen=256;fnshift=fnlen/2;n=length(x);
[b2,a2]=butter(2,900/4000);speech2=filter(b2,a2,x);[A,e]=lpc(speech2,order);errorlp=filter(A,1,speech2);re=xcorr(errorlp);
G=sqrt(e*length(speech2));minlag=17;maxlag=160;
[remax,idx]=max(re(n+minlag:n+maxlag));P=idx-1+minlag;end
四、实验结果
【实验六】⼀、实验题⽬Speech enhancement
⼆、实验内容
Write a program to implement the basic spectral magnitude subtraction.
三、实验程序clear
[speech,fs,nbits]=wavread('wznjdx_normal.wav');%读⼊数据alpha=0.04;%噪声⽔平winsize=256;%窗长
size=length(speech);%语⾳长度numofwin=floor(size/winsize);%帧数hamwin=zeros(1,size);%定义汉明窗长度enhanced=zeros(1,size);%定义增强语⾳的长度ham=hamming(winsize)';%%产⽣汉明窗x=speech'+alpha*randn(1,size);%信号加噪声noisy=alpha*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:winsizeif mag(i)-nmag(i)>0clean(i)=mag(i)-nmag(i);else clean(i)=0;endend
%频域中重新合成语⾳spectral=clean.*exp(j*phase);%反傅⾥叶变换并重叠相加
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));
endfigure(1);
subplot(3,1,1);plot(speech);xlabel('样点数');ylabel('幅度');title('原始语⾳波形');subplot(3,1,2);plot(x);xlabel('样点数');ylabel('幅度');title('语⾳加噪波形');subplot(3,1,3);plot(enhanced);xlabel('样点数');ylabel('幅度');title('增强语⾳波形');四、实验结果
因篇幅问题不能全部显示,请点此查看更多更全内容