Skip to content

Commit

Permalink
Fix detrending
Browse files Browse the repository at this point in the history
  • Loading branch information
tclements committed Apr 17, 2019
1 parent a8f15ab commit cb40d87
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/ArrayFuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ end
detrend(A::AbstractArray{<:Union{Float32,Float64},1}) = (U = deepcopy(A);
detrend!(U);return U)

"""
detrend!(A)
Remove linear trend from columns of `X` using least-squares regression.
"""
function detrend!(X::AbstractArray{<:Union{Float32,Float64},2})
M,N = size(X)
A = ones(M,2)
A[:,1] = Array(1:N) ./ N
A[:,1] = Array(1:M) ./ M
for ii = 1:N
coeff = lstsq(A,X[:,ii])
X[:,ii] = X[:,ii] .- A *coeff
Expand All @@ -52,7 +57,7 @@ detrend(A::AbstractArray{<:Union{Float32,Float64},2}) = (U = deepcopy(A);
"""
demean!(A)
Remove mean from columns of array `A`.
Remove mean from array `A`.
"""
function demean!(A::AbstractArray{<:Union{Float32,Float64},1})
μ = mean(A)
Expand All @@ -64,6 +69,11 @@ end
demean(A::AbstractArray{<:Union{Float32,Float64},1}) = (U = deepcopy(A);
demean!(U);return U)

"""
demean!(A)
Remove mean from columns of array `A`.
"""
function demean!(A::AbstractArray{<:Union{Float32,Float64},2})
M,N = size(A)
for ii = 1:N
Expand Down

0 comments on commit cb40d87

Please sign in to comment.