博客
关于我
离散波形的产生方法--正弦、余弦、三角波、方波、锯齿波
阅读量:535 次
发布时间:2019-03-07

本文共 1633 字,大约阅读时间需要 5 分钟。

1.正弦波

int GenSineWave(int numElements, float64 amplitude, float64 frequency, float64 *phase, float64 sineWave[])
{
    int i=1;
    for(;i<=numElements;++i)
         sineWave[i-1] = amplitude*sin(PI/180.0*(*phase+360.0*frequency*i));
    *phase = fmod(*phase+frequency*360.0*numElements,360.0);
    return 0;
}

注:frequency=1/numElements;

2.方波

int GenSquareWave(int numElements, float64 amplitude, float64 frequency, float64 *phase, float64 dutyCycle, float64 squareWave[])

{
    int i=0;

    for(;i<numElements;++i) 

    {
        float64    phase_i=fmod(*phase+360.0*frequency*i,360.0);
        
        squareWave[i] = phase_i/360.0<=dutyCycle/100.0 ? amplitude : -amplitude;
    }
    *phase = fmod(*phase+frequency*360.0*numElements,360.0);
    return 0;
}

3.锯齿波

int GenSawtoothWave(int numElements, float64 amplitude, float64 frequency, float64 *phase, float64 sawtoothWave[])
{
    int i=0;

    for(;i<numElements;++i) {

        float64    phase_i=fmod(*phase+360.0*frequency*i,360.0);
        float64    percentPeriod=phase_i/360.0;
        float64    dat=amplitude*2.0*percentPeriod;

        sawtoothWave[i] = percentPeriod<=0.5 ? dat : dat - 2.0*amplitude;

    }
    *phase = fmod(*phase+frequency*360.0*numElements,360.0);
    
    return 0;
}
4.三角波

int GenTriangleWave(int numElements, float64 amplitude, float64 frequency, float64 *phase, float64 triangleWave[])

{
    int i=0;

    for(;i<numElements;++i) {

        float64    phase_i=fmod(*phase+360.0*frequency*i,360.0);
        float64    percentPeriod=phase_i/360.0;
        float64    dat=amplitude*4.0*percentPeriod;

        if( percentPeriod<=0.25 )

            triangleWave[i] = dat;
        else if( percentPeriod<=0.75 )
            triangleWave[i] = 2.0*amplitude - dat;
        else
            triangleWave[i] = dat - 4.0*amplitude;
    }
    *phase = fmod(*phase+frequency*360.0*numElements,360.0);
    
    return 0;
}

转载地址:http://hpwnz.baihongyu.com/

你可能感兴趣的文章
mysql 转义字符用法_MySql 转义字符的使用说明
查看>>
mysql 输入密码秒退
查看>>
mysql 递归查找父节点_MySQL递归查询树状表的子节点、父节点具体实现
查看>>
mysql 通过查看mysql 配置参数、状态来优化你的mysql
查看>>
mysql 里对root及普通用户赋权及更改密码的一些命令
查看>>
Mysql 重置自增列的开始序号
查看>>
mysql 锁机制 mvcc_Mysql性能优化-事务、锁和MVCC
查看>>
MySQL 错误
查看>>
mysql 随机数 rand使用
查看>>
MySQL 面试题汇总
查看>>
MySQL 面试,必须掌握的 8 大核心点
查看>>
MySQL 高可用性之keepalived+mysql双主
查看>>
MySQL 高性能优化规范建议
查看>>
mysql 默认事务隔离级别下锁分析
查看>>
Mysql--逻辑架构
查看>>
MySql-2019-4-21-复习
查看>>
mysql-5.6.17-win32免安装版配置
查看>>
mysql-5.7.18安装
查看>>
MySQL-Buffer的应用
查看>>
mysql-cluster 安装篇(1)---简介
查看>>