MATLAB信号分析
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Dr WangZhengsheng - Lecture Notes 7
• 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 3
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 Y's 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 4
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语音分析
NBITS Y's data type Y's Data range Output Format ------- ---------------- --------------------- ------------8 uint8 0 <= Y <= 255 uint8 16 int16 -32768 <= Y <= +32767 int16 24 int32 -2^23 <= Y <= 2^23-1 int32 If Y contains floating point data: NBITS Y's data type Y's 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语音分析
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')
%存储录音
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.
%存储录音
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(...)
• 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语音分析
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) -2^23 <= Y <= 2^23-1 32 single (floating point) -1.0 <= Y <= +1.0 FMT='double' #Bits MATLAB data type Data range ----- ------------------------- ------------------N<32 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 Dr samples - Lecture Notes 10 N=32 bit data WangZhengshengstored in the WAV file.
Dr WangZhengsheng - Lecture Notes 12
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.wavwenku.baidu.com); %存储录音 wavplay(y,fs); %播放录音 %读取录音文件 [y, Fs, nbits] = wavread('d:\matlab.wav');
Lecture 4
MATLAB信号分析 (Sound Analysis)
Dr WangZhengsheng - Lecture Notes
1
Lecture 4
基本要求
Matlab语音分析
(1)掌握语音文件的创建与控制,以及语音文件的基本操作; (2)熟练掌握录制语音基本的命令和控制; (3)初步掌握用傅里叶变换来表现信号的波形和频谱。 (4)掌握坐标轴的控制和图形标注命令及其用法。
Dr WangZhengsheng - Lecture Notes
5
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
2
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.
• 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 3
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 Y's 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 4
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语音分析
NBITS Y's data type Y's Data range Output Format ------- ---------------- --------------------- ------------8 uint8 0 <= Y <= 255 uint8 16 int16 -32768 <= Y <= +32767 int16 24 int32 -2^23 <= Y <= 2^23-1 int32 If Y contains floating point data: NBITS Y's data type Y's 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语音分析
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')
%存储录音
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.
%存储录音
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(...)
• 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语音分析
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) -2^23 <= Y <= 2^23-1 32 single (floating point) -1.0 <= Y <= +1.0 FMT='double' #Bits MATLAB data type Data range ----- ------------------------- ------------------N<32 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 Dr samples - Lecture Notes 10 N=32 bit data WangZhengshengstored in the WAV file.
Dr WangZhengsheng - Lecture Notes 12
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.wavwenku.baidu.com); %存储录音 wavplay(y,fs); %播放录音 %读取录音文件 [y, Fs, nbits] = wavread('d:\matlab.wav');
Lecture 4
MATLAB信号分析 (Sound Analysis)
Dr WangZhengsheng - Lecture Notes
1
Lecture 4
基本要求
Matlab语音分析
(1)掌握语音文件的创建与控制,以及语音文件的基本操作; (2)熟练掌握录制语音基本的命令和控制; (3)初步掌握用傅里叶变换来表现信号的波形和频谱。 (4)掌握坐标轴的控制和图形标注命令及其用法。
Dr WangZhengsheng - Lecture Notes
5
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
2
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.