语音信号处理实验报告Word文件下载.docx
《语音信号处理实验报告Word文件下载.docx》由会员分享,可在线阅读,更多相关《语音信号处理实验报告Word文件下载.docx(15页珍藏版)》请在冰点文库上搜索。
plot(Mn);
fori=1:
n-1
ifx(i)>
=0y(i)=1;
elsey(i)=-1;
end
ifx(i+1)>
=0y(i+1)=1;
elsey(i+1)=-1;
w(i)=abs(y(i+1)-y(i));
end
k=1;
j=0;
while(k+N-1)<
n
Zm(k)=0;
fori=0:
N-1
Zm(k)=Zm(k)+w(k+i);
j=j+1;
k=k+N/2;
forw=1:
j
Q(w)=Zm(160*(w-1)+1)/(2*N);
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);
四、实验结果
语谱图:
(Matlab7.0用不了spectrogram)
【实验二】
Homomorphicanalysis
WriteaMATLABprogramtocomputetherealcepstrumsofasectionofvoicedspeechandunvoicedspeech.
Plotthesignal,thelogmagnitudespectrum,therealcepstrum,andthelowpasslifteredlogmagnitudespectrum.
三、实验程序
nfft=256;
[x,fs]=wavread('
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;
%窗宽度赋给循环自变量n
noverlap=0.5*fnlen;
while(n<
=length(x)-1)
fx=x(n-fnlen+1:
n).*win;
n=n+noverlap;
xhvp=xhv.*lifter'
;
figure;
subplot(4,1,1)
plot(lifter);
title('
倒谱滤波器'
subplot(4,1,2)
语音信号波形'
subplot(4,1,3)
plot(Xvm);
Xvm'
subplot(4,1,4)
plot(xhv);
xhv'
四、实验结果
【实验三】
一、实验题目
LPanalysis
二、实验要求
WriteaMATLABprogramtoconvertfromaframeofspeechtoasetoflinearpredictioncoefficients.PlottheLPCspectrumsuperimposedonthecorrespondingSTFT.
clear;
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);
holdon;
plot((0:
160-1),h,'
r'
【实验四】
Pitchestimation
二、实验内容
Writeaprogramtoimplementthepitchestimationandthevoiced/unvoiceddecisionusingtheLPC-basedmethod.
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'
%lowpassfilter
[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-termautocorrelation.
re=xcorr(errorlp);
%Findmaxautocorrelationforlagsintheintervalminlagtomaxlag.
minlag=17;
%F0:
450Hz
maxlag=160;
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+minlag
remax
【实验五】
Speechsynthesis
WriteaprogramtoanalyzeaspeechandsynthesizeitusingtheLPC-basedmethod.
主程序
[x,sr]=wavread('
p=[1-0.9];
x=filter(p,1,x);
N=256;
inc=128;
y=lpcsyn(x,N,inc);
wavplay(y,sr);
子程序lpcsyn
functiony=lpcsyn(x,N,inc)
%[x,sr]=wavread('
%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))%Voicedframe.
e=zeros(N,1);
e(1:
P(i):
N)=1;
%Impulse-trainexcitation.
else%Unvoicedframe.
e=randn(N,1);
%Whitenoiseexcitation.
yt=filter(G(i),A(i,:
),e);
j=(i-1)*inc+[1:
N];
y(j)=y(j)+yt'
end;
子程序lpcana
function[A,G,P,fnlen,fnshift]=lpcana(x,order)
fnshift=fnlen/2;
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;
【实验六】
Speechenhancement
Writeaprogramtoimplementthebasicspectralmagnitudesubtraction.
[speech,fs,nbits]=wavread('
%读入数据
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);
%噪声功率谱
%分帧
forq=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)=...
winsize+(q-1)*winsize/2)+ham;
y=fft(frame.*ham);
mag=abs(y);
%带噪语音功率谱
phase=angle(y);
%带噪语音相位
%幅度谱减
fori=1:
winsize
ifmag(i)-nmag(i)>
clean(i)=mag(i)-nmag(i);
elseclean(i)=0;
%频域中重新合成语音
spectral=clean.*exp(j*phase);
%反傅里叶变换并重叠相加
enhanced(1+(q-1)*winsize/2:
winsize+(q-1)*winsize/2)+real(ifft(spectral));
plot(speech);
xlabel('
样点数'
ylabel('
幅度'
原始语音波形'
语音加噪波形'
plot(enhanced);
增强语音波形'