audio - How can I get frequency and pitch from a monophonic wav file using matlab? -
i given assignment music data mining course have 2 days do. can't figure out how finish question 4 (below). other 4 questions extremely easy do, 1 makes no sense. nothing has taught in course helps, , no internet sources have been able shed light. understand how pitch name once have frequency of note, i'm not sure how frequency. appreciated.
full question:
write matlab program named hw2q4xxx.m (xxx last 3 digits of n-number) identify pitch containing in wave files.
the program executed using command:
hw2q4xxx(‘input.wav’)
input: • input.wav – monophonic wave file containing sound of single pitch.
output: • display pitch name , register on screen. example, displaying c4 wave file containing pitch frequency around 265 hz.
when loaded matlab, .wav files contain data vector , sampling frequency. need perform spectral estimate or fft determine frequency content. recommend using pwelch, perform power spectral estimate data. once loaded, can try along these lines:
pwelch(data,[],[],1024,fs)
this plot spectral estimate , should contain strong tone @ frequency of interest.
you can better spectrum using windowing techniques, example, using hamming window reduce lot of ripple see in spectrum plots. done using this:
nfft = 1024; pwelch(data,hamming(nfft),[],nfft,fs)
increasing size of nfft provide better frequency resolution. can play around (for example try nfft=1024*10).
to extract frequency information, can use findpeaks function. give code try:
nfft = 1024*10; out = pwelch(data,hamming(nfft),[],nfft,fs); [pks locs] = findpeaks(out); indx = find(pks == max(pks)); indx_max = locs(indx); f = indx_max/length(out) * (fs/2);
this save pwelch data vector "out". find of local maxima "pks" along locations "locs". can find maximum local peak find command , determine index within vector "out" located. last line converts index frequency.
Comments
Post a Comment