Generate sine signal in C without using the standard function

后端 未结 11 903
情歌与酒
情歌与酒 2021-02-02 09:41

I want to generate a sine signal in C without using the standard function sin() in order to trigger sine shaped changes in the brightness of a LED. My basic idea was to use a lo

11条回答
  •  不要未来只要你来
    2021-02-02 09:48

    Have you considered modelling the portion of the sine curve from [0..PI] as a parabola? If the brightness of the LED is only intended to be observed by a human eye, the shapes of the curves ought to be similar enough so that little difference would be detected.

    You would just need to figure out the appropriate equation to describe it.

    Hmmm, ...

    Vertex at (PI/2, 1)

    X-axis intersections at (0, 0) and (PI, 0)

    f(x) = 1 - K * (x - PI/2) * (x - PI/2)
    

    Where K would be ...

    K = 4 / (PI * PI)
    

提交回复
热议问题