20-2 ��������������?

b@qxWA`TɮתɦW .wavB.auB.mp3B.aifAڭ̳iHϥ MATLAB ӪŪoXɮסAҥΪOOaudioreadCҦpAYnŪdҵ{ؿɮ welcome.wavBeXTiΨüXTAiϥΤUC{G

Example 1: 20-TŪgBsP/audioRead01.m[y, fs]=audioread('welcome.wav'); sound(y, fs); % 񦹭T time=(1:length(y))/fs; % ɶbVq plot(time, y); % eXɶbWi

bWҤAfs OWv]sample rate^AȬ 11025ANbsoӭTɮ׮ɡAC|OU11025nT˭ȡC y OnTVqAϥ sound(y, fs) iXTAҥHA|ťڪnuw{vCtime hObbɶbVqA]N y time ϡANobɶbWTiΡC

Hint
bWzdҤATĤ@IҹɶO1/fsAڭ̤]iH令ɶO0AɹɶVqӬ time=(0:length(y)-1)/fsC

ƹWbsTɮ׮ɡAC@ӨIjO816Ӧ줸]bits^ҥNAYnD welcome.wav IOѦh֭Ӧ줸ӪܡAiϥ audioinfo(welcome.wav) Ӧ^ǦUجTAdҦpUG

Example 2: 20-TŪgBsP/audioInfo01.mfileName='welcome.wav'; info=audioinfo(fileName); fprintf('ɮצW = %s\n', info.Filename); fprintf('Y覡 = %s\n', info.CompressionMethod); fprintf('qDӼ = %g \n', info.NumChannels); fprintf('Wv = %g Hz\n', info.SampleRate); fprintf('I`Ӽ = %g \n', info.TotalSamples); fprintf('T = %g \n', info.Duration); fprintf('IѪR = %g 줸/I\n', info.BitsPerSample); ɮצW = D:\users\jang\books\matlabProgramming4beginner\example\20-TŪgBsP\welcome.wav Y覡 = Uncompressed qDӼ = 1 Wv = 11025 Hz I`Ӽ = 16001 T = 1.45134 IѪR = 8 줸/I

Hint
󤣦POɡAaudioinfo Ҧ^Ǫi঳ҤPAŪ̥iHOݬݥt@ӽd audioInfo03.mAӬݬݹ mp3 ɮת^ǵGC

Ū̥i|n_Ab welcome.wav TɮפAC@ӨI 8 Ӧ줸ӪܡAOqTiΨӬݡAC@Iȳ V1 M 1 AoOpഫHnD wav ɮת 8 줸OH unsigned integer]aŸơAYơ^覡xsA]үܪƭȬO 0 M 255 (2^8-1) AMATLAB ANȳ]wܼ y ɡA|۰ʱNƭȽվܤ V1 M 1 A]YnN MATLAB ŪXƭ^ 8 줸ҪܤƭȡAunNܼ y H 128AA[W 128ANiHoƭȡAҦpG

Example 3: 20-TŪgBsP/audioRead03.mfileName='welcome.wav'; [y, fs]=audioread(fileName); info=audioinfo(fileName); nbits=info.BitsPerSample; y0=y*(2^nbits/2)+(2^nbits/2); % y0 OxsbTɮפ difference=sum(abs(y0-round(y0))) difference = 0

bWҤAܼ difference ȬOsAN y0 ȧOơC~AFW[{XqΩʡAڭ̥ 2^nbits/2AӤϥ128C

MATLAB ɸƪWƤ覡AiHCpUG

Tɮפxs覡 ƭȽd MATLABWƤ覡
Unsigned 8-bit integer (uint8) y $\in$ [0, $2^8-1$] (y-$2^7$)/$2^7$
Signed 16-bit integer (int16) y $\in$ [$-2^{15}$, $2^{15}-1$] y/$2^{15}$
Signed 32-bit integer (int32) y $\in$ [$-2^{31}$, $2^{31}-1$] y/$2^{31}$

audioread ]iHŪnDΥn]Stereo^TɮסAɶǦ^ܼƬ㦳⪽檺}CAC@N@nDTAҦpG

Example 4: 20-TŪgBsP/audioRead04.mfileName='flanger.wav'; [y, fs]=audioread(fileName); % ŪT sound(y, fs); % 񭵰T left=y(:,1); % nDT right=y(:,2); % knDT subplot(2,1,1), plot((1:length(left))/fs, left); subplot(2,1,2), plot((1:length(right))/fs, right);

dҷ|ŪnDT flanger.wavAnDTAõeXnDTiΡCѩ󥪥knDq]YiΪ_T^ۤA]XӪĪGAPınbknD岾C]pDGA@ӳnDnTAApϥ MATLAB 惡TiBzA̫Უͭ쭵TbnD岾ĪGApPdҤ@H^

pGTɮ׫ܤjALk@ŪJOAڭ̤]iHϥ audioread ŪXTɪ䤤@AҦpG

Example 5: 20-TŪgBsP/audioRead05.m[y,fs]=audioread('welcome.wav', [4001 5000]); % ŪTɲ40015000I plot(y)

o@qiΥNuw{vuv}loiΡCѤWϥiݥXAni~O@ӶgiA_TjpNNqjpAӨg˼ƴNOuWvvCHWzϧΦӨA1000ӨIj]tF10ӶgAҥHCӶgj]t 100IAɶO 100/fs = 100/11025 = 0.0091 = 9.1 msAӰWvhO 1/0.0091 = 110.25 HzA⦨^AD`󤤥 la ]WvO 440 Hz^16ס]ӥ^ұo쪺A]NOUϤ A4]ƨӲ 5 ӥ^C


300

Hint

HչnCPıAOPWvƦCH^LӨA la WvO 440 Hz (Hertz)AKת la hO 880 HzACKת la hO 220 HzC^C@ӥ]t7ӥP5ӶA@ 12 AN 12 ӥb]semitones^AH MIDI зǦӨA la bȬO 69AWvO 440 HzA]bMWvഫ{igUCG $$semitone=69+12\log_2\left(\frac{Hz}{440}\right).$$

Ѥ@qnӨD䭵AbTBzW٬lܡ]Pitch Tracking^AOTBzܭn@AΦyXBտѡBۿqC

eLAaudioread |NŪ쪺TYb -1 M +1 ApGAQŪӭTxsbTɮפlơA]iHAdҦpUG

Example 6: 20-TŪgBsP/audioRead06.m[y, fs]=audioread('welcome.wav', [1, inf], 'native'); p=audioplayer(y, fs); play(p); % 񦹭T time=(1:length(y))/fs; % ɶbVq plot(time, y); % eXɶbWi class(y) % y ƫA ans = uint8

ѤWҥiHݥXAڭ̥[J 'native' audioread ĤTӰѼƮɡAŪXTN|OHɮפƫAǡA]ҤT y ƫA uint8APɵeXiΪ_Td]A -1 M +1 C


MATLAB{]pGJg