Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
FFTAnalyzer Class Reference

Module performing the final analysis of the Fourier transform. More...

#include <fftanalyzer.h>

+ Collaboration diagram for FFTAnalyzer:

Public Types

using SpectrumType = Key::SpectrumType
 Type of a log spectrum. More...
 
using PeakListType = Key::PeakListType
 Type for a peak map. More...
 

Public Member Functions

 FFTAnalyzer ()
 Constructor. More...
 
 ~FFTAnalyzer ()
 Empty destructor. More...
 
std::pair
< FFTAnalyzerErrorTypes,
std::shared_ptr< Key > > 
analyse (const Piano *piano, FFTDataPointer finalFFT, int finalKey)
 Main analyzing function. More...
 
FrequencyDetectionResult detectFrequencyOfKnownKey (FFTDataPointer finalFFT, const Piano *piano, const Key &key, int keyIndex)
 FFTAnalyzer::detectFrequencyOfKnownKey. More...
 

Private Member Functions

void constructLogBinnedSpectrum (FFTDataPointer fftData, SpectrumType &spectrum)
 Construct logarithmically binned spectrum from the mFinalFFT. More...
 
SpectrumType constructKernel (const SpectrumType &originalSpectrum)
 
TuningDeviationCurveType computeTuningDeviation (const SpectrumType &kernel, const SpectrumType &signal, int searchSize)
 
int locatePeak (const SpectrumType &spectrum, int m, int width)
 
double interpolatePeakPosition (const SpectrumType &spectrum, int m, int width)
 
int findNearestKey (double f, double conertPitch, int numberOfKeys, int keyNumberOfA)
 Compute the number of the nearest key. More...
 
double estimateFrequency (int keynumber, double concertPitch, int keyNumberOfA)
 Estimate the frequency for a given keynumber. More...
 
double findAccuratePeakFrequency (FFTDataPointer fftData, double f, int cents=5)
 Find the accurate frequency of a spectral peak in the original FFT. More...
 
double getExpectedInharmonicity (double f)
 
double estimateInharmonicity (FFTDataPointer fftData, SpectrumType &spectrum, double f)
 Estimate the inharmonicity B. More...
 
double estimateQuality ()
 
double estimateFrequencyShift ()
 
PeakListType identifyPeaks (FFTDataPointer fftData, const SpectrumType &spectrum, const double f, const double B)
 
void Write (std::string filename, SpectrumType &v)
 
void Write (std::string filename, FFTComplexVector &v)
 
void WritePeaks (std::string filename, SpectrumType &v, PeakListType &peaks)
 

Private Attributes

const int NumberOfBins =Key::NumberOfBins
 
SpectrumType mOptimalSuperposition
 Superposition of the partials. More...
 
FFT_Implementation mFFT
 Instance of FFT implementation. More...
 
SpectrumType mCurrentKernel
 The current kernel for the key detection. More...
 
const KeymCurrentKernelKey
 The key of which mCurrentKernel belongs to. More...
 

Detailed Description

Module performing the final analysis of the Fourier transform.

After completion of the recording process, the SignalAnalyzer sends the final Fourier transform via MessageNewFFTCalculated with a 'ture' flag to the FFT analyzer.

Definition at line 43 of file fftanalyzer.h.

Member Typedef Documentation

Type for a peak map.

Definition at line 48 of file fftanalyzer.h.

Type of a log spectrum.

Definition at line 47 of file fftanalyzer.h.

Constructor & Destructor Documentation

FFTAnalyzer::FFTAnalyzer ( )

Constructor.

Definition at line 41 of file fftanalyzer.cpp.

FFTAnalyzer::~FFTAnalyzer ( )
inline

Empty destructor.

Definition at line 51 of file fftanalyzer.h.

Member Function Documentation

std::pair< FFTAnalyzerErrorTypes, std::shared_ptr< Key > > FFTAnalyzer::analyse ( const Piano piano,
FFTDataPointer  finalFFT,
int  finalKey 
)

Main analyzing function.

Parameters
pianoPointer to the piano
finalFFTData of the final fourier transformation
samplingrate the sampling rate
finalKeythe identified key
Returns
Shared pointer of the detected key and idendified data

This function controls the main tasks of the FFTAnalyzer and is used by the SignalAnalyzer to analyze the final fft.

Definition at line 62 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

TuningDeviationCurveType FFTAnalyzer::computeTuningDeviation ( const SpectrumType kernel,
const SpectrumType signal,
int  searchSize 
)
private

Definition at line 312 of file fftanalyzer.cpp.

FFTAnalyzer::SpectrumType FFTAnalyzer::constructKernel ( const SpectrumType originalSpectrum)
private

Definition at line 300 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

void FFTAnalyzer::constructLogBinnedSpectrum ( FFTDataPointer  fftData,
SpectrumType spectrum 
)
private

Construct logarithmically binned spectrum from the mFinalFFT.

The FFT analysis yields a Fourier transform with an index which is linear in the frequency. For the tuning process, however, we need a spectrum which is logarithmic in the frequency. Only then it is possible to tune the key by simply shifting the index of the spectrum. This function transforms the incoming FFT into a logarithmically binned spectrum. The dimension NumberOfBins is copied from the constant in class Key. The actual map between the indices can be found in Key::IndexToFrequency.

Parameters
fftDataData of the fourier transform
spectrumVector holding the logarithmically binned spectrum.

Definition at line 291 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

FrequencyDetectionResult FFTAnalyzer::detectFrequencyOfKnownKey ( FFTDataPointer  finalFFT,
const Piano piano,
const Key key,
int  keyIndex 
)

FFTAnalyzer::detectFrequencyOfKnownKey.

Parameters
finalFFT
piano
key
keyIndex
Returns

Definition at line 167 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

double FFTAnalyzer::estimateFrequency ( int  keynumber,
double  concertPitch,
int  keyNumberOfA 
)
private

Estimate the frequency for a given keynumber.

This function uses a heuristic average tuning curve to roughly estimate the frequency of a given key. This function can be seen as an inverse of findNearestKey.

Parameters
keynumber: Number of the key
Returns
Frequency in Hz with respect to the actual mConcertPitch.

Definition at line 420 of file fftanalyzer.cpp.

double FFTAnalyzer::estimateFrequencyShift ( )
private

Definition at line 616 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

double FFTAnalyzer::estimateInharmonicity ( FFTDataPointer  fftData,
SpectrumType spectrum,
double  f 
)
private

Estimate the inharmonicity B.

This function estimates the inharmonicity coefficient B on the basis of the recorded data. This estimate serves as a quality and consistency check.

The function uses the frequency estimate that has been obtained before by determineFrequency. The frequency and inhamronicity is then optimized iteratively. This is achieved by minimizing the Renyi entropy of the collapsed peak according to the known inharmonicity formula.

Parameters
spectrum: Logarithmically binned spectrum
f: Previous frequency estimate
Returns
Estimated inharmonicity coefficient B (dimensionless).

Definition at line 510 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

double FFTAnalyzer::estimateQuality ( )
private

Definition at line 592 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

double FFTAnalyzer::findAccuratePeakFrequency ( FFTDataPointer  fftData,
double  f,
int  cents = 5 
)
private

Find the accurate frequency of a spectral peak in the original FFT.

The logarithmically binned spectrum has a resolution of one cent. However, the spectral peaks are not always mapped faithfully but their location may be slightly different (due to the integration involved in the mapping). To eliminate this uncertainty, the present function looks for the maximum of the spectral line in the original FFT and returns its frequency.

Parameters
f: Estimate of the frequency where the peak is supposed to be.
cents: Width of the search window around f in cents.
Returns
: Frequency in Hz.

Definition at line 449 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

int FFTAnalyzer::findNearestKey ( double  f,
double  conertPitch,
int  numberOfKeys,
int  keyNumberOfA 
)
private

Compute the number of the nearest key.

This function uses a heuristic average tuning curve to estimate the most likely number of the key for a given frequency.

Parameters
f: Frequency in Hz.
Returns
Key number.

Definition at line 394 of file fftanalyzer.cpp.

double FFTAnalyzer::getExpectedInharmonicity ( double  f)
private

This function provides a very rough estimate of the expected inharmonicity coefficient of an average upright. It is used improve the expectation where the spectral lines should be located in the spectrum during key recognition.

Parameters
f: frequency in Hz
Returns
Inharmonicity coefficient B

Definition at line 484 of file fftanalyzer.cpp.

FFTAnalyzer::PeakListType FFTAnalyzer::identifyPeaks ( FFTDataPointer  fftData,
const SpectrumType spectrum,
const double  f,
const double  B 
)
private

Definition at line 632 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

double FFTAnalyzer::interpolatePeakPosition ( const SpectrumType spectrum,
int  m,
int  width 
)
private

Search for a local peak in the logarithmically binned spectrum. Optimize the index as a floating-point value

Parameters
spectrum: Logarithmically binned spectrum
m: Spectral index
width: Searching width in +/- cents
Returns
Index where the maximum is located

Definition at line 363 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

int FFTAnalyzer::locatePeak ( const SpectrumType spectrum,
int  m,
int  width 
)
private

Search for a local peak in the logarithmically binned spectrum

Parameters
spectrum: Logarithmically binned spectrum
m: Spectral index
width: Searching width in +/- cents
Returns
Integer index where the maximum is lodated

Definition at line 341 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

void FFTAnalyzer::Write ( std::string  filename,
SpectrumType v 
)
private

Definition at line 659 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

void FFTAnalyzer::Write ( std::string  filename,
FFTComplexVector v 
)
private

Definition at line 676 of file fftanalyzer.cpp.

void FFTAnalyzer::WritePeaks ( std::string  filename,
SpectrumType v,
PeakListType peaks 
)
private

Definition at line 697 of file fftanalyzer.cpp.

+ Here is the call graph for this function:

Member Data Documentation

SpectrumType FFTAnalyzer::mCurrentKernel
private

The current kernel for the key detection.

Definition at line 70 of file fftanalyzer.h.

const Key* FFTAnalyzer::mCurrentKernelKey
private

The key of which mCurrentKernel belongs to.

Definition at line 71 of file fftanalyzer.h.

FFT_Implementation FFTAnalyzer::mFFT
private

Instance of FFT implementation.

Definition at line 69 of file fftanalyzer.h.

SpectrumType FFTAnalyzer::mOptimalSuperposition
private

Superposition of the partials.

Definition at line 68 of file fftanalyzer.h.

const int FFTAnalyzer::NumberOfBins =Key::NumberOfBins
private

Definition at line 66 of file fftanalyzer.h.


The documentation for this class was generated from the following files: