Issue
first I would like to say it is my first time using Matplotlib and Numpy so I will be wrong about what I am talking about and this code is definitely super messy, Thank you.
I have got this signal, and I am trying to get a graph of its Magnitude Spectrum my problem is that I cant seem to represent its negative values, FYI I did not make this code from scratch I got it off a Magnitude Spectrum example and adapted it. What am I doing wrong?
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(0)
dt = 1 # sampling interval
Fs = 11000 # sampling frequency
t = np.arange(0,1,1/Fs)
s = 20000 * np.cos(2 * np.pi * 5025 * t) + 10000*np.cos(2 * np.pi * 2507 * t -np.pi/2) # the signal
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(10, 10))
axs[0, 0].set_title("Magnitude Spectrum")
axs[0, 0].set_xlim([-Fs/2, Fs/2])
axs[0, 0].magnitude_spectrum(s, Fs=Fs, color='C1')
axs[0, 1].remove() # don't display empty ax
axs[1, 0].remove()
axs[1, 1].remove()
fig.tight_layout()
plt.show()
Solution
Here you go:
axs[0, 0].magnitude_spectrum(s, Fs=Fs, color='C1', sides= 'twosided')
Answered By - sehan2
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.