Mercurial > hg > adaptinstrspec
comparison functions/midiPitch2Shift.m @ 0:b4e26b53072f tip
Initial commit.
author | Holger Kirchhoff <holger.kirchhoff@eecs.qmul.ac.uk> |
---|---|
date | Tue, 04 Dec 2012 13:57:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b4e26b53072f |
---|---|
1 function shifts = midiPitch2Shift(midiPitches, tuningFreqInHz, binFreqsCQT) | |
2 % shifts = midiPitch2Shift(midiPitches, tuningFreqInHz, binFreqsCQT) | |
3 % | |
4 % converts midi pitch to shift values in constant-Q vector. | |
5 % shifts for pitches that below the lowest or above the highest CQT | |
6 % frequency are set to a value of -1 | |
7 | |
8 numMidiPitches = length(midiPitches); | |
9 numFreqsCQT = length(binFreqsCQT); | |
10 | |
11 pitchF0s = midiPitch2Freq(midiPitches, tuningFreqInHz); | |
12 outOfBoundsPitches = (pitchF0s < binFreqsCQT(1) | pitchF0s > binFreqsCQT(end)); | |
13 if any(outOfBoundsPitches) | |
14 warning('F0s of some midi pitches lie outside the constant-Q spectrogram frequency range'); | |
15 end | |
16 | |
17 freqRatios = repmat(binFreqsCQT, 1, numMidiPitches) ./ repmat(pitchF0s', numFreqsCQT, 1); | |
18 freqRatios(freqRatios < 1) = 1 ./ freqRatios(freqRatios < 1); | |
19 | |
20 [dummy shifts] = min(abs(freqRatios), [], 1); | |
21 shifts = shifts - 1; % 'no shift' is defined as 0 | |
22 shifts(outOfBoundsPitches) = -1; | |
23 shifts = shifts'; |