Hey guys. So my goal is to:
- load a single cycle wave
- run an FFT to deconstruct the wave into arrays of level and phase
- manipulate those levels and phases in normalized space
- then recreate a waveform
Thanks to your help, I have most of this working.
const int fftOrder = 11;
const int numBins = 1 << fftOrder; // 2048
const int waveSize = numBins; // just for clarity
const int fftBufferSize = waveSize * 2;
float fftBuffer[fftBufferSize];
float levels[numBins];
float phases[numBins];
auto fft = new dsp::FFT(fftOrder);
bufferClear(fftBuffer, fftBufferSize);
loadWaveIntoBuffer();
fft->performRealOnlyForwardTransform(fftBuffer, true);
// zero out the DC and Nyquist bins
fftBuffer[0] = 0.0f;
fftBuffer[fftBufferSize - 1] = 0.0f;
// convert the complex buffer into floats and find the max value
auto* realBuffer = reinterpret_cast<std::complex<float>*> (fftBuffer);
float maxValue = -1.f;
for(int i = 1; i < numBins; ++i)
{
float mag = std::abs(realBuffer[i]);
float phase = std::arg(realBuffer[i]);
maxValue = jmax(mag, maxValue);
levels[i] = mag;
phases[i] = phase;
}
// normalize levels
for(int i = 0; i < numBins; ++i)
{
levels[i] /= maxValue;
// anything required to normalize phase values?
}
// edit levels and phases using normalized values......................
// reconstruct complex number from levels and phases and put back into fftBuffer
??????
// run fft to create new waveform
fft->performRealOnlyInverseTransform(fftBuffer);
So, given that, my three questions are:
- Do I need to do anything to the phase values to normalize them after getting them from
std::arg(realBuffer[i]);
? - How do I reconstruct complex numbers from the normalized levels and phases?
- Did I miss anything?
Thanks again, gents.