Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

GMT_App_J_1.sh 4.0 KB

You have to be logged in to leave a comment. Sign In
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  1. #!/usr/bin/env bash
  2. #
  3. # Script to draw the impulse responses and transfer functions
  4. # for GMT cookbook Appendix_J.
  5. #
  6. # W H F Smith, 18 December 1998.
  7. #
  8. # 1-dimensional case, "gmt filter1d", Fourier transform.
  9. #
  10. # Impulse responses (relative amplitude, x in units of
  11. # length per filter width).
  12. #
  13. # Let distance units be expressed relative to filter width,
  14. # i.e. x = s/w, where s is the user's distance unit and w
  15. # is the user's filter width in the argument to gmt filter1d.
  16. # Then the impulse responses are non-zero only for fabs(x) < 0.5.
  17. # The impulse responses for fabs(x) < 0.5 are proportional to:
  18. # boxcar: h(x) = 1.0;
  19. # cosine: h(x) = 0.5 * (1.0 + cos(2 * pi * x) );
  20. # gaussian: h(x) = exp (-18 * x * x);
  21. # The factor 18 comes from the fact that we use sigma = 1/6
  22. # in these units and a definition of the gaussian with the
  23. # factor 1/2 as in the normal probability density function.
  24. #
  25. # Transfer functions (f = frequency in cycles per filter width):
  26. # H(f) = integral from -0.5 to 0.5 of h(x) * cos(2 * pi * f * x).
  27. # boxcar: H(f) = (sin (pi f) ) / (pi * f);
  28. # cosine: H(f) = ((sin (pi f) ) / (pi * f)) / ( 1.0 - f*f);
  29. # gaussian: H(f) ~ exp (-(1/18) * (pi * f) * (pi * f) );
  30. # The gaussian H(f) is approximate because the convolution is
  31. # carried only over fabs(x) < 0.5 and not fabs(x) -> infinity.
  32. # Of course, all these H(f) are approximate because the discrete
  33. # sampling of the data is not accounted for in these formulae.
  34. #
  35. #
  36. # 2-dimensional case, "gmt grdfilter", Hankel transform.
  37. #
  38. # Impulse response:
  39. # Let r be measured in units relative to the filter width.
  40. # The filter width defines a diameter, so the impulse
  41. # response is non-zero only for r < 0.5, as for x above.
  42. # So the graph of the impulse response h(r) for 0 < r < 0.5
  43. # is identical to the graph for h(x) for 0 < x < 0.5 above.
  44. #
  45. # Transfer functions:
  46. # These involve the Hankel transform of h(r):
  47. # H(q) = 2 * pi * Integral from 0 to 0.5 of h(r) * J0(2piqr) r dr
  48. # as in Bracewell, p. 248, where J0 is the zero order Bessel function,
  49. # and q is in cycles per filter width.
  50. # boxcar: H(q) = J1 (2 * pi * q) / (pi * q); J1 = 1st order Bessel fn.
  51. # cosine: H(q) = must be evaluated numerically (?**).
  52. # gaussian: H(q) ~ exp (-(1/18) * (pi * q) * (pi * q) );
  53. #
  54. # After many hours of tedium and consulting the treatises like Watson,
  55. # I gave up on obtaining an answer for the Hankel transform of the
  56. # cosine filter. I tried substituting an infinite series of J(4k)(z)
  57. # for 1 + cos(z), and I tried substituting an integral form of J0(z).
  58. # Nothing worked out.
  59. #
  60. # I tried to compute the Hankel transform numerically on the HP, and
  61. # found that the -lm library routines j0(x) and j1(x) give wrong answers.
  62. # I used an old Sun to compute "r_tr_fns.d" for plotting here.
  63. #
  64. # NOTE that the expressions in the comments above are not the actual
  65. # impulse responses because they are normalized to have a maximum
  66. # value of 1. Direct Fourier or Hankel transform of these values
  67. # gives a transfer function with H(0) not equal 1, generally. I
  68. # have normalized the transfer functions (correctly) so that H(0)=1.
  69. # Thus the graphs of H are correct, but the graphs of h(x) are only
  70. # relative. One reason for doing it this was is that then the
  71. # graphs of h(x) can be interpreted as also = the graphs of h(r).
  72. #
  73. #---------------------------------------------------
  74. gmt begin GMT_App_J_1
  75. gmt set GMT_THEME cookbook
  76. RJ="-R-0.6/0.6/-0.1/1.1 -JX4i/2i"
  77. echo "-0.5 0" > tt.tmp
  78. gmt math -T-0.5/0.5/0.01 1 = >> tt.tmp
  79. echo "0.5 0" >> tt.tmp
  80. gmt set FONT_ANNOT_PRIMARY 10p,Times-Roman FONT_TITLE 14p,Times-Roman FONT_LABEL 12p,Times-Roman
  81. gmt plot tt.tmp $RJ -Bxa0.5f0.1+l"Distance (units of filter width)" -Bya0.2f0.1g1+l"Relative amplitude" -BWeSn -Wthick
  82. gmt math -T-0.5/0.5/0.01 T PI 2 MUL MUL COS 1 ADD 0.5 MUL = | gmt plot $RJ -Wthick,-
  83. gmt math -T-0.5/0.5/0.01 T T MUL 18 MUL NEG EXP = | gmt plot $RJ -Wthick,.
  84. gmt text -F+f9p,Times-Roman+j << END
  85. -0.2 0.3 LM Solid Line:
  86. -0.2 0.2 LM Dotted Line:
  87. -0.2 0.1 LM Dashed Line:
  88. 0.2 0.3 RM Boxcar
  89. 0.2 0.2 RM Gaussian
  90. 0.2 0.1 RM Cosine
  91. END
  92. gmt end show
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...