TA的每日心情 | 奋斗 2024-7-1 22:21 |
|---|
签到天数: 2014 天 [LV.Master]伴坛终老
- 自我介绍
- 数学中国站长
群组: 数学建模培训课堂1 群组: 数学中国美赛辅助报名 群组: Matlab讨论组 群组: 2013认证赛A题讨论群组 群组: 2013认证赛C题讨论群组 |
2#
发表于 2013-11-7 10:11
|只看该作者
|
|邮箱已经成功绑定
使用wavread
# ^# @& \! ?2 K! S8 @6 JCreate a WAV file from the example file handel.mat,9 g; w) W8 o7 |" V6 D0 Z* @: b
and read portions of the file back into MATLAB.% Create WAV file in current folder.; ]. F. i1 s B! f& p- D# ^3 H
load handel.mat
/ h5 I' {3 o: V; b! E; b) |3 `
: r! D- a2 L, `( D# n2 Khfile = 'handel.wav';8 Q4 l; V6 Z( A' m
wavwrite(y, Fs, hfile)
5 {7 _ R, {2 }$ X, f. [0 \/ iclear y Fs
" Y J0 \; S1 G0 _( s
: h3 q2 e2 ^' o% K) S2 L% e* k% Read the data back into MATLAB, and listen to audio.
* N& ^3 y1 i" w3 N: r3 A2 C[y, Fs, nbits, readinfo] = wavread(hfile);
8 M: N+ I0 Z, psound(y, Fs);
" a4 H0 D7 v- C6 X% ? R
5 a4 @ t' v7 U- |* Y% Pause before next read and playback operation.
$ E5 u9 K( t) z' p# ]duration = numel(y) / Fs;! s& x# k/ `" q8 g/ k, e. C7 p1 B
pause(duration + 2)+ K( ` j1 y4 R+ ]5 o- A+ @
! y7 @: f2 j3 l5 k& z1 f# K; |% Read and play only the first 2 seconds.
% O8 E( `* i# U% ]) Unsamples = 2 * Fs;0 a8 g$ [1 v- c! t1 V
[y2, Fs] = wavread(hfile, nsamples);
1 O* R6 H% ?& Y u4 Q& E- _3 {8 Rsound(y2, Fs);
$ Y( ~7 y- o' `1 C. a& Q2 apause(4)
. ~% l3 {# B$ q) }1 l , c- ]/ X$ v( c3 L" J9 V1 M! G$ h
% Read and play the middle third of the file.% u# d& _4 h1 \) b. y
sizeinfo = wavread(hfile, 'size');
2 ^" f1 |+ r/ u1 V* B8 I
" t1 Y6 J' p* B+ C* l6 k% p6 Stot_samples = sizeinfo(1);
' p! I7 z/ w5 J% u. l: D( estartpos = tot_samples / 3;% S: t! H+ o& z
endpos = 2 * startpos;
; d+ a0 N/ L6 H N/ {1 b$ ^ $ C; o( R9 e9 }: e7 b
[y3, Fs] = wavread(hfile, [startpos endpos]);
- N+ O3 {' b# N) V) `- Z8 ysound(y3, Fs); |
|