11-1 Filter Applications (�o�i������)

¥»¸`±N¤¶²Ð¦b¼Æ¦ì°T¸¹³B²z±`¥Î¨ìªºÂoªi¾¹¡]Filters¡^¡A¨Ã²³æ¤¶²Ð¨äÀ³¥Î¡C¤@¯ë¤H¤j·§³£Å¥¹LÂoªi¾¹¡A¦ý¬O¹ï©ó¬ÛÃöªº¼Æ¾Ç¤ÀªR¡A¥i¯à³£Ä±±o«Ü½ÆÂø¡A·q¦Ó»·¤§¡C¥»¸`±N±qÀ³¥Î­±¨ÓµÛ¤â¡A¨Ã»¡©ú¬ÛÃöªº MATLAB «ü¥O¡A©Ò¥H¨Ã¤£·|²o¯A¨ì½ÆÂøªº¤ÀªR¡C

²³æªº»¡¡A¤@­ÓÂoªi¾¹¥i¥H¥Î¨â­Ó¦V¶q a ©M b ¨Ó¥Nªí¡A¨ä¤¤ a ªºªø«×¬O p¡Ab ªºªø«×¬O q¡A¦Ó¥B a ªº²Ä¤@­Ó¤¸¯À a1 ¥Ã»·¬O 1¡A¦p¤U¡G

a = [1, a2, ... ap]
b = [b1, b2, ... bq]
·í§Ú­Ì§â¨ã¦³°Ñ¼Æ a ©M b ªºÂoªi¾¹À³¥Î¨ì¤@¬qÂ÷´²®É¶¡°T¸¹ x[n]¡A©Ò±o¨ìªºµ²ªG¬O y[n]¡A¥i¥Hªí¥Ü¦p¤U¡G
y[n] = b1x[n] + b2x[n-1] + ... + bqx[n-q+1]
-a2y[n-1] - a3y[n-2] - ... - apx[n-p+1]
³o­Ó¦¡¤l¬Ý°_¨Ó¦³ÂI½ÆÂø¡A¤U­±§Ú­Ì¨Ó¬Ý°_­Ó¯S¨Ò¡A´N·|¤ñ¸û²M·¡¡C

­º¥ý¡A¦pªG

a = [1]
b = [1/5, 1/5, 1/5, 1/5, 1/5]
¨º»òÂoªi¾¹ªº¿é¥X´N¬O
y[n] = (x[n] + x[n-1] + x[n-2] + x[n-3] + x[n-4])/5
³o´N¬O¤@­Ó²³æªºÂoªi¾¹¡A´«¥y¸Ü»¡¡AÂoªi¾¹ªº¿é¥X­È¡Aµ¥©ó­ì°T¸¹¦b¹L¥h¤­ÂIªº¥­§¡­È¡A¦]¦¹³o­ÓÂoªi¾¹´N¦³¡u§C³q¡v¡]Low Pass¡^ªº®ÄªG¡A´«¥y¸Ü»¡¡A¤ñ¸û¦y¾Uªº°T¸¹¡]°ªÀWªº³¡¤À¡^¡A¸g¹L¤F¤­ÂI¨D¥­§¡¡A·|Åܪº¤ñ¸û¥­·Æ¡A¦]¦¹¾ã­Ó°T¸¹ªº°ªÀW³¡¤À·|³QÀ£§C¡A¦Ó§CÀW³¡¤À«h¤ñ¸û¤£¨ü¨ì¼vÅT¡A©Ò¥H³o¤@ÃþÂoªi¾¹´NºÙ¬°¡u§C³qÂoªi¾¹¡v¡]Low Pass Filter¡^¡C§C³qÂoªi¾¹ªº®ÄªG¡A´N¦n¹³¥Î¯ÈªM¸nµÛ¼L¤ÚÁ¿¸Ü¡A¥u³Ñ¤U§C¨H¡B¼Ò½k¡B´e´eªºÁn­µ¡C

Hint
¬°¤°»ò¸n¤W¯ÈªMÁ¿¸Ü¡A·|¦³§C³qÂoªi¾¹ªº®ÄªG¡H½Ð·Q·Q¬Ý...

¥H¤U¬O¤@­Ó½d¨Ò¡G

Example 1: lpf01.mwaveFile='whatMovies.wav'; au=myAudioRead(waveFile); % Filter parameters a = [1]; b = [1, 1, 1, 1, 1]/5; y = filter(b, a, au.signal); % Plot the result time = (1:length(au.signal))/au.fs; subplot(2,1,1); plot(time, au.signal); title('Original signal x[n]'); subplot(2,1,2); plot(time, y); title('Output signal y[n]'); au.signal=y; myAudioWrite(au, 'lpf01.wav'); % Save the output signal

¦b¤W­z½d¨Ò¤¤¡Ay = filter(b, a, x) §Y¬O¥Ñ­ì©l°T¸¹ x ¤ÎÂoªi¾¹°Ñ¼Æ a ©M b¡A¨Ó²£¥ÍÂoªi¾¹ªº¿é¥X°T¸¹ y¡C¥Ñ¤W­z½d¨Ò¹Ï§Î¥i¥H¬Ý¥X¡A¦b°ªÀWªº³¡¤À¡]¤×¨ä¬O®ð­µªº³¡¤À¡^¡A°T¸¹¾_´T©úÅã­°§C¡A³o´N¬O§C³qÂoªi¾¹ªº®ÄªG¡C§Ú­Ì¤]¥i¥Hª½±µÅ¥¬Ý¬Ý°T¸¹ªº®t²§¡G §Ú­Ì¦b¬Ý¥t¤@²ÕÂoªi¾¹¡G
a = [1]
b = [1, -1]
¨º»òÂoªi¾¹ªº¿é¥X´N¬O
y[n] = x[n] - x[n-1]
´«¥y¸Ü»¡¡AÂoªi¾¹ªº¿é¥X­È¡Aµ¥©ó­ì°T¸¹¥Ø«eªº­È´î±¼­ì°T¸¹¦b«e¤@­Ó®É¶¡ÂIªº­È¡A¦]¦¹ÅܤƼ@¯Pªº°T¸¹¡]§Y°ªÀW°T¸¹¡^¡A¨ä®t²§·|³Q¬ðÅã¥X¨Ó¡A¦ÓÅܤƤ£¼@¯Pªº°T¸¹¡]§Y§CÀW°T¸¹¡^¡A¨ä®t²§·|³QÀ£§í¡A©Ò¥H³o¤@ÃþªºÂoªi¾¹´NºÙ¬°¡u°ª³qÂoªi¾¹¡v¡]High Pass Filter¡^¡A½Ð¨£¤U¦C½d¨Ò¡G

Example 2: hpf01.mwaveFile='whatMovies.wav'; au=myAudioRead(waveFile); % Filter parameters a = [1]; b = [1, -1]; y = filter(b, a, au.signal); % Plot the result time = (1:length(au.signal))/au.fs; subplot(2,1,1); plot(time, au.signal); title('Original signal x[n]'); subplot(2,1,2); plot(time, y); title('Output signal y[n]'); au.signal=y; myAudioWrite(au, 'hpf01.wav'); % Save the output signal

¥Ñ¤W­z½d¨Ò¹Ï§Î¥i¥H¬Ý¥X¡A¦b°ªÀWªº³¡¤À¡]¤×¨ä¬O®ð­µªº³¡¤À¡^¡A°T¸¹¾_´T¬Û¹ï©úÅãÅܤj¡A³o´N¬O°ª³qÂoªi¾¹ªº®ÄªG¡C§Ú­Ì¤]¥i¥Hª½±µÅ¥¬Ý¬Ý°T¸¹ªº®t²§¡G ¸g¹L¤F°ª³qÂoªi¾¹¤§«á¡A°T¸¹Å¥°_¨Óªº·Pı¡A¦n¹³´N¬O¤p«¬¦¬­µ¾÷¡]¨S¦³­«§C­µ³â¥z¡^ªº¼½©ñ®ÄªG¡A¤ñ¸û¦y¾U¨ë¦Õ¡C

°£¤F°ª³q©M§C³qÂoªi¾¹¥~¡AÂoªi¾¹¤]¥i¥H²£¥Í¦UºØ¤£¦Pªº­µ®Ä¡A¨Ò¦p

a = [1]
b = [1, 0, 0, 0, ..., 0, 0.8] ¡]¤¤¶¡§¨Âø¤F3199­Ó¹s¡^
¨º»òÂoªi¾¹ªº¿é¥X´N¬O
y[n] = x[n] + 0.8*x[n-3200]
´«¥y¸Ü»¡¡A³o­ÓÂoªi¾¹ªº¥\¯à´N¬O¡u³æ¦¸°j­µ¾¹¡v¡A·|²£¥Í¤@¦¸°j­µ¡A­Y¨ú¼ËÀW²v fs = 16kHz¡A«h°j­µ©M­ì­µªº®É¶¡®t¬O 3200/fs = 3200/16000 = 0.2 ¬í¡C½Ð¨£¤U¦C½d¨Ò¡G

Example 3: echo01.mwaveFile='whatMovies.wav'; au=myAudioRead(waveFile); % Filter parameters delay=0.2; gain=0.8; a = [1]; b = [1, zeros(1, round(delay*au.fs)-1), gain]; y = filter(b, a, au.signal); % Plot the result time = (1:length(au.signal))/au.fs; subplot(2,1,1); plot(time, au.signal); title('Original signal x[n]'); subplot(2,1,2); plot(time, y); title('Filter output y[n]'); au.signal=y; myAudioWrite(au, 'echo01.wav'); % Save the output signal[Warning: Data clipped when writing file.] [> In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('audiowrite>clipInputData', 'E:\MATLAB\R2015a\toolbox\matlab\audiovideo\audiowrite.m', 396)" style="font-weight:bold">audiowrite>clipInputData</a> (<a href="matlab: opentoline('E:\MATLAB\R2015a\toolbox\matlab\audiovideo\audiowrite.m',396,0)">line 396</a>) In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('audiowrite', 'E:\MATLAB\R2015a\toolbox\matlab\audiovideo\audiowrite.m', 176)" style="font-weight:bold">audiowrite</a> (<a href="matlab: opentoline('E:\MATLAB\R2015a\toolbox\matlab\audiovideo\audiowrite.m',176,0)">line 176</a>) In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('myAudioWrite', 'd:\users\jang\matlab\toolbox\sap\myAudioWrite.m', 29)" style="font-weight:bold">myAudioWrite</a> (<a href="matlab: opentoline('d:\users\jang\matlab\toolbox\sap\myAudioWrite.m',29,0)">line 29</a>) In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('echo01', 'D:\users\jang\books\audioSignalProcessing\example\echo01.m', 16)" style="font-weight:bold">echo01</a> (<a href="matlab: opentoline('D:\users\jang\books\audioSignalProcessing\example\echo01.m',16,0)">line 16</a>) In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('goWriteOutputFile>dummyFunction', 'D:\users\jang\books\goWriteOutputFile.m', 85)" style="font-weight:bold">goWriteOutputFile>dummyFunction</a> (<a href="matlab: opentoline('D:\users\jang\books\goWriteOutputFile.m',85,0)">line 85</a>) In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('goWriteOutputFile', 'D:\users\jang\books\goWriteOutputFile.m', 55)" style="font-weight:bold">goWriteOutputFile</a> (<a href="matlab: opentoline('D:\users\jang\books\goWriteOutputFile.m',55,0)">line 55</a>)]

¦b¤W­z½d¨Ò¤¤¡Again = 0.8 ¥Nªí°j­µªº°I´î¤ñ­È¡A¦Ó delay = 0.2 «h¬O°j­µªº®É¶¡®t¡C§Ú­Ì¥i¥HÅ¥¬Ý¬Ý­ì°T¸¹©MÂoªi¾¹¿é¥Xªº®t²§¡G ¤W­zÂoªi¾¹¥u¯à²£¥Í¤@­Ó°j­µ¡A¤ñ¸û¤£¹³¤@¯ë¦h­«°j­µ¡C­Y­n²£¥Í¦h­«°j­µ¡A¥i¥Î¤U¦CÂoªi¾¹¡G
a = [1, 0, 0, 0, ..., 0, -0.8] ¡]¤¤¶¡§¨Âø¤F3199­Ó¹s¡^
b = [1]
¨º»òÂoªi¾¹ªº¿é¥X´N¬O
y[n] = x[n] + 0.8*y[n-3200]
³o­ÓÂoªi¾¹ªº¥\¯à´N¬O¡u¦h­«°j­µ¾¹¡v¡A·|²£¥Í¦h­«°j­µ¡A­Y¨ú¼ËÀW²v fs = 16kHz¡A«h°j­µ¤§¶¡ªº®É¶¡®t¬O 3200/fs = 3200/16000 = 0.2 ¬í¡C½Ð¨£¤U¦C½d¨Ò¡G

Example 4: echo02.mwaveFile='whatMovies.wav'; au=myAudioRead(waveFile); % Filter parameters delay=0.2; gain=0.8; a = [1 zeros(1, round(delay*au.fs)), -gain]; b = [1]; y = filter(b, a, au.signal); % Plot the result time = (1:length(au.signal))/au.fs; subplot(2,1,1); plot(time, au.signal); title('Original signal x[n]'); subplot(2,1,2); plot(time, y); title('Filter output y[n]'); au.signal=y; myAudioWrite(au, 'echo02.wav'); % Save the output signal[Warning: Data clipped when writing file.] [> In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('audiowrite>clipInputData', 'E:\MATLAB\R2015a\toolbox\matlab\audiovideo\audiowrite.m', 396)" style="font-weight:bold">audiowrite>clipInputData</a> (<a href="matlab: opentoline('E:\MATLAB\R2015a\toolbox\matlab\audiovideo\audiowrite.m',396,0)">line 396</a>) In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('audiowrite', 'E:\MATLAB\R2015a\toolbox\matlab\audiovideo\audiowrite.m', 176)" style="font-weight:bold">audiowrite</a> (<a href="matlab: opentoline('E:\MATLAB\R2015a\toolbox\matlab\audiovideo\audiowrite.m',176,0)">line 176</a>) In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('myAudioWrite', 'd:\users\jang\matlab\toolbox\sap\myAudioWrite.m', 29)" style="font-weight:bold">myAudioWrite</a> (<a href="matlab: opentoline('d:\users\jang\matlab\toolbox\sap\myAudioWrite.m',29,0)">line 29</a>) In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('echo02', 'D:\users\jang\books\audioSignalProcessing\example\echo02.m', 16)" style="font-weight:bold">echo02</a> (<a href="matlab: opentoline('D:\users\jang\books\audioSignalProcessing\example\echo02.m',16,0)">line 16</a>) In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('goWriteOutputFile>dummyFunction', 'D:\users\jang\books\goWriteOutputFile.m', 85)" style="font-weight:bold">goWriteOutputFile>dummyFunction</a> (<a href="matlab: opentoline('D:\users\jang\books\goWriteOutputFile.m',85,0)">line 85</a>) In <a href="matlab:matlab.internal.language.introspective.errorDocCallback('goWriteOutputFile', 'D:\users\jang\books\goWriteOutputFile.m', 55)" style="font-weight:bold">goWriteOutputFile</a> (<a href="matlab: opentoline('D:\users\jang\books\goWriteOutputFile.m',55,0)">line 55</a>)]

§Ú­Ì¥i¥HÅ¥¬Ý¬Ý­ì°T¸¹©MÂoªi¾¹¿é¥Xªº®t²§¡G
Audio Signal Processing and Recognition (­µ°T³B²z»P¿ëÃÑ)