Python Forum
Magnitude and Phase spectrum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Magnitude and Phase spectrum
#1
I'm having trouble with graphing the magnitude and phase spectrum of the following function with give period T= 10^-6
-10^6 * t + 0.5 when 0 <= t <= 5*10^-7
0 in any other case

This is the program I've done until now
import sympy as sp
import numpy as np
import scipy as sy
from scipy.fftpack import fft
import matplotlib.pyplot as plt

n = 25 #number used for the harmonics

t = np.linspace(0, (5*10**-7), n*2-1) #values in which function is valid as defined in the start. 
x = (-10**6)*t + 0.5 #my function

Y = fft(x) #apply fourier transform to function
print "This is Y = "
print(Y)
print "Length of Y is = "
print(len(Y))
h = [u for u in range((-n+1),n)] #has a length of 49, just the same as the fft(Y) from above
print "This is h = "
print(h)
print "This is the length of h "
print(len(h))

plt.plot(h,np.abs(Y))
plt.title('Magnitude Spectrum')
plt.ylabel('Amplitude')
plt.xlabel('Harmonics')
plt.show()
What I did here is I applied the fourier transform to the function defined in the interval explained in the start and later I applied the absolute value to that result and plot it against the number of harmonics to get the Magnitud spectrum. I haven't done the phase spectrum yet but I pretend on doing the same but instead of applying abs function on the fft(Y), I'll apply angle(fft(Y)).

This is the graph I get when I run the program, where it doesn't really look like it's good.


[Image: a6QS6]

Maybe there's something wrong in the concept, any help/guidance is appreciated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  phase portrait - Nonlinear damped pendulum Giovanni_62 1 823 Sep-10-2023, 02:25 PM
Last Post: deanhystad
  Magnitude/phase Spectrum Fourier ramsese 0 2,985 Apr-11-2018, 03:52 AM
Last Post: ramsese

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020