signbit
September 21st, 2004, 06:01 AM
Hello,
I am working on an assignment that:
1. take an array of values.
2. Transform it using FFT
and
3. Regenerate the signal, described by the sample values, in a graphical form (i.e. image of a wave or something like that, that's to be displayed on the monitor...)
I am using the following formulas:
Frequency = k * sampleRate / N; // in my case, sampleRate/N will always be 1, so Frequency is 'k'
Amplitude = sqrt(Re(k)*Re(k) + Im(k) * Im(k)) / sqrt(N)
Phase = 180 *atan2(Im(k), Re(bin)) / M_PI - 90;
(The formula for 'Phase' is taken from an article and I don't really know why do we have to use a formula like that for phase...).
Can I use the following code to get the regenrated signal...
// code inside 'Regenrate' function
for(int i=0; i < N; i++)
{
for(int angle = 0; angle < 360; angle++)
{
aRegeneratedSignal[i] = Amplitude[i] * sin( ( Phase[i] + angle ) / 57.3); // A * sin(theeta + phase)
}
}
// Display the signal (inside the 'onDraw' function)
for(int i=0; i < 360; i++)
{
pDC->SetPixel(i, RegeneratedSignal[i], RGB(0, 0, 0));
}
When I use the above code, no matter what the original values were, a Sine Wave is printed on the screen (Amplitude and Phase may differ, but they are always sine waves...).
Some people say: "You cannot vary the angle from 0 to 360 like you are doing right now (in the for loop inside Regenrate function), instead you'll have to take into the account the 'frequency' of the each signal component...", If that's true, could you please give me an example of what the code might look like...
Any help will be much appreciated...
Links to similar projects and articals will be a great favor...
Bye,
I am working on an assignment that:
1. take an array of values.
2. Transform it using FFT
and
3. Regenerate the signal, described by the sample values, in a graphical form (i.e. image of a wave or something like that, that's to be displayed on the monitor...)
I am using the following formulas:
Frequency = k * sampleRate / N; // in my case, sampleRate/N will always be 1, so Frequency is 'k'
Amplitude = sqrt(Re(k)*Re(k) + Im(k) * Im(k)) / sqrt(N)
Phase = 180 *atan2(Im(k), Re(bin)) / M_PI - 90;
(The formula for 'Phase' is taken from an article and I don't really know why do we have to use a formula like that for phase...).
Can I use the following code to get the regenrated signal...
// code inside 'Regenrate' function
for(int i=0; i < N; i++)
{
for(int angle = 0; angle < 360; angle++)
{
aRegeneratedSignal[i] = Amplitude[i] * sin( ( Phase[i] + angle ) / 57.3); // A * sin(theeta + phase)
}
}
// Display the signal (inside the 'onDraw' function)
for(int i=0; i < 360; i++)
{
pDC->SetPixel(i, RegeneratedSignal[i], RGB(0, 0, 0));
}
When I use the above code, no matter what the original values were, a Sine Wave is printed on the screen (Amplitude and Phase may differ, but they are always sine waves...).
Some people say: "You cannot vary the angle from 0 to 360 like you are doing right now (in the for loop inside Regenrate function), instead you'll have to take into the account the 'frequency' of the each signal component...", If that's true, could you please give me an example of what the code might look like...
Any help will be much appreciated...
Links to similar projects and articals will be a great favor...
Bye,