【问题标题】:How to plot sine wave?如何绘制正弦波?
【发布时间】:2021-09-07 07:36:15
【问题描述】:

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

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

【问题讨论】:

  • 绘图可以使用OpenGL,FFT部分可以使用KissFFT等FFT包。

标签: c++11 fft waveform


【解决方案1】:

此代码应该适合您。只需确保在具有 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;
} 

【讨论】:

  • 是的,我正在使用 Visual Studios。我看看能不能找到获取 graphics.h 文件的方法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-22
  • 1970-01-01
  • 1970-01-01
  • 2012-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多