MCPcopy Create free account
hub / github.com/adamstark/BTrack / complexSpectralDifferenceHWR

Method complexSpectralDifferenceHWR

src/OnsetDetectionFunction.cpp:520–564  ·  view source on GitHub ↗

=======================================================================

Source from the content-addressed store, hash-verified

518
519//=======================================================================
520double OnsetDetectionFunction::complexSpectralDifferenceHWR()
521{
522 double phaseDeviation;
523 double sum;
524 double magnitudeDifference;
525 double csd;
526
527 // perform the FFT
528 performFFT();
529
530 sum = 0; // initialise sum to zero
531
532 // compute phase values from fft output and sum deviations
533 for (int i = 0; i < frameSize; i++)
534 {
535 // calculate phase value
536 phase[i] = atan2 (complexOut[i][1], complexOut[i][0]);
537
538 // calculate magnitude value
539 magSpec[i] = sqrt (pow (complexOut[i][0],2) + pow(complexOut[i][1],2));
540
541 // phase deviation
542 phaseDeviation = phase[i] - (2 * prevPhase[i]) + prevPhase2[i];
543
544 // calculate magnitude difference (real part of Euclidean distance between complex frames)
545 magnitudeDifference = magSpec[i] - prevMagSpec[i];
546
547 // if we have a positive change in magnitude, then include in sum, otherwise ignore (half-wave rectification)
548 if (magnitudeDifference > 0)
549 {
550 // calculate complex spectral difference for the current spectral bin
551 csd = sqrt (pow (magSpec[i], 2) + pow (prevMagSpec[i], 2) - 2 * magSpec[i] * prevMagSpec[i] * cos (phaseDeviation));
552
553 // add to sum
554 sum = sum + csd;
555 }
556
557 // store values for next calculation
558 prevPhase2[i] = prevPhase[i];
559 prevPhase[i] = phase[i];
560 prevMagSpec[i] = magSpec[i];
561 }
562
563 return sum;
564}
565
566
567//=======================================================================

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected