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 graph (this sine wave)?
and create name of xlabel as 'voltage(V)' and ylabel as 'sample(n)'
What code to do this?
I am so thanksful for help ^_^
Here is the code to generate sine wave in Matplotlib. The graph of y=sin(x) y = sin ( x ) for x between −π and π .
To graph the sine function, we mark the angle along the horizontal x axis, and for each angle, we put the sine of that angle on the vertical y-axis. The result, as seen above, is a smooth curve that varies from +1 to -1. Curves that follow this shape are called 'sinusoidal' after the name of the sine function.
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 timesI hope this will help:
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.: For comfortable work you can use The Jupyter Notebook.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With