资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,*,Dr WangZhengsheng-Lecture Notes,1,Lecture 4,MATLAB,信号分析,(,Sound Analysis,),Dr WangZhengsheng-Lecture Notes,2,Lecture 4 Matlab,语音分析,基本要求,(,1,)掌握,语音文件,的创建与控制,以及语音文件的,基本操作,;,(2)熟练掌握录制语音,基本的命令和,控制;,(3)初步掌握用,傅里叶变换,来表现信号的波形和频谱。,(,4,)掌握,坐标轴的控制和图形标注命令,及其用法。,Dr WangZhengsheng-Lecture Notes,3,Lecture 4 Matlab,语音分析,1.,语音录制函数,wavrecord,Record sound using Windows audio input device.,wavrecord will be removed in a future release.Use,AUDIORECORDER,instead.,命令格式:,Y=wavrecord(N,FS,CH),records N audio samples at FS Hertz from CH number of input channels from the Windows WAVE audio device.,Standard audio rates are 8000,11025,22050,and 44100 Hz.CH can be 1 or 2(mono or stereo).Samples are returned in a matrix of size N-by-CH.If not specified,FS=11025 Hz,and CH=1.,Dr WangZhengsheng-Lecture Notes,4,Lecture 4 Matlab,语音分析,Y=wavrecord(.,DTYPE)uses the data type specified by the string DTYPE to record the sound.The string values for DTYPE are listed in the following table along with corresponding bits per sample and acceptable data ranges for Y.,DTYPE Bits/sample Ys Data range,-,double 16 -1.0=Y +1.0,single 16 -1.0=Y +1.0,int16 16 -32768=Y=+32767,uint8 8 0=Y=255,Dr WangZhengsheng-Lecture Notes,5,Lecture 4 Matlab,语音分析,Example:Record and play back 5 seconds of 16-bit audio sampled at 11.025 kHz.,Fs=11025;,y =,wavrecord,(5*Fs,Fs,int16);,wavplay(y,Fs);,Dr WangZhengsheng-Lecture Notes,6,Lecture 4 Matlab,语音分析,2.,语音文件生成函数,wavwrite,Write Microsoft WAVE(.wav)sound file.,wavwrite(Y,FS,NBITS,WAVEFILE)writes data Y to a Windows WAVE file specified by the file name WAVEFILE,with a sample rate of FS Hz and with NBITS number of bits.,NBITS must be 8,16,24,or 32.Stereo data should be specified as a matrix with two columns.,命令格式:,wavwrite(Y,FS,NBITS,WAVEFILE),wavwrite(Y,FS,WAVEFILE)assumes NBITS=16 bits.,wavwrite(Y,WAVEFILE)assumes NBITS=16 bits and FS=8000 Hz.,Dr WangZhengsheng-Lecture Notes,7,NBITS Ys data type Ys Data range Output Format,-,8 uint8 0=Y=255 uint8,16 int16 -32768=Y=+32767 int16,24 int32 -223=Y=223-1 int32,If Y contains floating point data:,NBITS Ys data type Ys Data range Output Format,-,8 single or double -1.0=Y +1.0 uint8,16 single or double -1.0=Y +1.0 int16,24 single or double -1.0=Y +1.0 int32,32 single or double -1.0=Y=+1.0 single,Lecture 4 Matlab,语音分析,Example:Record and play back 5 seconds of 16-bit audio sampled at 11.025 kHz.,Fs=11025;,y =wavrecord(5*Fs,Fs,int16);,wavwrite,(y,Fs,d:matlab.wav);%,存储录音,wavplay(y,fs);%,播放录音,Dr WangZhengsheng-Lecture Notes,9,Lecture 4 Matlab,语音分析,3.,语音文件读出函数,wavread Read Microsoft WAVE(.wav)sound file.,Y=wavread(FILE)reads a WAVE file specified by the string FILE,returning the sampled data in Y.The.wav extension is appended if no extension is given.,命令格式:,Y,FS,NBITS=wavread(FILE),.=wavread(FILE,N),.=wavread(FILE,N1 N2),Y,.=wavread(.,FMT),SIZ=wavread(FILE,size),Y,FS,NBITS,OPTS=wavread(.),Dr WangZhengsheng-Lecture Notes,10,Lecture 4 Matlab,语音分析,FMT=native,#Bits MATLAB data type Data range,-,8 uint8 (unsigned integer)0=Y=255,16 int16 (signed integer)-32768=Y=+32767,24 int32 (signed integer)-223=Y=223-1,32 single(floating point)-1.0=Y=+1.0,FMT=double,#Bits MATLAB data type Data range,-,N32 double -1.0=Y +1.0,N=32 double -1.0=Y=+1.0,Note:Values in y might exceed-1.0 or+1.0 for the case of,N=32 bit data samples stored in the WAV file.,Example:Record and play back 5 seconds of 16-bit audio sampled at 11.025 kHz.,Fs=11025;,y =wavrecord(5*Fs,Fs,int16);,wavwrite(y,Fs,d:matlab.wav);%,存储录音,wavplay(y,fs);%,播放录音,%,读取录音文件,y,Fs,nbits=,wavread,(d:matlab.wav);,Dr WangZhengsheng-Lecture Notes,12,Lecture 4 Matlab,语音分析,4.,语音文件播放函数,wavplay,Play sound using Windows audio output device.,wavplay will be removed in a future release.Use,AUDIOPLAYER,instead.,命令格式:,wavplay(Y,FS):sends the signal in vector Y with sample frequency of FS Hertz to the Windows WAVE audio device.Standard audio rates are 8000,11025,22050,and 44100 Hz.,wavplay(Y),wavplay(.,async),wavplay(.,sync),Supported data types for Y and the corresponding number of bits per sample used during playback in each format are as follows:,Data Type bits/sample,double 16,single 16,int16 16,uint8 8,Example:Record and play back 5 seconds of 16-bit audio sampled at 11.025 kHz.,Fs=11025;,y =wavrecord(5*Fs,Fs,int16);,wavwrite(y,Fs,d:matlab.wav);%,存储录音,wavplay,(y,fs);%,播放录音,%,读取录音文件,Dr WangZhengsheng-Lecture Notes,15,Lecture 4 Matlab,语音分析,5.,傅里叶变换函数,fft,Discrete Fourier transform.,fft(X)is the discrete Fourier transform(DFT)of vector X.For matrices,the fft operation is applied to each column.For N-D arrays,the fft operation operates on the first non-singleton dimension.,命令格式:,fft(X,N)is the N-point fft,padded with zeros if X has less than N points and truncated if it has more.,fft(X,DIM)or fft(X,N,DIM)applies the fft operation across the dimension DIM.,Example:,对获取的语音信号进行傅里叶变换,.,N=length(y);%,求语音信号的长度,Y=,fft,(y,N);%,傅里叶变换,Dr WangZhengsheng-Lecture Notes,17,Lecture 4 Matlab,语音分析,6.,傅里叶逆变换函数,ifft,nverse discrete Fourier transform.,ifft(X)is the inverse discrete Fourier transform of X.,命令格式:,ifft(X,N)is the N-point inverse transform.,ifft(X,DIM)or ifft(X,N,DIM)is the inverse discrete Fourier transform of X across the dimension DIM.,ifft(.,symmetric)causes ifft to treat X as conjugate symmetric along the active dimension.,ifft(.,nonsymmetric)causes ifft to make no assumptions about the symmetry of X.,Example:,将频域函数经傅里叶逆变换变为时域函数,.,语音“,matlab,matlab,matlab,”的语音波形和频谱。,语音“湖南师大”的语音波形和频谱。,
展开阅读全文