DSPRelated.com
Forums

FFT Radix 3

Started by Akshaya Mukund March 19, 2010
I have been trying to code a normal C program for a radix 3 fft problem. My
program works for 3,6,9,27 points but conks off for the 81 point fft
onwards. I would like to know if there is a mistake in my program or is it
because VC can't support such intensive calculations ;P. Well I really
don't know how to go ahead.I thought maybe I had calculated my twiddle
factors wrong and I have even tried writing out the complete equation(81
terms) for one particular output. Nothing wrong with my algo (but I could
definitely be wrong as well). Can anyone please check it out. Here is my
code.

The possible sources of error could be my butterfly function (you can chk
it out below), or maybe the fact that I have messed up some type casting.

If anyone gets lucky with this please let me know. thank you for your
time.

Cheers 
Akshaya

/////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

struct dft
{
	double r,i;
};

#define pi (double)2*asin((double)1)

double* data_input(char*, double*);  //used to input data 
int trittoint(int *trit,int m);      //convert trit to int
void tritrev(int *trit, int m);      //reverse the trit
void tritconvert(int m, int i,int* trit);    //convert to trit
double twiddle_geni(int N,int k,int m);   //imag part of twiddle factor
double twiddle_genr(int N,int k,int m);   //real part
void butterfly(struct dft *a,int aidx,int stage,int bno,int sets,int N);
      //butterfly structure (radix-3)and also twiddle factor mult
 
int main()
{//to do a 3,6,9,27 just change N to no of pts and m to no. of trits
	FILE *fid, *fid1;
	int i,j,k,l,N=81,m=4,trit[4],limit,limit1,aidx=0;				//3^m = N (no of
trits)
	struct dft a[81],b[81],*temp;
	char *path = "data2.txt";
	double temp1,t2[81],*t1;
	
	

	//init data for fft
	for(i=0;i<N;i++)
	{
		b[i].r = b[i].i = 0;
		a[i].r = 0;
		a[i].i = 0;
		c[i].r=c[i].i=0;
	}
	
	//data entered into input struct var from file
	//t1 = data_input(path,t2);
	for(i=0;i<N;i++)                // i'm entering arbitrary data here
		a[i].r  = i;

        //reordering loop
        //reordered into proper order trit conversion then reversal
        // this part is fine but you are welcome to chk it out

	for(i=1;i<2*N/3;i++)
	{
		tritconvert(i,m,trit);		//convert to trits
		tritrev(trit,m);			//reverse the trit
		j = trittoint(trit,m);		//convert to integer

		if(j>i)						//swap
		{
			temp1 = a[j].r;
			a[j].r = a[i].r;
			a[i].r = temp1;
		}
	}


        //fft loop

	for(i=0;i<m;i++)	//loop takes care of the stage
	{
		limit = (int)pow((double)3,(double)(m-1-i)); //sets of 
                                                      //radix 3
butterflies
		aidx = 0;
		for(j=0;j<limit;j++)	//no of sets of butterflies
		{
			limit1 = (int)pow((double)3,(double)i);
			for(k=0;k<limit1;k++)	//no of butterflies per set
			{
				butterfly(a,aidx,i,k,limit,N);
				aidx++;
			}
			aidx += (int)pow((double)3,(double)(i+1))-limit1; 
		}
	}

	
	//writing the fft onto text file
	fid = fopen("datafftreal.txt","wb");
	fid1 = fopen("datafftimag.txt","wb");
	for(i=0;i<27;i++)
	{
		temp = &(a[i].r);
		fwrite(temp,sizeof(double),1,fid);
		temp = &(a[i].i);
		fwrite(temp,sizeof(double),1,fid1);
	}
	
	fclose(fid);
	fclose(fid1);

	return (0);
}

double* data_input(char* path, double* input)
{
	FILE *fid;
	int i;

	fid = fopen(path,"rb");
	fread(input,8,27,fid);

	for(i=0;i<27;i++)
	{
		//svbarve
		input[i] = 00.0;
		printf("%lf\t",input[i]);
	}

	fclose(fid);

	return (input);
}

void butterfly(struct dft *a,int aidx,int stage,int bno,int sets,int N)
{
	int l,k,i,loopinc,n=3;
	struct dft temp[3];

	loopinc = (int)pow((double)3,(double)stage);

	for(l=aidx,i=0;i<3;i++)
	{
		temp[i].r = a[l].r;
		temp[i].i = a[l].i;
		a[l].r=0;
		a[l].i=0;
		l += loopinc;
	}

	k = aidx;
	for(i=0;i<3;i++)
	{
		for(l=0;l<3;l++)
		{
			a[k].r += (temp[l].r*twiddle_genr(n,l,i) -
temp[l].i*twiddle_geni(n,l,i))*twiddle_genr(N,l,bno*sets);//doubt
			a[k].r -= (temp[l].r*twiddle_geni(n,l,i) +
temp[l].i*twiddle_genr(n,l,i))*twiddle_geni(N,l,bno*sets);
			a[k].i += (temp[l].r*twiddle_geni(n,l,i) +
temp[l].i*twiddle_genr(n,l,i))*twiddle_genr(N,l,bno*sets);//doubt
			a[k].i += (temp[l].r*twiddle_genr(n,l,i) -
temp[l].i*twiddle_geni(n,l,i))*twiddle_geni(N,l,bno*sets);
		}
		k += loopinc;
	}
}


void tritconvert(int i, int m, int* trit)
//used inreordering loop (conv to trit)
{
	int j=0;
	for(j=0;j<m;j++)
		trit[j]=0;
	
	j=0;
	while(i>0)
	{
		trit[j]=i%3;
		i = i/3;
		j++;
	}
}

void tritrev(int *trit,int m)	//used in reordering loop (rev the trits)
{
	int temp,i,j;
	for(i=0,j=m-1;i<m/2;i++,j--)
	{
		temp = trit[i];
		trit[i] = trit[j];
		trit[j] = temp;
	}
}

int trittoint(int *trit,int m)	//used in reordering loop(convert to int)
{
	int i,j=0,z=1;
	for(i=0;i<m;i++)
	{
		j = j + trit[i]*z;
		z*= 3;
	}
	return (j);
}

double twiddle_genr(int N,int k,int m)
{
	double te;
	te = cos((-2*k*m*pi)/N);
	return(te); 
}
double twiddle_geni(int N,int k,int m)
{
	double te;
	te = sin((-2*k*m*pi)/N);
	return(te); 
}	


On Mar 19, 8:01&#4294967295;am, "Akshaya Mukund"
<akshaya.mukund@n_o_s_p_a_m.gmail.com> wrote:
> I have been trying to code a normal C program for a radix 3 fft problem. My > program works for 3,6,9,27 points but conks off for the 81 point fft > onwards. I would like to know if there is a mistake in my program or is it > because VC can't support such intensive calculations ;P. Well I really > don't know how to go ahead.I thought maybe I had calculated my twiddle > factors wrong and I have even tried writing out the complete equation(81 > terms) for one particular output. Nothing wrong with my algo (but I could > definitely be wrong as well). Can anyone please check it out. Here is my > code. > > The possible sources of error could be my butterfly function (you can chk > it out below), or maybe the fact that I have messed up some type casting. > > If anyone gets lucky with this please let me know. thank you for your > time. > > Cheers > Akshaya > > ///////////////////////////////////////////////////////////////// > > #include <stdio.h> > #include <stdlib.h> > #include <math.h> > > struct dft > { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; double r,i; > > }; > > #define pi (double)2*asin((double)1) > > double* data_input(char*, double*); &#4294967295;//used to input data > int trittoint(int *trit,int m); &#4294967295; &#4294967295; &#4294967295;//convert trit to int > void tritrev(int *trit, int m); &#4294967295; &#4294967295; &#4294967295;//reverse the trit > void tritconvert(int m, int i,int* trit); &#4294967295; &#4294967295;//convert to trit > double twiddle_geni(int N,int k,int m); &#4294967295; //imag part of twiddle factor > double twiddle_genr(int N,int k,int m); &#4294967295; //real part > void butterfly(struct dft *a,int aidx,int stage,int bno,int sets,int N); > &#4294967295; &#4294967295; &#4294967295; //butterfly structure (radix-3)and also twiddle factor mult > > int main() > {//to do a 3,6,9,27 just change N to no of pts and m to no. of trits > &#4294967295; &#4294967295; &#4294967295; &#4294967295; FILE *fid, *fid1; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; int i,j,k,l,N=81,m=4,trit[4],limit,limit1,aidx=0; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; //3^m = N (no of > trits) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; struct dft a[81],b[81],*temp; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; char *path = "data2.txt"; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; double temp1,t2[81],*t1; > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; //init data for fft > &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(i=0;i<N;i++) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; b[i].r = b[i].i = 0; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; a[i].r = 0; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; a[i].i = 0; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; c[i].r=c[i].i=0; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; //data entered into input struct var from file > &#4294967295; &#4294967295; &#4294967295; &#4294967295; //t1 = data_input(path,t2); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(i=0;i<N;i++) &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;// i'm entering arbitrary data here > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; a[i].r &#4294967295;= i; > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; //reordering loop > &#4294967295; &#4294967295; &#4294967295; &#4294967295; //reordered into proper order trit conversion then reversal > &#4294967295; &#4294967295; &#4294967295; &#4294967295; // this part is fine but you are welcome to chk it out > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(i=1;i<2*N/3;i++) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; tritconvert(i,m,trit); &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;//convert to trits > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; tritrev(trit,m); &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;//reverse the trit > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; j = trittoint(trit,m); &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;//convert to integer > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; if(j>i) &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295;//swap > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; temp1 = a[j].r; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; a[j].r = a[i].r; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; a[i].r = temp1; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; //fft loop > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(i=0;i<m;i++) &#4294967295; &#4294967295; //loop takes care of the stage > &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; limit = (int)pow((double)3,(double)(m-1-i)); //sets of > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; //radix 3 > butterflies > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; aidx = 0; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(j=0;j<limit;j++) //no of sets of butterflies > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; limit1 = (int)pow((double)3,(double)i); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(k=0;k<limit1;k++) &#4294967295; &#4294967295; &#4294967295; &#4294967295;//no of butterflies per set > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; butterfly(a,aidx,i,k,limit,N); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; aidx++; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; aidx += (int)pow((double)3,(double)(i+1))-limit1; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; //writing the fft onto text file > &#4294967295; &#4294967295; &#4294967295; &#4294967295; fid = fopen("datafftreal.txt","wb"); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; fid1 = fopen("datafftimag.txt","wb"); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(i=0;i<27;i++) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; temp = &(a[i].r); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; fwrite(temp,sizeof(double),1,fid); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; temp = &(a[i].i); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; fwrite(temp,sizeof(double),1,fid1); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; fclose(fid); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; fclose(fid1); > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; return (0); > > } > > double* data_input(char* path, double* input) > { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; FILE *fid; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; int i; > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; fid = fopen(path,"rb"); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; fread(input,8,27,fid); > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(i=0;i<27;i++) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; //svbarve > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; input[i] = 00.0; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; printf("%lf\t",input[i]); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; fclose(fid); > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; return (input); > > } > > void butterfly(struct dft *a,int aidx,int stage,int bno,int sets,int N) > { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; int l,k,i,loopinc,n=3; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; struct dft temp[3]; > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; loopinc = (int)pow((double)3,(double)stage); > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(l=aidx,i=0;i<3;i++) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; temp[i].r = a[l].r; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; temp[i].i = a[l].i; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; a[l].r=0; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; a[l].i=0; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; l += loopinc; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; k = aidx; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(i=0;i<3;i++) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(l=0;l<3;l++) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; a[k].r += (temp[l].r*twiddle_genr(n,l,i) - > temp[l].i*twiddle_geni(n,l,i))*twiddle_genr(N,l,bno*sets);//doubt > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; a[k].r -= (temp[l].r*twiddle_geni(n,l,i) + > temp[l].i*twiddle_genr(n,l,i))*twiddle_geni(N,l,bno*sets); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; a[k].i += (temp[l].r*twiddle_geni(n,l,i) + > temp[l].i*twiddle_genr(n,l,i))*twiddle_genr(N,l,bno*sets);//doubt > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; a[k].i += (temp[l].r*twiddle_genr(n,l,i) - > temp[l].i*twiddle_geni(n,l,i))*twiddle_geni(N,l,bno*sets); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; k += loopinc; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > > } > > void tritconvert(int i, int m, int* trit) > //used inreordering loop (conv to trit) > { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; int j=0; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(j=0;j<m;j++) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; trit[j]=0; > > &#4294967295; &#4294967295; &#4294967295; &#4294967295; j=0; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; while(i>0) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; trit[j]=i%3; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; i = i/3; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; j++; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > > } > > void tritrev(int *trit,int m) &#4294967295; //used in reordering loop (rev the trits) > { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; int temp,i,j; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(i=0,j=m-1;i<m/2;i++,j--) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; temp = trit[i]; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; trit[i] = trit[j]; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; trit[j] = temp; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > > } > > int trittoint(int *trit,int m) &#4294967295;//used in reordering loop(convert to int) > { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; int i,j=0,z=1; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; for(i=0;i<m;i++) > &#4294967295; &#4294967295; &#4294967295; &#4294967295; { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; j = j + trit[i]*z; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; z*= 3; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; } > &#4294967295; &#4294967295; &#4294967295; &#4294967295; return (j); > > } > > double twiddle_genr(int N,int k,int m) > { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; double te; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; te = cos((-2*k*m*pi)/N); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; return(te);} > > double twiddle_geni(int N,int k,int m) > { > &#4294967295; &#4294967295; &#4294967295; &#4294967295; double te; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; te = sin((-2*k*m*pi)/N); > &#4294967295; &#4294967295; &#4294967295; &#4294967295; return(te); > > > > } &#4294967295; &#4294967295; &#4294967295;- Hide quoted text - > > - Show quoted text -
I'm sure the problem is in your code and not a limitation of VC. Clay
Akshaya Mukund wrote:
> I have been trying to code a normal C program for a radix 3 fft problem. My > program works for 3,6,9,27 points but conks off for the 81 point fft > onwards. I would like to know if there is a mistake in my program or is it > because VC can't support such intensive calculations ;P. Well I really > don't know how to go ahead.I thought maybe I had calculated my twiddle > factors wrong and I have even tried writing out the complete equation(81 > terms) for one particular output. Nothing wrong with my algo (but I could > definitely be wrong as well). Can anyone please check it out. Here is my > code. > > The possible sources of error could be my butterfly function (you can chk > it out below), or maybe the fact that I have messed up some type casting. > > If anyone gets lucky with this please let me know. thank you for your > time.
Do you use signed bytes as counters? 3*81 wraps. Jerry -- Discovery consists of seeing what everybody has seen, and thinking what nobody has thought. .. Albert Szent-Gyorgi &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;