I have a function $f(t)$ that is piecewise constant: $$ f(t) = a_i \forall t\in[t_i,t_{i+1}) $$ with $n$ values $a_0, a_1, ..., a_{n-1}$, and $n+1$ values $t_0, t_1, ..., t_n$.
I want to approximate this function with a function $g(t)$ that is continuous, with the condition that the average of $g(t)$ equals that of $f(t)$ in each piece: $$ \int_{t_i}^{t_{i+1}}g(t) dt = a_i\cdot(t_{i+1}-t_i) $$
In addition, I'd like $g$ to have no structure (oscillations) at a timescale below that of the individual pieces. For example: if $a_{i-1} < a_i < a_{i+1}$, I'd like $g$ to have no extremes in $t \in[t_i,t_{i+1})$.
The function $g(t)$ may be a piecewise function (i.e., existing as a different equation in each piece, and not necessarily differentiable in the $t$-values $t_0, t_i, ...$).
I can imagine several ways of doing this, but before I reinvent the wheel, I thought I'd ask here if there is a 'common' way to do this. I find many ways to do the reverse, but maybe I'm not using the correct search terms, as I don't know what the mathematical term for this process is.
EDIT
I've added some initial implementations as an answer to this question.
However, what I think would be the best way of getting a good function $g$, is using a physical analogue; but I've started a seperate question for that here.




I think is difficult, or perhaps impossible, to avoid extrema of the built function.
Take $$ y_0=a_0,\quad y_i=\frac{a_{i-1}+a_i}{2},\quad y_n=a_{n-1} $$ then take a quadratic that pass through the required ends, $$ f(x)=y_i\frac{x-x_i}{x_{i+1}-x_i}+y_{i+1}\frac{x-x_{i+1}}{x_i-x_{i+1}}+A_i(x-x_i)(x-x_{i+1}),\quad x_i\leq x\leq x_{i+1} $$ with $A_i$ such that the area is the right one $$ \int_{x_i}^{x_{i+1}}f(x)dx=\frac{1}{6}[3(y_i+y_{i+1})-A_i(x_{i+1}-x_i)^2]=a_i $$ Example: