File: fftS05.htm

package info (click to toggle)
extrema 4.4.4.dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 19,416 kB
  • ctags: 6,689
  • sloc: cpp: 88,991; sh: 8,229; makefile: 480
file content (54 lines) | stat: -rw-r--r-- 1,725 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<HTML>
<HEAD>
<TITLE>Example</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF" fgcolor="#000000">

<p>
 <font size="+1" color="green"><B>Example</B></font></P>
<p>
 The following script demonstrates how you can use the <code>FFT</code>
 function to smooth data. Note that when all the Fourier coefficients are used, the smoothed
 curve must pass through the original data points.</p>
<p>
 <font color="blue"><pre>
 PI = ACOS(-1)          ! define pi
 N = 16                 ! even number of points
 X = [0:N-1]*2*PI/N     ! generate some "data"
 Y = SIN(X)+5*RAN(X)    !
 M = FFT(Y,'COS&SIN')   ! calculate Fourier coefficients
 H = M[*,1]             ! extract column 1 as a vector
 G = M[*,2]             ! extract column 2 as a vector
 Z = [0:2*PI:.05]
 DO J = [3:N/2+1:2]
   WINDOW (J-3)/2+5     ! choose a graphics window
   SCALE 0 6 0 -2 7 0   ! set axis scales
   SET PLOTSYMBOL -1    ! choose plotting symbol
   SET %XNUMBERHEIGHT 5
   SET %YNUMBERHEIGHT 5
   GRAPH X Y            ! plot original data
   SET PLOTSYMBOL 0     ! choose no plotting symbol
   VECTOR TMP len(z)
   DO K = [2:J]
     TMP = TMP + H[K]*COS((K-1)*Z)+G[K]*SIN((K-1)*Z)
   ENDDO
   GRAPH/OVERLAY Z H[1]/2+TMP
   destroy tmp
   SET %TEXTHEIGHT 5    ! increase the size of the text label
   SET %XTEXTLOCATION 50
   SET %YTEXTLOCATION 85
   SET TEXTALIGN 2
   SET TEXTINTERACTIVE 0
   TEXT RCHAR(J)//' harmonics used'
 ENDDO
 GRAPH/OVERLAY [0;2*PI] [H[1]/2;H[1]/2] ! overlay the mean value
 CLEAR/-REPLOT
 REPLOT/ALL
 </pre></font></p>
<p>
 <center><img src="fftS05I01.jpg"></center></p>
<P>
  <a href="fftS04.htm"><img align="top" border="0" src="../shadow_left.gif">&nbsp;
    <font size="+1" color="olive">Prime factors</font></a></p>
</BODY>
</HTML>