I have read a couple of posts on least squares regression of a sine wave, which is essentially what I am trying to do.

(Least squares regression of sine wave; Method of least squares question with trigonometric function)

However, they both include reference to bilinear regression as part of the solution, but unfortunately don't cover that part. I have searched around the net but every result seems to use very complicated notation that I cannot follow. Can someone please give me a simple example of bilinear regression in the context of determining the coefficients of a best fit sine function?


EDIT: To add a bit more info, I have test data collected whilst driving a vehicle around a circle at increasing speed and measuring its response. This particular query relates to the roll behaviour, which increases almost linearly with lateral acceleration. However, the roll data also contains a once per circle variation due to gravity, which is the sinusoid I am trying to fit to so it can be removed.

If I plot roll angle against circles (yaw angle/360), then the variation is obvious. I've tried FFT and DFT techniques to remove the once per circle variation but they are not robust. My best guess at the reason why is that the results are being affected by the underlying trend in the data, which isn't periodic. Even after subtracting a third order polynomial from the data, the results are still hugely sensitive to small differences between runs.

So, I have changed tack and am trying a best fit sinusoid method, hence my post here.

  • $\begingroup$ If you joint to the question a representative example of data you have more chances to have an answer with clear explanation how to proceed. $\endgroup$
    – JJacquelin
    Commented Sep 23, 2022 at 7:29
  • $\begingroup$ Yes, I appreciate that. However, my datasets have two channels in it that are over 10k points, hence I'm looking for some discussion to get me going. I will add some extra information though. $\endgroup$ Commented Sep 23, 2022 at 8:09

1 Answer 1


Continuing from the first link Least squares regression of sine wave

you model now looks like

y = A * S + B * C

Where y is your data vector, S, C are the sin and cos vectors, and A, B scalars

A and B are found by projecting y onto S and C respectivly.


A * S = proj_S( y ) "Projection of y onto S"

= [dot(y, S) / dot(S, S)] * S

B * C = proj_C( y )

= [dot(y, C) / dot(C, C)] * C

  • $\begingroup$ Thanks for the response to my post. I have a couple of questions. When projecting vectors, shouldn't the denominator of the fraction be a magnitude rather than a magnitude squared? Is this bilinear regression? I expected there to be minimising of residuals and so on. $\endgroup$ Commented Sep 30, 2022 at 2:40
  • $\begingroup$ This video runs you through the calculation, duckduckgo.com/… at ~5 minute mark you can see the square, and square root cancel. As for the bilinear regression part, I'm not an expert so if its important perhaps try and verify this, but my understanding is least squares regression in vector space equates to trying to find the cloest vector of the model (S & C) for the measured values (y). Ie the projection is the minimised solution. $\endgroup$
    – acon
    Commented Oct 1, 2022 at 8:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .