Detrending sine waves accurately

I am doing some data analysis where I look at electricity demand over the course of a day, but need to separate the intra-day (constant and periodic) components from daily changes (assumed linear). At its very simplest it boils down to a scenario of a function of the form $y = a t + b \sin n t + c \cos n t$ over the interval $t \in [0,2\pi)$.

The question I have is are there any well recognised algorithms for removing the $t$ component? The problem I am having is that $t$ is not orthogonal to $\sin t$ over the interval $t \in [0, 2\pi)$, so any simple algorithm like doing a matrix regression using QR results in perdioic basis waveforms that are no longer sinusoids.

Are there any special algorithms for removing a ramp from a sinusoid without distorting them? In general I am not doing a full fourier transform, as a day's data has 48 samples but I am in general only interested in the components with at least a 2 hour long cycle.

If $n$ is large enough, linear regression should do the trick. In other words, you can jut consider the residuals of the linear regression.

• True, but I want it to be accurate for any $n$, in particular $n = 1$. – bjem Jul 16 '15 at 5:15