#include <stdio.h>
#include <math.h>
#include <stdint.h>
#define SAMPLE_POINT_NUM (200) /* 需要生成的点的个数 */
#define SINE_MAX (255) /* sin 函数幅值 */
#define PI (3.1415926) /* 数学中的常量:Π */
#define POINT_BUFFER_LEN (400)
int generate_data[POINT_BUFFER_LEN]; /* 生成的数据放在此数组中 */
void get_sin_data(unsigned int point)
{
unsigned int i = 0;
float step = 0.0;
float data = 0.0;
int tem = 0;
step = 1 * PI / point; /* 将 sin 函数从 [0-2Π] 等分为 N 个点,则每个点的步长为 2Π/point_num */
for (i = 0; i < point; i++)
{
data = SINE_MAX * sin(step * i);
tem = (int)data;
generate_data[i] = tem;
}
}
int main(int argc, char *argv[])
{
get_sin_data(SAMPLE_POINT_NUM);
for (int i = 0; i < SAMPLE_POINT_NUM; i++)
{
printf("%d ,", generate_data[i]);
}
printf("\r\n");
return 0;
}