【发布时间】:2021-09-07 07:36:15
【问题描述】:
我是 C++ 编程新手,我想绘制正弦/余弦/方波,但找不到任何资源来帮助我。
我的目标是产生任何波,然后对该波进行傅立叶变换并产生合成波。
【问题讨论】:
-
绘图可以使用OpenGL,FFT部分可以使用KissFFT等FFT包。
我是 C++ 编程新手,我想绘制正弦/余弦/方波,但找不到任何资源来帮助我。
我的目标是产生任何波,然后对该波进行傅立叶变换并产生合成波。
【问题讨论】:
此代码应该适合您。只需确保在具有 graphics.h 的 IDE 上运行它。在许多新的 IDE 中,graphics.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;
}
【讨论】: