import numpy as np
A = np.array([[2, 3], [4, -5]])
B = np.array([1, 2])
x = np.linalg.solve(A, B)
print(f'Solution: x = {x[0]:.2f}, y = {x[1]:.2f}')
import numpy as np
from scipy.fft import fft, rfft
from scipy.fft import fftfreq, rfftfreq
import plotly.graph_objs as go
from plotly.subplots import make_subplots
import matplotlib.pyplot as plt
%matplotlib inline
# Generate the three signals using Signal class and its method sine()
signal_1hz = Signal(amplitude=3, frequency=1, sampling_rate=200, duration=2)
sine_1hz = signal_1hz.sine()
signal_20hz = Signal(amplitude=1, frequency=20, sampling_rate=200, duration=2)
sine_20hz = signal_20hz.sine()
signal_10hz = Signal(amplitude=0.5, frequency=10, sampling_rate=200, duration=2)
sine_10hz = signal_10hz.sine()
# Sum the three signals to output the signal we want to analyze
signal = sine_1hz + sine_20hz + sine_10hz
# Plot the signal
plt.plot(signal_1hz.time_axis, signal, 'b')
plt.xlabel('Time [sec]')
plt.ylabel('Amplitude')
plt.title('Sum of three signals')
plt.show()
可以使用 scipy 包中的 (fft) 计算该信号的傅立叶变换,如下所示
# Apply the FFT on the signal
fourier = fft(signal)
# Plot the result (the spectrum |Xk|)
plt.plot(np.abs(fourier))
plt.show()