auFile='taiwanUniversity.wav'; au=myAudioRead(auFile); n=2; au.fs=au.fs/n; au.signal=au.signal(1:n:end, 1); % Down sampling index1=round(0.66*au.fs); frameSize=256; index2=index1+frameSize-1; frame=au.signal(index1:index2); % Take the frame for display audiowrite('frame.wav', frame, au.fs); subplot(2,1,1); plot(au.signal); grid on xlabel('Sample index'); ylabel('Amplitude'); title(auFile); %xlabel('取樣點索引值'); ylabel('波形振幅'); title(auFile); axis([1, length(au.signal), -1 1]); line(index1*[1 1], [-1 1], 'color', 'm', 'linewidth', 1); line(index2*[1 1], [-1 1], 'color', 'm', 'linewidth', 1); subplot(2,1,2); plot(frame, '.-'); grid on xlabel('Sample index within the frame'); ylabel('Amplitude'); %xlabel('音框內的取樣點索引值'); ylabel('波形振幅'); axis([1, length(frame), -1 1]); %boxOverlay([60.5 -0.7 52 1.4], 'r', 1, '音色:基本週期內的波形', 'top'); message=sprintf('Timbre:\nWaveform in a fundamental period'); boxOverlay([60.5 -0.5 52 1.2], 'r', 1, message, 'top'); subplot(211); loc1=get(gca, 'position'); subplot(212); loc2=get(gca, 'position'); %% ===== arrow 1 for closeup x1=[loc1(1)+(index1(1)-1)/(length(au.signal)-1)*loc1(3), loc2(1)]; y1=[loc1(2), loc2(2)+loc2(4)]; ah=annotation('arrow', x1, y1, 'color', 'm', 'linewidth', 1); %% ====== arrow 2 for closeup x2=[loc1(1)+(index2-1)/(length(au.signal)-1)*loc1(3), loc2(1)+loc2(3)]; y2=[loc1(2), loc2(2)+loc2(4)]; ah=annotation('arrow', x2, y2, 'color', 'm', 'linewidth', 1); %% Double arrow for fundamental period axisLimit=axis; % axisLimit=[1, 256, -1, 1] xPos=[171, 223]; yPos=[0.65, 0.65]; xRel=loc2(1)+(xPos-axisLimit(1))/(axisLimit(2)-axisLimit(1))*loc2(3); yRel=loc2(2)+(yPos-axisLimit(3))/(axisLimit(4)-axisLimit(3))*loc2(4); ah=annotation('doublearrow', xRel, yRel, 'color', 'r'); textH=text(mean(xPos), mean(yPos), 'Fundamental period', 'horizontal', 'center', 'vertical', 'bottom'); %% Double arrow for volume axisLimit=axis; % axisLimit=[1, 256, -1, 1] xPos=axisLimit(2)+[1, 1]; yPos=[min(frame), max(frame)]; xRel=loc2(1)+(xPos-axisLimit(1))/(axisLimit(2)-axisLimit(1))*loc2(3); yRel=loc2(2)+(yPos-axisLimit(3))/(axisLimit(4)-axisLimit(3))*loc2(4); ah=annotation('doublearrow', xRel, yRel, 'color', 'r'); textH=text(mean(xPos), mean(yPos), 'Volume', 'horizontal', 'center', 'vertical', 'top', 'rotation', 90);