Python如何绘制图形正弦波 [英] Python how to plot graph sine wave

查看:82
本文介绍了Python如何绘制图形正弦波的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个信号:

from math import*
Fs=8000
f=500
sample=16
a=[0]*sample
for n in range(sample):
    a[n]=sin(2*pi*f*n/Fs)

如何绘制图形(这个正弦波)?

How can I plot a graph (this sine wave)?

并将 xlabel 的名称创建为电压(V)",将 ylabel 的名称创建为样本(n)"

and create name of xlabel as 'voltage(V)' and ylabel as 'sample(n)'

执行此操作的代码是什么?

What code to do this?

非常感谢您的帮助^_^

推荐答案

  • 使用 np.arange(0, 1, 0.001) 设置 x 轴 以 0.001 为增量给出从 0 到 1 的数组.
    • x = np.arange(0, 1, 0.001) 返回从 0 到 1 的 1000 个点的数组,并且 y = np.sin(2*np.pi*x) 你会得到从 0 到 1 采样 1000 次的正弦波
      • Setting the x-axis with np.arange(0, 1, 0.001) gives an array from 0 to 1 in 0.001 increments.
        • x = np.arange(0, 1, 0.001) returns an array of 1000 points from 0 to 1, and y = np.sin(2*np.pi*x) you will get the sin wave from 0 to 1 sampled 1000 times
        • 我希望这会有所帮助:

          import matplotlib.pyplot as plt
          import numpy as np
          
          
          Fs = 8000
          f = 5
          sample = 8000
          x = np.arange(sample)
          y = np.sin(2 * np.pi * f * x / Fs)
          plt.plot(x, y)
          plt.xlabel('sample(n)')
          plt.ylabel('voltage(V)')
          plt.show()
          

          P.S.:为了舒适的工作,您可以使用 Jupyter Notebook.

          P.S.: For comfortable work you can use The Jupyter Notebook.

          这篇关于Python如何绘制图形正弦波的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆