File:FFTexample16T.png: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Dmitrii Kouznetsov
({{Image_Details|user |description = Application of the FFT operator to the array that approximates the self-Fourier gaussian |author = ~~~ |date-created = 9 October 2011 |pub-country = Japan |notes = Comparison of the discrete Fourier transform, shown with red, of a self–Fourier function <math>A(x)=\exp(-x^2/2)</math>, shown with black dots, to the result of the numerical evaluation of the the Fourier operator of array <math>A</math>, shown with blue. The disc...)
 
(== Summary == Importing file)
Tag: Server-side upload
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Summary ==
== Summary ==
{{Image_Details|user
Importing file
|description  = Application of the [[FFT]] operator to the array that approximates the [[self-Fourier]] gaussian
|author      = [[User:Dmitrii Kouznetsov|Dmitrii Kouznetsov]]
|date-created =  9 October 2011
|pub-country  = Japan
|notes        = Comparison of the discrete Fourier transform, shown with red,
of a [[self–Fourier function]] <math>A(x)=\exp(-x^2/2)</math>, shown with black dots, to the result of the numerical evaluation of the the [[Fourier operator]] of array <math>A</math>, shown with blue. The discrete representation is performed with number of nodes <math>n\!=\!16</math>.
 
 
==[[C++]] generator of curves==
 
File [[fafo.cin]] should be loaded to the working directory for the compilation of the code below.
 
#include<math.h>
#include<stdio.h>
#include <stdlib.h>
#include <complex>
using namespace std;
#define z_type complex<double>
#define Re(x)  x.real()
#define Im(x)  x.imag()
#define RI(x)  x.real(),x.imag()
#define DB double
#define DO(x,y) for(x=0;x<y;x++)
 
void ado(FILE *O, int X, int Y)
{      fprintf(O,"%c!PS-Adobe-2.0 EPSF-2.0\n",'%');
        fprintf(O,"%c%cBoundingBox: 0 0 %d %d\n",'%','%',X,Y);
        fprintf(O,"/M {moveto} bind def\n");
        fprintf(O,"/L {lineto} bind def\n");
        fprintf(O,"/S {stroke} bind def\n");
        fprintf(O,"/s {show newpath} bind def\n");
        fprintf(O,"/C {closepath} bind def\n");
        fprintf(O,"/F {fill} bind def\n");
        fprintf(O,"/o {.025 0 360 arc C F} bind def\n");
        fprintf(O,"/times-Roman findfont 20 scalefont setfont\n");
        fprintf(O,"/W {setlinewidth} bind def\n");
        fprintf(O,"/RGB {setrgbcolor} bind def\n");}
// #include "ado.cin"
 
#include"fafo.cin"
 
// DB F(DB x){DB u=x*x; return u*(-3.+u)*exp(-x*x/2.);}
DB F(DB x){ return exp(-x*x/2.);}
 
main(){z_type * a, *b, c; int j,m,n, N=16; FILE *o;
        double step=sqrt(2*M_PI/N),x,y,u;
        a=(z_type *) malloc((size_t)((N+1)*sizeof(z_type)));
        b=(z_type *) malloc((size_t)((N+1)*sizeof(z_type)));
//for(j=0;j<N;j++) { x=step*(j-N/2); u=x*x; a[j]=b[j]=(3.+u*(-6.+u))*exp(-x*x/2); }
for(j=0;j<N;j++) { x=step*(j-N/2); u=x*x; a[j]=b[j]=F(x); }
fft(b,N,1);
for(j=0;j<N;j++) printf("%2d %18.15f %18.15f  %18.15f %18.15f\n", j, RI(a[j]), RI(b[j])  );
o=fopen("FFTexample16.eps","w"); ado(o,1024,780);
#define M(x,y) fprintf(o,"%6.4f %6.4f M\n",0.+x,0.+y);
#define L(x,y) fprintf(o,"%6.4f %6.4f L\n",0.+x,0.+y);
#define o(x,y) fprintf(o,"%6.4f %6.4f o\n",0.+x,0.+y);
fprintf(o,"522 340 translate 100 100 scale\n");
// M(-5,0) L(5,0) M(0,0) L(0,1) fprintf(o,".01 W S\n");
// M(-5,1) L(5,1) M(-5,-1) L(5,-1)
for(m=-5;m<6;m++) {M(m,-3) L(m,3)} fprintf(o,".004 W S\n");
for(m=-3;m<4;m++) {M(-5,m) L(5,m)} fprintf(o,".004 W S\n");
fprintf(o,"1 setlinejoin 1 setlinecap\n");
DB *X; X=(DB *) malloc((size_t)((N+1)*sizeof(DB))); DO(j,N){ x=step*(j-N/2); X[j]=x; }
DO(j,N){x=X[j]; M(x,0)L(x,.15)} fprintf(o,".01 W S\n");
DO(j,N){x=X[j];y=Re(a[j]); if(j==0)M(x,y)else L(x,y);} fprintf(o,".04 W 0 .4 1 RGB S\n");
DO(j,N){x=X[j];y=Re(b[j]); if(j==0)M(x,y)else L(x,y);} fprintf(o,".04 W 1 0 0 RGB S\n");
// DO(j,N){x=X[j];y=Im(b[j]); if(j==0)M(x,y)else L(x,y);} fprintf(o,".04 W 1 0 0 RGB S\n");
// DO(j,N){x=X[j];y=100.*(Re(b[j])-F(x)); if(j==0)M(x,y)else L(x,y);} fprintf(o,"0.007 W 0 0 .3 RGB S\n");
printf("X[0]=%9.5f step=%9.6f\n",X[0],step);
// DO(m,101){x=-5.+.1*m; y=F(x); if(m/2*2==m)M(x,y)else L(x,y);} fprintf(o,".01 W 0 0 0 RGB S\n");
fprintf(o,".01 W 0 0 0 RGB S\n");
DO(m,101){x=-5.+.1*m; y=F(x); o(x,y)}
fprintf(o,"showpage\n%cTrailer",'%'); fclose(o);
  system("epstopdf FFTexample16.eps");
  system(    "open FFTexample16.pdf"); //these 2 commands may be specific for macintosh
  getchar(); system("killall Preview");// if run at another operational system, may need to modify
  free(a);
  free(b);
  free(X);
}
The image is generated in the following way.
 
The lines are drawn in the [[EPS]] format by the [[C++]] code below. The result is concerted to [[PDF]] format.
 
The labels are added in the [[latex]] document below.
 
The result is concerted to the [[PNG]] format with default reaolution.
 
|versions    =
}}
== Licensing ==
{{CC|by|3.0}}

Latest revision as of 18:57, 11 March 2022

Summary

Importing file

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current18:57, 11 March 2022Thumbnail for version as of 18:57, 11 March 20222,101 × 1,536 (155 KB)Maintenance script (talk | contribs)== Summary == Importing file

The following page uses this file:

Metadata