I needed a small routine to generate a cyclic waveform resembling sin(x) to test a CODEC board. This is what I came up with:

float pseudoSin(float x)
{
return (1.0f-x*x)*x
}

This produces the following waveform over the domain [-1,1]:

The derivative of the function is . The maximum and minimum occur at and , respectively. The function has maximum and minimum values of and .

The amplitude normalisation factor is approximately 2.5981. For completeness, here is the error of the function with respect to a real sin(x):

The error maximum is about 16.3%.

### Like this:

Like Loading...

*Related*

Pseudo sinusoidal waveform II | Niels Moseley's bloggy bits