PWM 正玄波形 通过C语言生成

复制代码
#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;
}
相关推荐
Mr YiRan1 小时前
C++面向对象继承与操作符重载
开发语言·c++·算法
一只鹿鹿鹿3 小时前
智慧水利一体化建设方案
大数据·运维·开发语言·数据库·物联网
没有医保李先生5 小时前
字节对齐的总结
java·开发语言
Elastic 中国社区官方博客5 小时前
使用 Elastic 进行网络监控:统一网络可观测性
大数据·开发语言·网络·人工智能·elasticsearch·搜索引擎·全文检索
Codefengfeng5 小时前
Python Base环境中加包的方法
开发语言·python
清水白石0085 小时前
《Python 编程全景解析:从核心精要到测试替身(Test Doubles)五大武器的实战淬炼》
开发语言·python
六件套是我7 小时前
无法访问org.springframeword.beans.factory.annotation.Value
java·开发语言·spring boot
S-码农7 小时前
Linux ——条件变量
linux·开发语言
清水白石0087 小时前
《Python 编程全景解析:从核心精要到 Hypothesis 属性基测试的边界探索》
开发语言·python