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_2.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
  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 "tt.r_tr_fns" for plotting here.
  63. # PW: I included that file into the script below
  64. #
  65. # NOTE that the expressions in the comments above are not the actual
  66. # impulse responses because they are normalized to have a maximum
  67. # value of 1. Direct Fourier or Hankel transform of these values
  68. # gives a transfer function with H(0) not equal 1, generally. I
  69. # have normalized the transfer functions (correctly) so that H(0)=1.
  70. # Thus the graphs of H are correct, but the graphs of h(x) are only
  71. # relative. One reason for doing it this was is that then the
  72. # graphs of h(x) can be interpreted as also = the graphs of h(r).
  73. #
  74. #---------------------------------------------------
  75. gmt begin GMT_App_J_2
  76. gmt set GMT_THEME cookbook
  77. gmt set FONT_ANNOT_PRIMARY 10p,Times-Roman FONT_TITLE 14p,Times-Roman FONT_LABEL 12p,Times-Roman
  78. gmt math -T0/5/0.01 T SINC = | gmt plot -R0/5/-0.3/1 -JX4i/2i -Bxa1f0.2+l"Frequency (cycles per filter width)" -Bya0.2f0.1g1+l"Gain" -BWeSn -Wthick
  79. gmt math -T0/5/0.01 T SINC 1 T T MUL SUB DIV = | grep -v '^>' | $AWK '{ if ($1 == 1) print 1, 0.5; else print $0}' | gmt plot -Wthick,-
  80. gmt math -T0/5/0.01 T PI MUL DUP MUL 18 DIV NEG EXP = | gmt plot -Wthick,.
  81. gmt text -F+f9p,Times-Roman+j << END
  82. 2.2 0.6 LM Solid Line:
  83. 2.2 0.5 LM Dotted Line:
  84. 2.2 0.4 LM Dashed Line:
  85. 3.8 0.6 RM Boxcar
  86. 3.8 0.5 RM Gaussian
  87. 3.8 0.4 RM Cosine
  88. END
  89. gmt end show
Tip!

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

Comments

Loading...