-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path004_fftpack.py
More file actions
executable file
·67 lines (54 loc) · 1.42 KB
/
004_fftpack.py
File metadata and controls
executable file
·67 lines (54 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# FileName: 004_fftpack.py
#
# Description:
#
# Version: 1.0
# Created: 2018-06-13 10:31:32
# Last Modified: 2019-09-03 10:51:16
# Revision: none
# Compiler: gcc
#
# Author: zt ()
# Organization:
import matplotlib.pyplot as plt
from numpy import *
from scipy.integrate import quad, dblquad, tplquad
from scipy.integrate import odeint, ode
from scipy.special import jn, yn, jn_zeros, yn_zeros
from numpy.fft import fftfreq
from scipy.fftpack import *
def dy(y, t, zeta, w0):
x, p = y[0], y[1]
dx = p
dp = -2 * zeta * w0 * p - w0**2 * x
return [dx, dp]
y0 = [1.0, 0.0]
t = linspace(0, 10, 1000)
w0 = 2 * pi * 1.0
y1 = odeint(dy, y0, t, args=(0.0, w0))
y2 = odeint(dy, y0, t, args=(0.2, w0))
y3 = odeint(dy, y0, t, args=(1.0, w0))
y4 = odeint(dy, y0, t, args=(5.0, w0))
# fig, ax = plt.subplots()
# ax.plot(t, y1[:, 0], 'k', label="undamped", linewidth=0.25)
# ax.plot(t, y2[:, 0], 'r', label="under damped")
# ax.plot(t, y3[:, 0], 'g', label=r"critical damping")
# ax.plot(t, y4[:, 0], 'b', label="over undamped")
# ax.legend()
# plt.show()
N = len(t)
dt = t[1] - t[0]
# print(y2)
F = fft(y2[:, 0])
W = fftfreq(N, dt)
fig, ax = plt.subplots(figsize=(9, 3))
ax.plot(W, abs(F))
indices = where(W > 0)
W_pos = W[indices]
F_pos = F[indices]
fig, ax = plt.subplots(figsize=(9, 3))
ax.plot(W_pos, abs(F_pos))
ax.set_xlim(0, 5)
plt.show()