DSPRelated.com
Code

Taylor-Weighted Window Generator

Eric Jacobsen October 27, 20104 comments Coded in C

This routine generates the coefficients for a Taylor-Weighted Window for use with a DFT. The window characteristics are user selectable and include:

N = the window length.
A = the desired Peak Sidelobe Ratio (PSLR).
n' = the number of terms used in the computation.
s = an integer scale factor.

The number of terms used affects the precision of the output window shape and the computation time. These days computation time is likely a non-issue.

This code is very old and was coded to the standards of the day (DOS consoles, yay!). It can be easily modified to run as a subroutine or to produce floating point coefficients.

Eric Jacobsen
Abineau Communications

/*

	11/8/89		Eric Jacobsen

	Generates Taylor weighting coefficients for a vector
	of arbitrary length n. The user supplies n' (nprime),
	the number of terms used in the calculations, and A,
	the peak sidelobe ratio in db. N must also be supplied
	by the user.

	This version (HTaylor) scales the output data by a
	user supplied integer. The output is rounded to the
	nearest integer.

*/
#include <stdio.h>
#include <math.h>

void main(argc,argv)

int argc;
char *argv[];

{

 char outfile[30],
  *help="\n USE: Taylor outfile N A n' s\n\n © 11/89 Eric Jacobsen\n\n N = # pts, A = PSLR, n' = # terms, s = integer scale factor.\n\n";

 float Fm,k,sigma,x,A,dprod,nprod,scl;
 int i,m,N,nprime,p,scale,*w,*h;
 extern double cos(),log(),pow();
 FILE *fopen(),*fp;

 if(argv[1][0]=='?'){
  puts(help);
  exit(0);
  }

 if(argc<2){
  printf("\n Enter name of output file: ");
  scanf("%s",outfile);
  }
 else strcpy(outfile,argv[1]);

 if(argc<3){
  printf("\n Enter the number of points: ");
  scanf("%d",&N);
  }
 else N=atoi(argv[2]);

 if(argc<4){
  printf("\n Enter PSLR (A) in db: ");
  scanf("%f",&A);
  }
 else A=atof(argv[3]);

 A=abs(A);

 if(argc<5){
  printf("\n Enter the number of terms (n'): ");
  scanf("%d",&nprime);
  }
 else nprime=atoi(argv[4]);

 if(argc<6){
  printf("\n Enter the scale factor: ");
  scanf("%d",&scale);
  }
 else scale=atoi(argv[5]);

 if(!(fp=fopen(outfile,"w"))){
  printf("\n\n Can't open %s.\n\n",outfile);
  exit(2);
  }

 k=0.885*(1.0+((A-13.0)/65.0));
 x=pow(10.0,A/20.0);
 A=log(x+sqrt((x*x)-1))/PI;

 sigma=(float)nprime/sqrt((A*A)+(((float)nprime)-0.5)*(((float)nprime)-0.5));

 printf("\n Sigma = %f, k = %f\n\n Calculating...",sigma,k);

 Fm=0.0;

 for(m=1;m<nprime;m++){
  dprod=nprod=1.0;
  for(p=1;p<nprime;p++){
   if(p!=m)dprod*=1.0-((float)(m*m)/(float)(p*p));
   nprod*=1.0-(float)(m*m)/(((A*A)+(((float)p)-0.5)*(((float)p)-0.5))*sigma*sigma);
   }
  Fm+=(float)(m % 2 ? 1:-1)*nprod/dprod;
  }

 if(!(w=h=(int *)AllocMem(4*N,0))){
  puts("\n\n ** Insufficient Memory **\n\n");
  exit(12);
  }

 scl=(float)scale;

 for(i=0;i<N;i++)
  *w++=(int)(scl*(1.0+(Fm*(-cos(2.0*PI*(float)i/(float)N))))+0.5);

 printf("done.\n");
 printf("\n Writing output file...");

 w=h;

 for(i=0;i<N;i++)fprintf(fp,"	DC.W	%d\n",*w++);

 printf("done.\n\n");

 FreeMem(h,4*N);
 fclose(fp);

}