File: fft.pcm

package info (click to toggle)
extrema 4.3.6-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 19,212 kB
  • ctags: 6,452
  • sloc: cpp: 86,428; sh: 8,229; makefile: 814
file content (39 lines) | stat: -rw-r--r-- 1,104 bytes parent folder | download | duplicates (3)
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
clear
defaults
!
DEFINE\CONSTANTS       ! define pi (among other constants)
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
  DEFAULTS
  SCALE\-mess 0 6 0 -2 7 0   ! set axis scales
  SET
   PLOTSYMBOL -1    ! choose plotting symbol
   %XNUMBERSHEIGHT 5
   %YNUMBERSHEIGHT 5
   
  GRAPH X Y            ! plot original data
  SET PLOTSYMBOL 0     ! choose no plotting symbol
  TMP[1:LEN(Z)] = 0
  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\-mess TMP
  SET
   %TEXTHEIGHT 5    ! increase the size of the x-axis label
   %XTEXTLOCATION 50
   %YTEXTLOCATION 80
    TEXTALIGN 2
    TEXTINTERACTIVE 0
    
  TEXT RCHAR(J)//' harmonics used'
  replot 
ENDDO
GRAPH\OVERLAY [0;2*PI] [H[1]/2;H[1]/2] ! overlay the mean value