Skip to content

Instantly share code, notes, and snippets.

@MHenderson
Created May 16, 2017 13:51
Show Gist options
  • Save MHenderson/2b1c8a43c12a0ecec5ef81f97bc8982f to your computer and use it in GitHub Desktop.
Save MHenderson/2b1c8a43c12a0ecec5ef81f97bc8982f to your computer and use it in GitHub Desktop.
Use SAX for key recognition
---
title: "SAX for Key Recognition"
author: "Matthew Henderson"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
html_document:
toc: yes
toc_float: true
fig_caption: no
theme: sandstone
code_folding: show
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
data <- read.delim("data.txt", header = FALSE, sep = "\t")
n <- nrow(data)
minX <- min(data$V2)
maxX <- max(data$V2)
minY <- min(data$V1)
maxY <- max(data$V1)
plot(0, xlim = c(minX, maxX), ylim = c(minY, maxY))
lines(x = data$V2, y = data$V1)
```
```{r}
xx <- lowess(data$V1[11:50], f = 0.05)
plot(xx$y, type = "l")
```
```{r}
result <- seewave::SAX(
xx$y,
alphabet_size = 5,
PAA_number = 8,
breakpoints = seq(170, 200, 10)
)
match(result, letters)
```
118.92764 5.78641
137.92097 9.04019
155.15894 25.83465
163.11984 34.92509
165.92883 39.41948
167.60094 67.65882
173.04701 84.06547
178.62163 93.72601
188.62697 108.98995
197.94444 116.93092
198.89563 129.93449
190.51662 157.30261
197.54214 160.18172
201.3793 169.84946
205.65309 193.13293
202.99301 206.20212
186.0 219.0
183.96339 223.46907
182.68979 241.97739
181.74179 254.98117
177.58154 278.95142
170.31758 291.45828
177.52794 307.70718
185.29904 309.96771
189.39218 329.87018
188.82559 342.91812
192.0 350.0
194.93484 367.01984
200.3571 372.67914
203.21013 390.12686
208.64738 393.21121
203.64621 401.31207
185.42871 411.827
180.0 419.0
170.30928 438.08804
172.99106 459.1286
175.71289 459.56665
178.60001 479.70001
184.57655 494.60114
187.16396 502.8862
196.09999 517.79999
199.70001 519.59998
209.38345 525.71844
204.0 540.0
203.23799 550.92261
203.75002 559.25
202.3696 562.07434
200.49327 579.2608
202.53951 583.237
204.2054 593.06519
204.25293 600.91498
203.78789 606.26367
199.86903 622.07635
201.89775 638.07452
201.50954 642.28571
200.21155 660.8548
206.39099 667.54327
200.80638 685.5589
203.77078 687.37085
205.25002 691.75
203.60558 711.24377
205.9472 715.03265
205.66669 723.66663
204.49892 739.95581
205.64421 749.4765
203.60558 766.24377
205.9472 770.03265
206.0 773.0
208.97525 788.02533
203.74184 801.00549
206.45993 814.67682
207.03262 830.86176
207.89775 845.07452
208.97926 863.89087
206.86627 872.28687
202.17694 890.24066
205.71094 907.75061
207.06993 911.62469
209.16525 922.34387
209.94806 935.03265
204.91095 954.73639
212.21013 966.12683
213.07899 970.2489
214.48485 981.83881
214.00243 998.60236
215.3432 1008.93115
215.25609 1010.84052
213.83821 1018.95416
194.782 1004.35272
185.90683 1001.3335
177.88976 1003.41046
169.92702 1001.27173
154.02675 1001.80481
154.03279 1005.80817
136.96202 1005.14496
127.93523 1003.92975
118.18668 1011.39813
99.0 1011.125
84.0 1011.125
78.6497 1011.45776
61.14947 1012.29395
43.80001 1017.59998
22.01132 1018.92328
3.96184 1016.25848
14.64044 984.17395
13.92445 981.49323
19.77925 964.22076
15.88366 955.85089
7.68934 940.75
7.49998 921.5
8.42376 904.64124
8.99999 888.0
7.80545 873.17249
7.74672 867.16107
9.56181 859.82886
10.93088 846.22919
8.60001 837.37085
8.47638 816.29443
10.87089 801.99164
9.10225 784.07452
8.449 765.82129
18.58 750.24353
15.54322 738.82147
5.62507 741.11462
10.16875 731.9649
7.61077 715.01337
11.77677 705.16272
5.27605 683.51361
7.63882 660.98621
16.53671 640.6087
11.10355 615.95709
9.75001 612.68933
14.72522 587.33521
7.13355 581.99866
7.0 558.5
6.90985 531.00037
4.76398 528.00513
3.95406 526.25696
5.24584 522.24396
25.07063 496.68433
32.70572 484.88245
35.04789 479.01913
40.14802 470.01993
50.9925 455.99078
45.21734 450.13336
42.81758 443.18347
45.20015 423.70438
34.10223 424.07452
27.10355 417.95712
23.2278 412.99896
15.18175 399.2226
10.10935 402.85855
6.84559 404.28403
5.53954 400.45987
4.3543 394.15887
11.99243 376.34726
17.5 361.0
14.90124 343.2363
25.57335 321.87469
24.51262 316.82266
31.43815 296.01477
41.33462 282.01141
39.87738 269.97137
39.0 262.0
29.78673 252.78477
29.06997 247.00249
26.23671 228.34186
24.55418 226.47923
17.10001 217.79999
8.13294 209.17714
3.91656 193.6133
11.04451 178.82153
22.16955 166.68427
19.60096 159.00328
18.04727 143.57306
9.43857 128.99821
13.18526 123.43065
19.73464 116.97533
27.68424 111.42051
33.99122 107.98389
35.00408 94.24229
47.91251 75.98496
57.86757 60.94791
62.96038 48.0046
67.98343 38.99852
73.0 25.0
75.1883 20.60399
79.0 19.0
99.8 14.0
118.92764 5.78641
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment