C++ (Qt) // Calculate the FFT m_fft->calculateFFT(m_output.data(), m_input.data()); // Analyze output to obtain amplitude and phase for each frequency for (int i=2; i<=m_numSamples/2; ++i) { // Calculate frequency of this complex sample m_spectrum[i].frequency = qreal(i * inputFrequency) / (m_numSamples); const qreal real = m_output[i]; qreal imag = 0.0; if (i>0 && i<m_numSamples/2) imag = m_output[m_numSamples/2 + i]; const qreal magnitude = sqrt(real*real + imag*imag); qreal amplitude = SpectrumAnalyserMultiplier * log(magnitude); // Bound amplitude to [0.0, 1.0] m_spectrum[i].clipped = (amplitude > 1.0); amplitude = qMax(qreal(0.0), amplitude); amplitude = qMin(qreal(1.0), amplitude); m_spectrum[i].amplitude = amplitude; }
C++ (Qt)// Получение частотыm_spectrum[i].frequency = qreal(i * inputFrequency) / (m_numSamples);// Получение магнитуды для этой частотыconst qreal magnitude = sqrt(real*real + imag*imag);// Получение амплитуды для этой частотыqreal amplitude = SpectrumAnalyserMultiplier * log(magnitude);