Calculating audio pitch in MATLAB?

僤鯓⒐⒋嵵緔 提交于 2019-12-20 04:52:22

问题


Yesterday I finalised the code for detecting the audio energy of a track displayed over time, which I will eventually use as part of my audio thumbnailing project.

However I would also like a method that can detect the pitch of a track displayed over time, so I have 2 options from which to base my research upon.

[y, fs, nb] = wavread('Three.wav');                  %# Load the signal into variable y

frameWidth = 441;                                    %# 10 msec
numSamples = length(y);                              %# Number of samples in y
numFrames = floor(numSamples/frameWidth);            %# Number of full frames in y
energy = zeros(1,numFrames);                         %# Initialize energy

for frame = 1:numFrames                              %# Loop over frames
  startSample = (frame-1)*frameWidth+1;              %# Starting index of frame
  endSample = startSample+frameWidth-1;              %# Ending index of frame
  energy(frame) = sum(y(startSample:endSample).^2);  %# Calculate frame energy
end

That is the correct code for the energy method, and after researching, I found that I would need to use a Discrete Time Fourier Transform to find the current pitch of each frame in the loop.

I thought that the process would be as easy as modifying the final lines of the code to include the "fft" MATLAB command for calculating Discrete Fourier Transforms but all I am getting back is errors about an unbalanced equation.

Help would be much appreciated, even if it's just a general pointer in the right direction. Thank you.


回答1:


Determining pitch is a lot more complicated than just applying a DFT. It also depends on the nature of the source - different algorithms are appropriate for speech versus a musical instrument, for example. If this is a music track, as your question seems to imply, then you're probably out of luck as there is no obvious way of determining a single pitch value for multiple musical instruments playing together (how would you even define pitch in this context ?). Maybe you could be more specific about what you are trying to do - perhaps a power spectrum would be more useful than trying to determine an arbitrary pitch ?



来源:https://stackoverflow.com/questions/3416428/calculating-audio-pitch-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!