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;
}
相关推荐
IsSh9nj6q12 分钟前
Python全栈应用搭建神器magic-dash .新版本介绍
开发语言·python·dash
Cachel wood34 分钟前
hands-on-modern-rl:动手学强化学习策略梯度reinforce
开发语言·python
wuminyu42 分钟前
JUC组件逐层剥离与深度剖析
java·linux·c语言·jvm·c++·算法
蓝斯4971 小时前
一碰即传,重构跨设备文件分享体验
开发语言·python·重构
宁风NF1 小时前
JavaScript:内存、垃圾回收、性能优化
开发语言·前端·javascript·学习·性能优化·es6
ShuiShenHuoLe1 小时前
Go html/template 使用入门
开发语言·golang·html
geovindu1 小时前
java: Gale-Shapley Algorithm
java·开发语言·后端·算法
冻柠檬飞冰走茶2 小时前
PTA基础编程题目集 7-34 通讯录的录入与显示(C语言实现)
c语言·开发语言·数据结构·算法
星核0penstarry2 小时前
DeepSeek-V4-Flash 正式公测:大模型行业进入「极速平价普惠时代」
java·开发语言·人工智能