waveFile='taiwanUniversity.wav'; au=myAudioRead(waveFile); 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 frameBasic=frame.*hanning(frameSize); frameExtended=zeros(8*frameSize, 1); frameExtended(1:frameSize)=frameBasic; [magSpec, phaseSpec, freqVec, powerSpecInDb]=fftOneSide(frameExtended, au.fs); plot(freqVec, powerSpecInDb); grid on title('Power spectrum'); xlabel('Frequency (Hz)'); ylabel('Power (dB)'); axis tight %xlabel('ÀW²v (Hz)'); ylabel('®¶´T (dB)'); order=10; freqNormalized=freqVec/max(freqVec); p=polyfit(freqNormalized, powerSpecInDb, order); f=polyval(p, freqNormalized); line(freqVec, f, 'color', 'g', 'linewidth', 2); %% Plot FF axisLimit=axis; axisLoc=get(gca, 'position'); xPos=[945.3125, 1085.9375]; yPos=[6.9, 6.9]; xRel=axisLoc(1)+((xPos-axisLimit(1))/(axisLimit(2)-axisLimit(1)))*axisLoc(3); yRel=axisLoc(2)+((yPos-axisLimit(3))/(axisLimit(4)-axisLimit(3)))*axisLoc(4); ah=annotation('doublearrow', xRel, yRel, 'color', 'r'); textH=text(mean(xPos), mean(yPos), 'FF', 'horizontal', 'center', 'vertical', 'bottom'); %% Plot first formant [maxValue, maxId]=max(f); xPos=[freqVec(maxId)+100, freqVec(maxId)]; yPos=[maxValue+20, maxValue]; line(xPos(2), yPos(2), 'marker', 'o', 'color', 'r'); xRel=axisLoc(1)+((xPos-axisLimit(1))/(axisLimit(2)-axisLimit(1)))*axisLoc(3); yRel=axisLoc(2)+((yPos-axisLimit(3))/(axisLimit(4)-axisLimit(3)))*axisLoc(4); ah=annotation('arrow', xRel, yRel, 'color', 'r'); textH=text(xPos(1), yPos(1), 'First formant', 'horizontal', 'center', 'vertical', 'bottom'); %% Plot second formant f(1:round(length(f)/2))=-inf; [maxValue, maxId]=max(f); xPos=[freqVec(maxId)+100, freqVec(maxId)]; yPos=[maxValue+30, maxValue]; line(xPos(2), yPos(2), 'marker', 'o', 'color', 'r'); xRel=axisLoc(1)+((xPos-axisLimit(1))/(axisLimit(2)-axisLimit(1)))*axisLoc(3); yRel=axisLoc(2)+((yPos-axisLimit(3))/(axisLimit(4)-axisLimit(3)))*axisLoc(4); ah=annotation('arrow', xRel, yRel, 'color', 'r'); textH=text(xPos(1), yPos(1), 'Second formant', 'horizontal', 'center', 'vertical', 'bottom'); %% Plot timbre curve point=[1184, -41.83]; xPos=[point(1)+300, point(1)]; yPos=[point(2)+25, point(2)]; xRel=axisLoc(1)+((xPos-axisLimit(1))/(axisLimit(2)-axisLimit(1)))*axisLoc(3); yRel=axisLoc(2)+((yPos-axisLimit(3))/(axisLimit(4)-axisLimit(3)))*axisLoc(4); ah=annotation('arrow', xRel, yRel, 'color', 'r'); textH=text(xPos(1), yPos(1), 'Timbre: Smoothed power spectrum', 'horizontal', 'center', 'vertical', 'bottom'); %% Plot energy point=[freqVec(1), powerSpecInDb(1)]; line(point(1), point(2), 'marker', 'o', 'color', 'r'); xPos=[point(1)+300, point(1)]; yPos=[point(2)-25, point(2)]; xRel=axisLoc(1)+((xPos-axisLimit(1))/(axisLimit(2)-axisLimit(1)))*axisLoc(3); yRel=axisLoc(2)+((yPos-axisLimit(3))/(axisLimit(4)-axisLimit(3)))*axisLoc(4); ah=annotation('arrow', xRel, yRel, 'color', 'r'); textH=text(xPos(1), yPos(1), 'Energy (volume)', 'horizontal', 'center', 'vertical', 'top');