首页 > 解决方案 > 如何绘制正弦波?

问题描述

我是 C++ 编程的新手,我想绘制一个正弦/余弦/方波,但我找不到任何资源来帮助我。

我的目标是产生任何波,然后对该波进行傅立叶变换并产生合成波。

标签: c++11fftwaveform

解决方案


这段代码应该适合你。只需确保在具有graphics.h. 在许多新的 IDEgraphics.h中,默认情况下不会出现,您必须先添加它。

#include <iostream>
#include <conio.h>
#include <graphics.h>
#include <math.h>
using namespace std;

int main(){

initwindow(800,600);
int x,y;
line(0,500,getmaxx(),500); //to draw co-ordinate axes
line(500,0,500,getmaxy());

float pi = 3.14;
for(int i = -360; i < 360 ; i++){
    x = (int)500+i;
    y = (int)500 - sin(i*pi/100)*25;
    putpixel(x,y,WHITE); //to plot points on the graph
}
getch(); //to see the resultant graph
closegraph();

return 0;
} 

推荐阅读