Python how to plot graph sine wave

前端 未结 9 1238
死守一世寂寞
死守一世寂寞 2021-02-01 07:11

I have this signal :

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

9条回答
  •  一向
    一向 (楼主)
    2021-02-01 07:49

    The window of usefulness has likely come and gone, but I was working at a similar problem. Here is my attempt at plotting sine using the turtle module.

    from turtle import *
    from math import *
    
    #init turtle
    T=Turtle()
    
    #sample size
    T.screen.setworldcoordinates(-1,-1,1,1) 
    
    #speed up the turtle
    T.speed(-1)
    
    #range of hundredths from -1 to 1
    xcoords=map(lambda x: x/100.0,xrange(-100,101))
    
    #setup the origin
    T.pu();T.goto(-1,0);T.pd()
    
    #move turtle
    for x in xcoords:
        T.goto(x,sin(xcoords.index(x)))
    

提交回复
热议问题