File: stepfft.4th

package info (click to toggle)
kforth 20010227-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 508 kB
  • ctags: 652
  • sloc: asm: 2,026; cpp: 1,795; ansic: 575; makefile: 64
file content (57 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download
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
55
56
57
\ stepfft.4th
\
\ Compute the FFT of a square pulse.
\
\ Requires:
\
\	matrix.4th
\	fft.4th
\

include matrix
include fft

2048 1 fmatrix pulse

variable pulse_width
100 pulse_width !

fvariable pulse_height
1e pulse_height f!

." Initial pulse width is " pulse_width @ . cr

variable start_pulse
variable stop_pulse

: gen_pulse ( -- | generate the pulse profile )
	pulse mat_size@ drop 2/
	dup pulse_width @ - start_pulse !
	pulse_width @ + stop_pulse !
	pulse mat_size@ drop 1+ 1 do
	  i start_pulse @ > 
	  if
	    i stop_pulse @ < if
	      pulse_height f@ i 1 pulse fmat!
	    else
	      0e i 1 pulse fmat!
	    then
	  else
	    0e i 1 pulse fmat!
	  then
	  0e i 1+ 1 pulse fmat!	\ imaginary component of the pulse
	2 +loop ;


: go ( -- compute the FFT and display real and imaginary components and power )
	gen_pulse
	pulse fft
	pulse mat_size@ drop 1+ 1 do
	  i 4 .r 2 spaces
	  i 1 pulse fmat@ fdup fdup f. f* 2 spaces
	  i 1+ 1 pulse fmat@ fdup fdup f. f* f+ 2 spaces
	  f. cr
	2 +loop ;
	

." Type 'go' to generate the FFT and print it." cr