FFT build with DSP
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
FFT build with DSP

 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP
Author Message
Eugene
Guest





Posted: Mon Dec 20, 2004 1:15 pm    Post subject: FFT build with DSP Reply with quote

Hi,

hier is my quelltext,
Can anybody say me, what is in my program false.
I want to produce a sine or rectangle inputsignal, and build fft
spectrum from it.
then I take a absolut value from the result and display it in ccs
"single-time"

if the input is sine then I haven't only one peak (or two, if it's
symmetrical) and if I have rectangle input, then I haven't a harmonic
waves in my spectrum.
I thank you in advance

///////////////////////////////////
#include <math.h>
#include <tms320.h>
#include <dsplib.h>
#include <stdio.h>
#define NX 128
#define SINE_MAX 0x7FFE
#define SINE_TABLE_SIZE 256
#define PI ((double)3.1415927)
short scale = 1;
short x1[2*NX];
int sinetable[SINE_TABLE_SIZE];
DATA prueftest[SINE_TABLE_SIZE];
DATA prueftest1[SINE_TABLE_SIZE];
DATA prueftest2[SINE_TABLE_SIZE];
DATA prueftest3[SINE_TABLE_SIZE];
void InitSineTable(void)
{
int counter1=0;
int signal_Wert=1;
int i=30;
double increment= 0;
double radian = 0;

/*Hier will produce a rectangle input*/
while(i||counter1!=255)
{
i--;
if(i==0)
{
i=30;
if(signal_Wert)
signal_Wert=0;

else
signal_Wert=1;
}
sinetable[counter1]=signal_Wert;
counter1++;
if(counter1==256)
break;
}
/*Hier WILL BE PRODUCE a sine input
increment = (PI * 2) / SINE_TABLE_SIZE;
for (i = 0; i < SINE_TABLE_SIZE; i++)
{
sinetable[i] = (int)(sin(radian) * SINE_MAX);
radian += increment;
}*/
for (i=0;i<SINE_TABLE_SIZE;i++)
prueftest[i]=sinetable[i];
}void main()
{int NumUniquePts=0;
int i=0,j=0;
int counter1=0;
float temp1=0.0;
float temp2=0.0;
float temp3=0.0;
float temp4=0.0;
for(i=0;i<SINE_TABLE_SIZE;i++)
{
sinetable[i]=0;
prueftest[i]=0;
prueftest1[i]=0;
prueftest2[i]=0;
prueftest3[i]=0.0;

}
// Initialize the Inputsignal
InitSineTable();
NumUniquePts=(int)((NX+1)/2);
for(i=0;i<SINE_TABLE_SIZE;i++)
prueftest3[i]=0.0;

// compute the real fft
cbrev(prueftest,prueftest2,NX);
rfft(prueftest2,SINE_TABLE_SIZE,scale);

//Calculate the numberof unique points
j=sizeof(prueftest);
i=0;
counter1=0;
/*
Hier will be shown two variation. I I'm not sure, that one of this is
correct
you should remove the commentary
*/
// Take the magnitude of fft of x Hier will calculate the abs(input)
for(i=0;i<(SINE_TABLE_SIZE-1);i+=2)
{
temp1=(float)((float)prueftest2[i]*(float)prueftest2[i]);
temp2=(float)((float)prueftest2[i+1]*(float)prueftest2[i+1]);
temp3=temp2+temp1;
temp4=(float)sqrt((double)temp3);
prueftest3[counter1]=(DATA)temp4;
counter1++;
}
// then the value of prueftest3 will be display in time/frequenz-
single Time

printf("Hallo Leute");
}
//////////////////////////
Back to top
Stephan M. Bernsee
Guest





Posted: Mon Dec 20, 2004 3:25 pm    Post subject: Re: FFT build with DSP Reply with quote

On 2004-12-20 09:15:22 +0100, johnbesel@web.de (Eugene) said:

Quote:
DATA

What kind of data type is that exactly?
--
Stephan M. Bernsee
http://www.dspdimension.com
Back to top
Shawn Steenhagen
Guest





Posted: Tue Dec 21, 2004 1:02 am    Post subject: Re: FFT build with DSP Reply with quote

"Eugene" <johnbesel@web.de> wrote in message
news:6484110f.0412200015.4fd13c7b@posting.google.com...
Quote:

///////////////////////////////////
#include <math.h
#include <tms320.h
#include <dsplib.h
#include <stdio.h
#define NX 128
#define SINE_MAX 0x7FFE
#define SINE_TABLE_SIZE 256
#define PI ((double)3.1415927)
short scale = 1;
short x1[2*NX];
int sinetable[SINE_TABLE_SIZE];
DATA prueftest[SINE_TABLE_SIZE];
DATA prueftest1[SINE_TABLE_SIZE];
DATA prueftest2[SINE_TABLE_SIZE];
DATA prueftest3[SINE_TABLE_SIZE];

{Snip}

// compute the real fft
cbrev(prueftest,prueftest2,NX);
rfft(prueftest2,SINE_TABLE_SIZE,scale);


{Snip..}

// Take the magnitude of fft of x Hier will calculate the abs(input)
for(i=0;i<(SINE_TABLE_SIZE-1);i+=2)
{
temp1=(float)((float)prueftest2[i]*(float)prueftest2[i]);
temp2=(float)((float)prueftest2[i+1]*(float)prueftest2[i+1]);
temp3=temp2+temp1;
temp4=(float)sqrt((double)temp3);
prueftest3[counter1]=(DATA)temp4;
counter1++;
}
// then the value of prueftest3 will be display in time/frequenz-
single Time

printf("Hallo Leute");
}
//////////////////////////

At first glance I would make sure that the variables prueftest[],
prueftest2[ ] are aligned on 2*nx = 2*256 = 512 word boundaries by using the
..align directive in your linker command file. Since I don't see the use of
the #pragma DATA_SECTION directive, I'll bet you aren't putting these
variables in a special section so that you can tell the linker command file
to align variables in this section on the proper boundary.

Look at the example in C:\ti\c5400\dsplib\examples\rfft.
Look at test.h and the linker command file for that example..

-Shawn
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> DSP All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB