Seasonal plot is not smooth -- where am I going wrong?

Howdy friends,

I am attempting to plot the seasonal variability within the GPS data so that, in the future, I am able to have a de-trended/residual plot of GPS positions.

Shown here is only the vertical component of a single GPS stations called AGMT that is located near Barstow, CA - just for reference.

The general method for these types of problems, for the unfamiliar, is a least squares fit where the d = Gm matrix is utilized and the G matrix contains the modeled variables.

These modeled parameters are fit against the actual data points.

The problem I’m having is that I’m not sure where I’m going wrong with the methodology? The orange line should not be as choppy as it is, and I’ve been trying to figure out where I am going wrong. I’m sure it’s a simple solution that I’m just blind too since I’ve been staring at this for hours now…

# laod removed velocity components
d_vert = round.(agmt_df.vert_m_frac_north_RESE_function, digits=6) 

# modeled variables for G matrix
uno = ones(length(agmt_raw_t))
mean_vert = mean(d_vert)
A_vert = (d_vert) .- mean_vert
A_cos_vert = A_vert .* cos.((2 * π) .* agmt_raw_t) 
B_sin_vert = A_vert .* sin.((2 *π) .* agmt_raw_t)

# create G matrix 
G = [uno agmt_raw_t A_cos_vert B_sin_vert]
G = convert(Matrix{Float64}, G)
Gg = inv(G' * G) * G'

m_est_vert = Gg * d_vert

σ_vert = agmt_df.vert_sigma_m

covar_d_vert = Diagonal(σ_vert .^ 2)

covar_matrix_v = Gg * covar_d_vert * Gg'

d_pred_vert = G * m_est_vert

plot(xlabel = "years", ylabel = "vertical", legend= true,  dpi = 750);
plot!(minorgrid = true);
plot!(agmt_yr, d_vert, label = "data points", seriestype =:scatter, mc =:blue3, ms =:2);
plot!(agmt_yr, d_pred_vert, label = "annual trend", linewidth = 2)

l suspect it may have to do something with how I am calculating the amplitude for both the sin and cos functions here? But I’m not sure how I would calculate the amplitude…

Does anyone have any insights or can see where I’m going wrong with my implementation of the code? Any help is greatly appreciated! :face_with_monocle:


Okay, so my suspicion was correct that the amplitude I was using was incorrect. It’s obvious, looking back, that the constant in front of the cos and sin functions needs to be, well, constant. I had it such that the amplitude was varying with each line operation.

I found the actual annual and semi-annual amplitudes from the USGS website. However, I am still lost one how to calculate these amplitudes from the GPS data? Because the process I used in the code above was obviously incorrect. Thanks, again, for any help that anyone can provide!