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
Since you try to generate a signal, i think use a differential equation should not be a bad idea ! it give something like that
#include
#include
#define DT (0.01f) //1/s
#define W0 (3) //rad/s
int main(void) {
float a = 0.0f;
float b = DT * W0;
float tmp;
for (int i = 0; i < 400; i++) {
tmp = (1 / (1 + (DT * DT * W0 * W0))) * (2 * a - b);
b = a;
a = tmp;
printf("%f\n", tmp);
}
}
Still set the amplitude and frequency of the signal is a pain in the neck :/