DSPRelated.com
Forums

Verifying FFT Result

Started by B S June 29, 2010
Hi Guys,

I have computed FFT of 1 KHz sine wave with 1 Vp_p using C6713 DSK, to be sure that FFT algorithm is working fine, I want to verify my result. Can you please tell me how can I do this.

Sampling frequency used is 8KHz and no. of FFT points are 256.

Waiting for your quick response.

BR,
BS
B.S.

A spectrum analyzer (CCS can do the job) to run on the PC that will display a
frequency spectrum is needed.
The results of the FFT can be output to the PC via the USB connection to feed
the spectrum analyzer.

IN CCS select:
View, Graph, Time/Frequency
then set appropriate parameters using the Graphical Display Dialog.
the result is displayed using the Graphical Display window.

R. Williams

---------- Original Message -----------
From: B S
To: c...
Sent: Tue, 29 Jun 2010 04:54:54 -0700 (PDT)
Subject: [c6x] Verifying FFT Result

> Hi Guys,
>
> I have computed FFT of 1 KHz sine wave with 1 Vp_p using C6713 DSK, to
> be sure that FFT algorithm is working fine, I want to verify my
> result. Can you please tell me how can I do this.
>
> Sampling frequency used is 8KHz and no. of FFT points are 256.
>
> Waiting for your quick response.
>
> BR,
> BS
------- End of Original Message -------

_____________________________________
BS-

> I have computed FFT of 1 KHz sine wave with 1 Vp_p using C6713 DSK,
> to be sure that FFT algorithm is working fine, I
> want to verify my result. Can you please tell me how can I do this.
>
> Sampling frequency used is 8KHz and no. of FFT points are 256.

If you're using no window (i.e. "rectangular window) and no zero-fill and you have no pre- or post-FFT scaling, then
you can:

-calculate magnitude

-check bin 32 (1/8 of FFT size)

it should be approx 128*V, where V is the the value you read from the AIC23 codec when you audio signal is 1 V.

In other words, since you have a pure sine wave, FFT multiplies and adds should contribute to a sum at only one bin;
i.e. your signal is a match to one of the sine waves the FFT throws at it. Of course nothing in a real system is that
perfect, which is why I say your amplitude value should be "approx".

-Jeff

_____________________________________
B S,

Why don't you plot your output array using View-->Graph in CCS and check
you're getting the peak at 1 KHz.

Regards,

On Tue, Jun 29, 2010 at 4:54 AM, B S wrote:

> Hi Guys,
>
> I have computed FFT of 1 KHz sine wave with 1 Vp_p using C6713 DSK, to be
> sure that FFT algorithm is working fine, I want to verify my result. Can you
> please tell me how can I do this.
>
> Sampling frequency used is 8KHz and no. of FFT points are 256.
>
> Waiting for your quick response.
>
> BR,
> BS
>
>
>

--
Varun
R. Williams and Jeff,

I used Oscilloscope to see the frequency response, I am getting very strange type of graph or perhaps I am not understanding the way it is showing on Oscilloscope. Here is the code which I used for calculaing FFT.

#include "dsk6713_aic23.h"
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;
#include
#define PTS 256 //# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer
float x1[PTS]; //intermediate buffer
short i; //general purpose index variable
short buffercount = 0; //number of new samples in iobuffer
short flag = 0; //set to 1 by ISR when iobuffer full
COMPLEX w[PTS]; //twiddle constants stored in w
COMPLEX samples[PTS]; //primary working buffer

main()
{
for (i = 0 ; i {
w[i].real = cos(2*PI*i/512.0); //Re component of twiddle constants
w[i].imag =-sin(2*PI*i/512.0); //Im component of twiddle constants
}
comm_intr(); //init DSK, codec, McBSP

while(1) //infinite loop
{
while (flag == 0) ; //wait until iobuffer is full
flag = 0; //reset flag
for (i = 0 ; i < PTS ; i++) //swap buffers
{
samples[i].real=iobuffer[i]; //buffer with new data
iobuffer[i] = x1[i]; //processed frame to iobuffer
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0

FFT(samples,PTS); //call function FFT.c

for (i = 0 ; i < PTS ; i++) //compute magnitude
{
x1[i] = sqrt(samples[i].real*samples[i].real
+ samples[i].imag*samples[i].imag)/16;
}
x1[0] = 32000.0; //negative spike for reference
} //end of infinite loop
} //end of main

interrupt void c_int11() //ISR
{
output_sample((short)(iobuffer[buffercount])); //out from iobuffer
iobuffer[buffercount++]=(float)((short)input_sample()); //input to iobuffer
if (buffercount >= PTS) //if iobuffer full
{
buffercount = 0; //reinit buffercount
flag = 1; //set flag
}
}
The two negative spikes are 256(Ts) = 32ms apart, as shown in Figure 6.14. This interval also represents the sampling frequency Fs. The location of the first positive spike then corresponds to a frequency of 2kHz (the mid-distance between the two spikes corresponds to 4 kHz).The location of the second positive spike corresponds to the folding frequency of Fs - f = 6kHz. Increase the frequency of the input signal and observe the convergence of the two spikes toward the 4-kHz Nyquist frequency.

@ Jeff,

I couldn't grab much what you tried to explain

-check bin 32 (1/8 of FFT size)

it should be approx 128*V, where V is the the value you read from the
AIC23 codec when you audio signalis 1 V.

I had a look over 32rd sample and that seems to be the biggest value in the vector. Can you please elaborate more.

Please find attached plot obtained by oscilloscope and CCS.

For oscilloscope plot, X-axis contains 10 division with value of 5ms/Div and for Y-axis, its 500mV/Div.

Waiting for your kind help.

BR,
BS

________________________________
From: Richard Williams
To: B S ; c...
Sent: Tue, June 29, 2010 7:55:00 PM
Subject: Re: [c6x] Verifying FFT Result

B.S.

A spectrum analyzer (CCS can do the job) to run on the PC that will display a
frequency spectrum is needed.
The results of the FFT can be output to the PC via the USB connection to feed
the spectrum analyzer.

IN CCS select:
View, Graph, Time/Frequency
then set appropriate parameters using the Graphical Display Dialog.
the result is displayed using the Graphical Display window.

R. Williams

---------- Original Message -----------
From: B S
To: c...
Sent: Tue, 29 Jun 2010 04:54:54 -0700 (PDT)
Subject: [c6x] Verifying FFT Result

> Hi Guys,
>
> I have computed FFT of 1 KHz sine wave with 1 Vp_p using C6713 DSK, to
> be sure that FFT algorithm is working fine, I want to verify my
> result. Can you please tell me how can I do this.
>
> Sampling frequency used is 8KHz and no. of FFT points are 256.
>
> Waiting for your quick response.
>
> BR,
> BS
------- End of Original Message -------
because a plot is not precise enough, you can have an error in one butterfly you wouldn't see it.best choice, insert random noise and compare your result with Matlab.

To: m...@yahoo.com
CC: c...
From: v...@gmail.com
Date: Tue, 29 Jun 2010 09:51:25 -0700
Subject: Re: [c6x] Verifying FFT Result

B S,
Why don't you plot your output array using View-->Graph in CCS and check you're getting the peak at 1 KHz.
Regards,

On Tue, Jun 29, 2010 at 4:54 AM, B S wrote:

Hi Guys,

I have computed FFT of 1 KHz sine wave with 1 Vp_p using C6713 DSK, to be sure that FFT algorithm is working fine, I want to verify my result. Can you please tell me how can I do this.

Sampling frequency used is 8KHz and no. of FFT points are 256.

Waiting for your quick response.

BR,
BS

--
Varun
Varoonian,

I did try but there is no peak at 1 KHz, I used FFT magnitude option to plot the result.

There is one confusion about choosing FFT magnitude option for viewing graph. I used FFT magnitude option when I was sampling real time Sine Wave and that option was showing me peak at 1 KHz without using any FFT algorithm. In my understadning FFT magnitude option in graph is calculating FFT again, therefore, peak is not present at 1Khz.

I am attaching a plot obtained by Code Composer Studio graph option.

Waiting for your comments.

________________________________
From: varoonian .
To: B S
Cc: c...
Sent: Tue, June 29, 2010 7:51:25 PM
Subject: Re: [c6x] Verifying FFT Result

B S,

Why don't you plot your output array using View-->Graph in CCS and check you're getting the peak at 1 KHz.

Regards,
On Tue, Jun 29, 2010 at 4:54 AM, B S wrote:

>
> >>>
>
>Hi Guys,
>
>I have computed FFT of 1 KHz sine wave with 1 Vp_p using C6713 DSK, to be sure that FFT algorithm is working fine, I want to verify my result. Can you please tell me how can I do this.
>
>Sampling frequency used is 8KHz and no. of FFT points are 256.
>
>Waiting for your quick response.
>
>BR,
>BS
--
Varun
B S,

I don't quite understand you.

Did you include the starting address, Sampling Frequency, Window Type and
Buffer Size in the graph Properties Dialog Box as per your requirements ?

Regards,

On Wed, Jun 30, 2010 at 4:06 AM, B S wrote:

>
> [Attachment(s) <#12988e1ca4f7952c_TopText> from B S included below]
>
> Varoonian,
>
> I did try but there is no peak at 1 KHz, I used FFT magnitude option to
> plot the result.
>
> There is one confusion about choosing FFT magnitude option for viewing
> graph. I used FFT magnitude option when I was sampling real time Sine Wave
> and that option was showing me peak at 1 KHz without using any FFT
> algorithm. In my understadning FFT magnitude option in graph is calculating
> FFT again, therefore, peak is not present at 1Khz.
>
> I am attaching a plot obtained by Code Composer Studio graph option.
>
> Waiting for your comments.
>
> ------------------------------
> *From:* varoonian .
> *To:* B S
> *Cc:* c...
> *Sent:* Tue, June 29, 2010 7:51:25 PM
> *Subject:* Re: [c6x] Verifying FFT Result
>
> B S,
>
> Why don't you plot your output array using View-->Graph in CCS and check
> you're getting the peak at 1 KHz.
>
> Regards,
>
> On Tue, Jun 29, 2010 at 4:54 AM, B S
> > wrote:
>
>> Hi Guys,
>>
>> I have computed FFT of 1 KHz sine wave with 1 Vp_p using C6713 DSK, to be
>> sure that FFT algorithm is working fine, I want to verify my result. Can you
>> please tell me how can I do this.
>>
>> Sampling frequency used is 8KHz and no. of FFT points are 256.
>>
>> Waiting for your quick response.
>>
>> BR,
>> BS
> --
> Varun
>
>
>

--
Varun
Hi Varoonian,

Here you can see the parameters I included.

Display Type: Single Time
Start Address: x1 (contain FFT magnitude)
Acquisition Buffer Size: 256 as of FFT Points
Display Data Size: 256
DSP Data Type: 32-bit Floating Point- I am not quite sure which one to choose here, I chosen this option because the variable x1 that contain FFT magnitude is floating point.
Sampling Rate: 8000

In the last email, plot has been obtained using FFT Magnitude option but this time its Single Time and I am getting peaks but not at 1KHz. You can see the attached plot. I am also copying piece of code which I used.

#include "dsk6713_aic23.h"
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;
#include
#define PTS 256 //# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer
float x1[PTS]; //intermediate buffer
short i; //general purpose index variable
short buffercount = 0; //number of new samples in iobuffer
short flag = 0; //set to 1 by ISR when iobuffer full
COMPLEX w[PTS]; //twiddle constants stored in w
COMPLEX samples[PTS]; //primary working buffer

main()
{
for (i = 0 ; i {
w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants
w[i].imag =-sin(2*PI*i/(PTS*2.0)); //Im component of twiddle constants
}
comm_intr(); //init DSK, codec, McBSP

while(1) //infinite loop
{
while (flag == 0) ; //wait until iobuffer is full
flag = 0; //reset flag
for (i = 0 ; i < PTS ; i++) //swap buffers
{
samples[i].real=iobuffer[i]; //buffer with new data
iobuffer[i] = x1[i]; //processed frame to iobuffer
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0

FFT(samples,PTS); //call function FFT.c

for (i = 0 ; i < PTS ; i++) //compute magnitude
{
x1[i] = sqrt(samples[i].real*samples[i].real // x1 contains the magnitude (scaled) of the transformed (processed) data
+ samples[i].imag*samples[i].imag);
}
x1[0] = 32000.0; //negative spike for reference
} //end of infinite loop
} //end of main

interrupt void c_int11() //ISR
{
output_sample((short)(iobuffer[buffercount])); //out from iobuffer
iobuffer[buffercount++]=(float)((short)input_sample()); //input to iobuffer
if (buffercount >= PTS) //if iobuffer full
{
buffercount = 0; //reinit buffercount
flag = 1; //set flag
}
}

Waiting for your response.

BR,
BS

________________________________
From: varoonian .
To: B S
Cc: c...
Sent: Thu, July 1, 2010 1:41:02 AM
Subject: Re: [c6x] Verifying FFT Result

B S,

I don't quite understand you.

Did you include the starting address, Sampling Frequency, Window Type and Buffer Size in the graph Properties Dialog Box as per your requirements ?

Regards,
On Wed, Jun 30, 2010 at 4:06 AM, B S wrote:

>
> >>>
> [Attachment(s) from B S included below] >
>
>Varoonian,
>
>I did try but there is no peak at 1 KHz, I used FFT magnitude option to plot the result.
>
>There is one confusion about choosing FFT magnitude option for viewing graph. I used FFT magnitude option when I was sampling real time Sine Wave and that option was showing me peak at 1 KHz without using any FFT algorithm. In my understadning FFT magnitude option in graph is calculating FFT again, therefore, peak is not present at 1Khz.
>
>I am attaching a plot obtained by Code Composer Studio graph option.
>
>Waiting for your comments.
>
>>
________________________________
From: varoonian .
>To: B S
>Cc: c6x@yahoogroups. com
>Sent: Tue, June 29, 2010 7:51:25 PM
>Subject: Re: [c6x] Verifying FFT Result
>
> >
>>
>
>B S,
>Why don't you plot your output array using View-->Graph in CCS and check you're getting the peak at 1 KHz.
>Regards,
>>
>On Tue, Jun 29, 2010 at 4:54 AM, B S wrote:
>
>>>
>> >>>>>>
>>
>>Hi Guys,
>>
>>I have computed FFT of 1 KHz sine wave with 1 Vp_p using C6713 DSK, to be sure that FFT algorithm is working fine, I want to verify my result. Can you please tell me how can I do this.
>>
>>Sampling frequency used is 8KHz and no. of FFT points are 256.
>>
>>Waiting for your quick response.
>>
>>BR,
>>BS
>--
>Varun
--
Varun
Hi All,

I plotted the result of FFT Magnitude using graph option in CCS, for 1KHz signal peak appears at 32nd and 224th samples respectively and the magnitudes are 7e5 for both peaks :D

How can I calculate the exact amplitude and map it to 1 KHz frequency as of real time signal ?

Please help.

Thanks.
-BS
________________________________
From: varoonian .
To: B S
Cc: c...
Sent: Thu, July 1, 2010 1:41:02 AM
Subject: Re: [c6x] Verifying FFT Result [1 Attachment]

B S,

I don't quite understand you.

Did you include the starting address, Sampling Frequency, Window Type and Buffer Size in the graph Properties Dialog Box as per your requirements ?

Regards,
On Wed, Jun 30, 2010 at 4:06 AM, B S wrote:

>
> >>>
>
>[Attachment(s) from B S included below]
>Varoonian,
>
>I did try but there is no peak at 1 KHz, I used FFT magnitude option to plot the result.
>
>There is one confusion about choosing FFT magnitude option for viewing graph. I used FFT magnitude option when I was sampling real time Sine Wave and that option was showing me peak at 1 KHz without using any FFT algorithm. In my understadning FFT magnitude option in graph is calculating FFT again, therefore, peak is not present at 1Khz.
>
>I am attaching a plot obtained by Code Composer Studio graph option.
>
>Waiting for your comments.
>
>>
________________________________
From: varoonian .
>To: B S
>Cc: c...
>Sent: Tue, June 29, 2010 7:51:25 PM
>Subject: Re: [c6x] Verifying FFT Result
>
> >
>>
>
>B S,
>Why don't you plot your output array using View-->Graph in CCS and check you're getting the peak at 1 KHz.
>Regards,
>>
>On Tue, Jun 29, 2010 at 4:54 AM, B S wrote:
>
>>>
>> >>>>>>
>>
>>Hi Guys,
>>
>>I have computed FFT of 1 KHz sine wave with 1 Vp_p using C6713 DSK, to be sure that FFT algorithm is working fine, I want to verify my result. Can you please tell me how can I do this.
>>
>>Sampling frequency used is 8KHz and no. of FFT points are 256.
>>
>>Waiting for your quick response.
>>
>>BR,
>>BS
>--
>Varun
>
--
Varun