Python how to plot graph sine wave

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

    import matplotlib.pyplot as plt # For ploting
    import numpy as np # to work with numerical data efficiently
    
    fs = 100 # sample rate 
    f = 2 # the frequency of the signal
    
    x = np.arange(fs) # the points on the x axis for plotting
    # compute the value (amplitude) of the sin wave at the for each sample
    y = np.sin(2*np.pi*f * (x/fs)) 
    
    #this instruction can only be used with IPython Notbook. 
    % matplotlib inline
    # showing the exact location of the smaples
    plt.stem(x,y, 'r', )
    plt.plot(x,y)
    

提交回复
热议问题