Python how to plot graph sine wave

前端 未结 9 1243
死守一世寂寞
死守一世寂寞 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:59

    This is another option

    #!/usr/bin/env python
    
    import numpy as np
    import matplotlib
    matplotlib.use('TKAgg') #use matplotlib backend TkAgg (optional)
    import matplotlib.pyplot as plt
    
    sample_rate = 200 # sampling frequency in Hz (atleast 2 times f)
    t = np.linspace(0,5,sample_rate)    #time axis
    f = 100 #Signal frequency in Hz
    sig = np.sin(2*np.pi*f*(t/sample_rate))
    plt.plot(t,sig)
    plt.xlabel("Time")
    plt.ylabel("Amplitude")
    plt.tight_layout() 
    plt.show()
    

提交回复
热议问题