Taylor-Weighted Window Generator

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,
*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=='?'){
puts(help);
exit(0);
}

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

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

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

A=abs(A);

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

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

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);

} gilgamash
Said:
Sorry, but you could have put a little effort in rewriting this. Why is w a pointer?And *w++=... does not work (correct me if I am wrong).. Why read an int scale and then cast it into a float scl? Where doe the magic numbers for setting k come from? And why, in the last loop for computing w, casting i and N to floats? Last, AllocMem is not a C-function... However, if I am wrong, let me know. Regards, gilgamash
9 years ago
0
Sorry, you need javascript enabled to post any comments. Slartibartfast
Said:
As mentioned in the description, this is very old code and was very typical for when it was written. It is expected that some translation and rewrite may be necessary, especially since few people use console user interfaces these days. Likewise, the memory functions were either machine or compiler specific, I don't recall, but should be easy for a competent coder to translate (or eliminate, as memory isn't nearly as constrained as it was twenty-plus years ago). So, yeah, I wouldn't expect it to just plug in and run, but it's pretty straightforward code so porting shoudln't be difficult. The useful part, the computation of the Taylor coefficients, should work with little or no modification. Certainly if one wants results in a different format then adjust as needed.
9 years ago
0
Sorry, you need javascript enabled to post any comments. Moldy01
Replied:
I realize this is a long shot, as you posted this 7 years back, but I'm hoping to find the equations for the Taylor Window. Your code is actually not bad considering the DOS comment above. Easy to understand, a simple port to Python. I'm just hoping to get the root of it all. The equations! so it'll make better sense and be easier to commit to memory.

I've tried and tried on the internet to find the Taylor window, the best that comes of the searches is comments about how it is good for Radar (especially SAR), and how it is just the Dolph-Chebyshev
2 years ago
0 Moldy01
Replied:
rearranged a bit.

Thanks,
2 years ago
0
Sorry, you need javascript enabled to post any comments.