Created
January 22, 2014 19:35
-
-
Save mike-lawrence/8565774 to your computer and use it in GitHub Desktop.
R code for complex demodulation of a time series. Applies complex demodulation to a timeseries twice, once on the signal then once on the reverse of the signal, re-reversing the latter and finally averaging the two to correct for artificial shift induced by the butterworth filter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd = function(s,freq,srate){ | |
x = s*exp(2 * pi * 1i * freq * (1:length(s)) / srate ) | |
zR1 = filter( x = Re(x) , filt = butter(3,freq/srate/2) ) | |
zI1 = filter( x = Im(x) , filt = butter(3,freq/srate/2) ) | |
z1 = 2*sqrt((zR1^2)+(zI1^2)) | |
x = rev(x) | |
zR2 = filter( x = Re(x) , filt = butter(3,freq/srate/2) ) | |
zI2 = filter( x = Im(x) , filt = butter(3,freq/srate/2) ) | |
z2 = 2*sqrt((zR2^2)+(zI2^2)) | |
z = (z1+rev(z2))/2 | |
return(as.numeric(z)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment