Skip to content

Commit 38ade81

Browse files
committed
Add one tutorial
1 parent 680bef2 commit 38ade81

File tree

19 files changed

+948
-2
lines changed

19 files changed

+948
-2
lines changed

documentation/utilities/mat2ds.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ does not need explicit coordinates to place the text.
5050

5151
- `geom`: The data geometry. By default, we set `wkbUnknown` but try to do some basic guess.
5252

53-
- `proj` or `proj4`: A proj4 string for dataset CRS (Coordinate Reference System).
53+
- `proj` or `proj4`: A proj4 string for dataset CRS (Coordinate Reference System). Default is empty.
54+
To set it to lon,lat in WGS84 use ``proj=prj4WGS84``
5455

55-
- `wkt`: A WKT (Well Known Text) CRS.
56+
- `wkt`: A WKT (Well Known Text) CRS. Default is empty.
57+
58+
- `epsg`: An integer EPSG code. _e.g._ ``epsg=4326`` for lon,lat in WGS84. Default is 0.
5659

5760
- `colnames`: Optional string vector with names for each column of `mat`.
5861

tutorials.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,14 @@
144144
~~~</a>~~~
145145
@@
146146

147+
@@box
148+
~~~<a class="boxlink" href="signal/signal/">~~~
149+
@@title Signal Processing@@
150+
@@box-content
151+
~~~
152+
<img src="/tutorials/signal/tilelogo.jpg">
153+
~~~
154+
@@
155+
~~~</a>~~~
156+
@@
147157
@@

tutorials/signal.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Signal processing
2+
3+
{{list_folder_with_images signal}}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Find Periodicity in Chlorophyl time series
2+
3+
Another example on how to detect periodicities in a Chlorophyl time series.
4+
5+
Load the data file with the chlorophyll concentration file.
6+
7+
\begin{examplefig}{}
8+
```julia
9+
using GMT
10+
11+
D1 = gmtread(TESTSDIR * "assets/cmems_mod_blk_bgc-plankton.csv");
12+
viz(D1, figsize=(15,6))
13+
```
14+
\end{examplefig}
15+
16+
17+
Create the _lags_ vector. This case is simple as data points were collected one every day
18+
(less the missing days), so we use a lag interval of 1, extended over 3 years.
19+
20+
```julia
21+
lags = 0:3*365;
22+
```
23+
24+
Now, compute the autocorrelation of the data using the `autocor` function. But, we want to pass it
25+
**only** the chlorophyll data that is stored in the second column of **D1**
26+
27+
```julia
28+
ac = GMT.autocor(D1[:,2], lags)
29+
```
30+
31+
Show the autocorrelation values in a plot. The x-axis represent be the lags,
32+
and the y-axis should be the autocorrelation value.
33+
34+
35+
\begin{examplefig}{}
36+
```julia
37+
using GMT # Hide
38+
D1 = gmtread(TESTSDIR * "assets/cmems_mod_blk_bgc-plankton.csv"); # Hide
39+
lags = 0:3*365; # Hide
40+
41+
ac = GMT.autocor(D1[:,2], lags)
42+
viz(ac, figsize=(15,6), grid=true)
43+
```
44+
\end{examplefig}
29.5 KB
Loading
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Find Periodicity Using Autocorrelation
2+
3+
([Example](https://www.mathworks.com/help/signal/ug/find-periodicity-using-autocorrelation.html) from Matlab documentation)
4+
5+
The autocorrelation sequence of a periodic signal has the same cyclic characteristics as the signal itself. Thus, autocorrelation can help verify the presence of cycles and determine their durations.
6+
7+
Consider a set of temperature data collected by a thermometer inside an office building.
8+
The device takes a reading every half hour for four months. Load the data and plot it.
9+
Subtract the mean to concentrate on temperature fluctuations. Convert the temperature to degrees Celsius.
10+
Measure time in days. The sample rate is thus 2 measurements/hour × 24 hours/day = 48 measurements/day.
11+
12+
13+
\begin{examplefig}{}
14+
```julia
15+
using GMT
16+
17+
D = gmtread(TESTSDIR * "assets/temps.dat");
18+
tempC = (D-32)*5/9;
19+
tempnorm = tempC - mean(tempC);
20+
fs = 2*24;
21+
t = (0:length(tempnorm) - 1)/fs;
22+
plot(t,tempnorm, xlabel="Time (days)", ylabel="Temperature (°C)", title="Temperature time series", figsize=(15, 6), show=true)
23+
```
24+
\end{examplefig}
25+
26+
The temperature does seem to oscillate, but the lengths of the cycles cannot be read out easily.
27+
28+
Compute the autocorrelation of the temperature such that it is unity at zero lag. Restrict the
29+
positive and negative lags to three weeks. Note the double periodicity of the signal.
30+
31+
32+
\begin{examplefig}{}
33+
```julia
34+
using GMT # Hide
35+
D = gmtread(TESTSDIR * "assets/temps.dat"); # Hide
36+
tempC = (D-32)*5/9; # Hide
37+
tempnorm = tempC - mean(tempC);# Hide
38+
fs = 2*24;# Hide
39+
40+
lags = 0:3*7*fs;
41+
ac = GMT.autocor(tempnorm, lags);
42+
locs = findpeaks(ac);
43+
plot(lags/fs, ac, figsize=(15, 7))
44+
scatter!(lags[locs]/fs,ac[locs], show=1)
45+
```
46+
\end{examplefig}
47+
48+
Determine the short and long periods by finding the peak locations and determining the average time differences between them.
49+
50+
To find the long period, restrict findpeaks to look for peaks separated by more than the short period and with a minimum height of 0.3.
51+
52+
\begin{examplefig}{}
53+
```julia
54+
using GMT # Hide
55+
56+
D = gmtread(TESTSDIR * "assets/temps.dat"); # Hide
57+
tempC = (D-32)*5/9; # Hide
58+
tempnorm = tempC-mean(tempC);# Hide
59+
fs = 2*24;# Hide
60+
lags = 0:3*7*fs; # Hide
61+
ac = GMT.autocor(tempnorm, lags);# Hide
62+
locs = findpeaks(ac);# Hide
63+
64+
shortT = mean(diff(sort(locs))) / fs
65+
locs_long = findpeaks(ac, min_dist=ceil(shortT)*fs, min_height=0.3);
66+
longT = mean(diff(locs_long))/fs
67+
plot(lags/fs, ac, figsize=(15, 7))
68+
scatter!(lags[locs]/fs,ac[locs], fill=:red)
69+
scatter!(lags[locs_long]/fs, ac[locs_long], fill=:blue, show=1)
70+
```
71+
\end{examplefig}
72+
73+
To a very good approximation, the autocorrelation oscillates both daily and weekly.
74+
This is to be expected, since the temperature in the building is higher when people
75+
are at work and lower at nights and on weekends.
76+
16 KB
Loading

0 commit comments

Comments
 (0)