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

spectrum1d.rst 12 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
  1. .. index:: ! spectrum1d
  2. .. include:: module_core_purpose.rst_
  3. **********
  4. spectrum1d
  5. **********
  6. |spectrum1d_purpose|
  7. Synopsis
  8. --------
  9. .. include:: common_SYN_OPTs.rst_
  10. **gmt spectrum1d** [ *table* ] [ |-S|\ *segment_size* ]
  11. [ |-C|\ [**xycnpago**] ] [ |-D|\ *dt* ] [ |-L|\ [**h**\|\ **m**] ]
  12. [ |-N|\ [*name_stem*] ] [ |-T| ] [ |-W| ]
  13. [ |SYN_OPT-b| ]
  14. [ |SYN_OPT-d| ]
  15. [ |SYN_OPT-e| ]
  16. [ |SYN_OPT-f| ]
  17. [ |SYN_OPT-g| ]
  18. [ |SYN_OPT-h| ]
  19. [ |SYN_OPT-i| ]
  20. [ |SYN_OPT-qi| ]
  21. [ |SYN_OPT--| ]
  22. |No-spaces|
  23. Description
  24. -----------
  25. **spectrum1d** reads X [and Y] values from the first [and second]
  26. columns on standard input [or *x[y]file*]. These values are treated as
  27. timeseries X(t) [Y(t)] sampled at equal intervals spaced *dt* units
  28. apart. There may be any number of lines of input. **spectrum1d** will
  29. create file[s] containing auto- [and cross- ] spectral density estimates
  30. by Welch's method of ensemble averaging of multiple overlapped windows,
  31. using standard error estimates from Bendat and Piersol.
  32. The output files have 3 columns: f or w, p, and e. f or w is the
  33. frequency or wavelength, p is the spectral density estimate, and e is
  34. the one standard deviation error bar size. These files are named based
  35. on *name_stem*. If the **-C** option is used, up to eight files are
  36. created; otherwise only one (xpower) is written. The files (which are
  37. ASCII unless **-bo** is set) are as follows:
  38. *name_stem*.xpower
  39. Power spectral density of X(t). Units of X \* X \* *dt*.
  40. *name_stem*.ypower
  41. Power spectral density of Y(t). Units of Y \* Y \* *dt*.
  42. *name_stem*.cpower
  43. Power spectral density of the coherent output. Units same as ypower.
  44. *name_stem*.npower
  45. Power spectral density of the noise output. Units same as ypower.
  46. *name_stem*.gain
  47. Gain spectrum, or modulus of the transfer function. Units of (Y / X).
  48. *name_stem*.phase
  49. Phase spectrum, or phase of the transfer function. Units are
  50. radians.
  51. *name_stem*.admit
  52. Admittance spectrum, or real part of the transfer function. Units of
  53. (Y / X).
  54. *name_stem*.coh
  55. (Squared) coherency spectrum, or linear correlation coefficient as a
  56. function of frequency. Dimensionless number in [0, 1]. The
  57. Signal-to-Noise-Ratio (SNR) is coh / (1 - coh). SNR = 1 when coh = 0.5.
  58. In addition, a single file with all of the above as individual columns will
  59. be written to *stdout* (unless disabled via **-T**).
  60. Required Arguments
  61. ------------------
  62. .. _-S:
  63. **-S**\ *segment_size*
  64. *segment_size* is a radix-2 number of samples per window for
  65. ensemble averaging. The smallest frequency estimated is
  66. 1.0/(\ *segment_size* \* *dt*), while the largest is 1.0/(2 \*
  67. *dt*). One standard error in power spectral density is approximately
  68. 1.0 / sqrt(\ *n_data* / *segment_size*), so if *segment_size* =
  69. 256, you need 25,600 data to get a one standard error bar of 10%.
  70. Cross-spectral error bars are larger and more complicated, being a
  71. function also of the coherency.
  72. Optional Arguments
  73. ------------------
  74. *table*
  75. One or more ASCII (or binary, see **-bi**)
  76. files holding X(t) [Y(t)] samples in the first 1 [or 2] columns. If
  77. no files are specified, **spectrum1d** will read from standard input.
  78. .. _-C:
  79. **-C**\ [**xycnpago**]
  80. Read the first two columns of input as samples of two time-series,
  81. X(t) and Y(t). Consider Y(t) to be the output and X(t) the input in
  82. a linear system with noise. Estimate the optimum frequency response
  83. function by least squares, such that the noise output is minimized
  84. and the coherent output and the noise output are uncorrelated.
  85. Optionally specify up to 8 letters from the set { **x y c n p a g
  86. o** } in any order to create only those output files instead of the
  87. default [all]. **x** = xpower, **y** = ypower, **c** = cpower, **n**
  88. = npower, **p** = phase, **a** = admit, **g** = gain, **o** = coh.
  89. .. _-D:
  90. **-D**\ *dt*
  91. *dt* Set the spacing between samples in the time-series [Default = 1].
  92. .. _-L:
  93. **-L**
  94. Leave trend alone. By default, a linear trend will be removed prior
  95. to the transform. Alternatively, append **m** to just remove the
  96. mean value or **h** to remove the mid-value.
  97. .. _-N:
  98. **-N**\ [*name\_stem*]
  99. Supply an alternate name stem to be used for each individual output file [Default = "spectrum"].
  100. If **-N** is given with no argument then we disable the writing of individual
  101. output files and instead write a single composite results table to standard output.
  102. .. _-V:
  103. .. |Add_-V| unicode:: 0x20 .. just an invisible code
  104. .. include:: explain_-V.rst_
  105. .. _-T:
  106. **-T**
  107. Disable the writing of a single composite results table to stdout. Only individual output
  108. files for each selected component (see **-C**) will be written.
  109. .. _-W:
  110. **-W**
  111. Write Wavelength rather than frequency in column 1 of the output
  112. file[s] [Default = frequency, (cycles / *dt*)].
  113. .. |Add_-bi| replace:: [Default is 2 input columns].
  114. .. include:: explain_-bi.rst_
  115. .. |Add_-bo| replace:: [Default is 2 output columns].
  116. .. include:: explain_-bo.rst_
  117. .. |Add_-d| unicode:: 0x20 .. just an invisible code
  118. .. include:: explain_-d.rst_
  119. .. |Add_-e| unicode:: 0x20 .. just an invisible code
  120. .. include:: explain_-e.rst_
  121. .. |Add_-f| unicode:: 0x20 .. just an invisible code
  122. .. include:: explain_-f.rst_
  123. .. |Add_-g| unicode:: 0x20 .. just an invisible code
  124. .. include:: explain_-g.rst_
  125. .. |Add_-h| unicode:: 0x20 .. just an invisible code
  126. .. include:: explain_-h.rst_
  127. .. include:: explain_-icols.rst_
  128. .. include:: explain_-qi.rst_
  129. .. include:: explain_help.rst_
  130. .. include:: explain_precision.rst_
  131. Examples
  132. --------
  133. .. include:: explain_example.rst_
  134. Suppose data.g is gravity data in mGal, sampled every 1.5 km. To write
  135. its power spectrum, in mGal\*\*2-km, to the file data.xpower, use
  136. ::
  137. gmt spectrum1d data.g -S256 -D1.5 -Ndata
  138. Suppose in addition to data.g you have data.t, which is topography in
  139. meters sampled at the same points as data.g. To estimate various
  140. features of the transfer function, considering data.t as input and
  141. data.g as output, use
  142. ::
  143. paste data.t data.g | gmt spectrum1d -S256 -D1.5 -Ndata -C > results.txt
  144. Tutorial
  145. --------
  146. The output of spectrum1d is in units of power spectral density, and so to get units
  147. of data-squared you must divide by delta_t, where delta_t is the sample spacing.
  148. (There may be a factor of 2 pi somewhere, also. If you want to be sure of the
  149. normalization, you can determine a scale factor from Parseval's theorem: the sum of
  150. the squares of your input data should equal the sum of the squares of the outputs
  151. from spectrum1d, if you are simply trying to get a periodogram. [See below.])
  152. Suppose we simply take a data set, x(t), and compute the discrete Fourier transform
  153. (DFT) of the entire data set in one go. Call this X(f). Then suppose we form X(f)
  154. times the complex conjugate of X(f).
  155. P_raw(f) = X(f) * X'(f), where the ' indicates complex conjugation.
  156. P_raw is called the periodogram. The sum of the samples of the periodogram equals the
  157. sum of the samples of the squares of x(t), by Parseval's theorem. (If you use a DFT
  158. subroutine on a computer, usually the sum of P_raw equals the sum of x-squared, times M,
  159. where M is the number of samples in x(t).)
  160. Each estimate of X(f) is now formed by a weighted linear combination of all of the
  161. x(t) values. (The weights are sometimes called "twiddle factors" in the DFT literature.)
  162. So, no matter what the probability distribution for the x(t) values is, the probability
  163. distribution for the X(f) values approaches [complex] Gaussian, by the Central Limit
  164. Theorem. This means that the probability distribution for P_raw(f) approaches chi-squared
  165. with two degrees of freedom. That reduces to an exponential distribution, and the
  166. variance of the estimate of P_raw is proportional to the square of the mean, that is,
  167. the expected value of P_raw.
  168. In practice if we form P_raw, the estimates are hopelessly noisy. Thus P_raw is not useful,
  169. and we need to do some kind of smoothing or averaging to get a useful estimate, P_useful(f).
  170. There are several different ways to do this in the literature. One is to form P_raw and
  171. then smooth it. Another is to form the auto-covariance function of x(t), smooth, taper and
  172. shape it, and then take the Fourier transform of the smoothed, tapered and shaped auto-covariance.
  173. Another is to form a parametric model for the auto-correlation structure in x(t), then compute
  174. the spectrum of that model. This last approach is what is done in what is called the
  175. "maximum entropy" or "Berg" or "Box-Jenkins" or "ARMA" or "ARIMA" methods.
  176. Welch's method is a tried-and-true method. In his method, you choose a segment length,
  177. **-S**\ *N*, so that estimates will be made from segments of length *N*. The frequency samples
  178. (in cycles per delta_t unit) of your P_useful will then be at *k* /(*N* \* *delta_t*),
  179. where *k* is an integer, and you will get *N* samples (since the spectrum is an even
  180. function of *f*, only *N*/2 of them are really useful). If the length of your entire
  181. data set, x(t), is *M* samples long, then the variance in your P_useful will decrease
  182. in proportion to *N/M*. Thus you need to choose *N* << *M* to get very low noise and
  183. high confidence in P_useful. There is a trade-off here; see below.
  184. There is an additional reduction in variance in that Welch's method uses a Von Hann
  185. spectral window on each sample of length *N*. This reduces side lobe leakage and has
  186. the effect of smoothing the (*N* segment) periodogram as if the X(f) had been
  187. convolved with [1/4, 1/2, 1/4] prior to forming P_useful. But this slightly widens
  188. the spectral bandwidth of each estimate, because the estimate at frequency sample *k*
  189. is now a little correlated with the estimate at frequency sample k+1. (Of course this
  190. would also happen if you simply formed P_raw and then smoothed it.)
  191. Finally, Welch's method also uses overlapped processing. Since the Von Hann window is
  192. large in the middle and tapers to near zero at the ends, only the middle of the segment
  193. of length *N* contributes much to its estimate. Therefore in taking the next segment
  194. of data, we move ahead in the x(t) sequence only *N*/2 points. In this way, the next
  195. segment gets large weight where the segments on either side of it will get little weight,
  196. and vice versa. This doubles the smoothing effect and ensures that (if *N* << *M*)
  197. nearly every point in x(t) contributes with nearly equal weight in the final answer.
  198. Welch's method of spectral estimation has been widely used and widely studied. It is very
  199. reliable and its statistical properties are well understood. It is highly recommended in
  200. such textbooks as "Random Data: Analysis and Measurement Procedures" by Bendat and Piersol.
  201. In all problems of estimating parameters from data, there is a classic trade-off between
  202. resolution and variance. If you want to try to squeeze more resolution out of your data
  203. set, then you have to be willing to accept more noise in the estimates. The same trade-off
  204. is evident here in Welch's method. If you want to have very low noise in the spectral
  205. estimates, then you have to choose *N* << *M*, and this means that you get only *N*
  206. samples of the spectrum, and the longest period that you can resolve is only *N* \* *delta_t*.
  207. So you see that reducing the noise lowers the number of spectral samples and lowers the
  208. longest period. Conversely, if you choose *N* approaching *M*, then you approach the
  209. periodogram with its very bad statistical properties, but you get lots of samples and
  210. a large fundamental period.
  211. The other spectral estimation methods also can do a good job. Welch's method was selected
  212. because the way it works, how one can code it, and its effects on statistical distributions,
  213. resolution, side-lobe leakage, bias, variance, etc. are all easily understood. Some of the
  214. other methods (e.g. Maximum Entropy) tend to hide where some of these trade-offs are
  215. happening inside a "black box".
  216. See Also
  217. --------
  218. :doc:`gmt`, :doc:`grdfft`
  219. References
  220. ----------
  221. Bendat, J. S., and A. G. Piersol, 1986, Random Data, 2nd revised ed., John Wiley & Sons.
  222. Welch, P. D., 1967, The use of Fast Fourier Transform for the estimation
  223. of power spectra: a method based on time averaging over short, modified
  224. periodograms, IEEE Transactions on Audio and Electroacoustics, Vol AU-15, No 2.
Tip!

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

Comments

Loading...