Read data:
tab=read.csv("~/Downloads/wiry_500_EOpen.csv")
x = tab$x
We can plot the signal:
plot(x,type="l")
We can now calculate the autocorrelation of this signal. Autocorrelation of a signal is just the correlation of a signal with it self for some specified lag. So autocorrelation for lag \(k\) is: \[A_k = \frac{1}{C}\sum_{j=1}^{n-k}x_jx_{j+k}\] It is normed so that autocorrelation for zero lag is 1. We can plot it with acf function:
acf(x,lag.max=5000)
You can easily see the dominant frequency, because it will correspond to the lag giving first maximum of autocorrelation. An alternative thing we can imagine is calculating correlation between our signal and a model wave (a fourier transform): \[F(h) = \sum_{j=1}^n x_je^{i\frac{j}{h}2\pi}\] Again, this should have a a highest value for the main frequency. The problem is it can be quite wiggly, so not always it’s easy to find the maximum.
F = function(lag) Mod(sum(x*exp(2i*pi*1:length(x)/lag)))
lag = seq(0,5000,len=200)
plot(lag, sapply(lag, F),type="l",xlab="Wave length",ylab="F")
On the plus side, we can use optimization functions to find the maximum more precisely:
ret = optimize(F, interval = c(3000,5000), maximum = TRUE)
print(ret$maximum)
## [1] 3679.058