I'm trying to get the amplitudes and phases of a (falling) saw-tooth signal. My saw-tooth is 1024 samples long and generated as
int numSamples = 1024;
for (int i = 0; i < numSamples; i++)
{
samples[i] = -((float)i / (float)(numSamples - 1) * 2.0f - 1.0f);
}
I setup the real and imaginary arrays as
for (int i = 0; i < numSamples; i++)
{
double sample = samples[i];
re[i] = sample;
im[i] = 0.0;
}
then passing it into the FFT function. I readout the result as
int numPartials = numSamples / 2;
for (int i = 1; i < numPartials; i++)
{
outMagnitudes[i] = (float)sqrt(re[i] * re[i] + im[i] * im[i]);
outPhases[i] = (float)atan2(im[i], re[i]);
}
2 problems occur:
- the magnitudes are only half as large as they should be
- the phases range linearly from -PI/2 for the first partial to zero for the last one where I'd expect them all to be zero for the given signal
I really don't get what I do wrong here.
Does anyone have an idea ?