for i=1:length(m) # loop over the various cluster sizes
for k=1:N-2*m[i] # implements the summation in the Allan Variance equation (eqn. 8 in ref 1.
sigma2(i,:) = sigma2(i,:) + (theta(k+2*m[i],:) - 2*theta(k+m[i],:) + theta(k,:)).^2
end
end
sigma2 = sigma2./repmat((2*T.^2.*(N-2*m)),1,M)
I get the error message
ERROR: LoadError: MethodError: no method matching ./(::#sigma2#1, ::Array{Float64,2})
Closest candidates are:
./{T}(!Matched::Number, ::AbstractArray{T,N}) at arraymath.jl:67
./(!Matched::SparseMatrixCSC{Tv,Ti<:Integer}, ::Array{T,N}) at sparse/sparsematrix.jl:1724
./(!Matched::AbstractArray{T,N}, ::AbstractArray{T,N}) at broadcast.jl:302
for i=1:length(m) # loop over the various cluster sizes
for k=1:N-2*m[i] # implements the summation in the Allan Variance equation (eqn. 8 in ref 1.
sigma2[i,:] = sigma2[i,:] + (theta[k+2*m[i],:] - 2*theta[k+m[i],:] + theta[k,:]).^2
end
end
throws
ERROR: LoadError: ArgumentError: invalid index: 3.0
in macro expansion at ./multidimensional.jl:294 [inlined]
in _unsafe_getindex at ./multidimensional.jl:291 [inlined]
in _getindex at ./multidimensional.jl:271 [inlined]
in getindex at ./abstractarray.jl:760 [inlined]
Hmmm, somehow it’s not mentioned there. You cannot index an array with floating point numbers. Without the full code it’s impossible to tell what you are doing but it’s likely that m is not an integer array.
# ********* FUNCTION DEFINITIONS ********
function allan(omega,fs,pts)
# omega = sample data. Unit should be in radians/sec
# fs = sample frequency
# pts = number of logarithmically spaced points
# Determine the size of the output data set
(N,M) = size(omega)
# determine largest bin size
n = 2.^(0:floor(log2(N/2)))'
# Select the last element of the vector (the largest bin size)
maxN = n[end]
endLogInc = log10(maxN)
# m is chosen arbitrarily
m = unique(ceil(logspace(0,endLogInc,pts)))' # create log spaced vector average factor
# t0 = sample interval
t0 = 1/fs
# T = length of time of each cluster (tau)
T = m*t0
# Integrate samples over time to obtain output angle θ
theta = cumsum(omega)/fs
# Create an array of dimensions (cluster periods) X ( No. of variables)
sigma2 = zeros(length(T),M)
for i=1:length(m) # loop over the various cluster sizes
for k=1:N-2*m[i] # implements the summation in the Allan Variance equation (eqn. 8 in ref 1.
sigma2[i,:] = sigma2[i,:] + (theta[k+2*m[i],:] - 2*theta[k+m[i],:] + theta[k,:]).^2
end
end
sigma2 = sigma2./repmat((2*T.^2.*(N-2*m)),1,M)
sigma = sqrt(sigma2) # The Allan Deviation
return sigma
end
# ********* END OF FUNCTION DEFINITIONS *****
# ********* MAIN PROGRAM ********
file=open("sensor_data.dat", "r")
data = readdlm(file,' ')
close(file)
fs = 50 # 50 Hz Sample rate
pts = 5 # No. of logarithmically spaced points
Sigma = allan(data, fs, pts)
println("Sigma= ", Sigma)
# ********* END OF MAIN PROGRAM ********
Returns a tuple containing the dimensions of A. Optionally you can specify the dimension(s) you want the length of, and get
the length of that dimension, or a tuple of the lengths of dimensions you asked for.
julia> A = ones(2,3,4);
julia> size(A, 2)
3
julia> size(A,3,2)
(4,3)
Showing the output of size should help you debug this problem.