from scipy.signal import hilbert
时间: 2023-11-23 15:05:51 浏览: 35
import scipy.signal
The `hilbert` function from the `scipy.signal` module computes the analytical signal of a real-valued signal using the Hilbert transform. It returns a complex-valued signal that represents the original signal with its imaginary part containing the Hilbert transform. Here's an example usage:
```python
import numpy as np
from scipy.signal import hilbert
# Create a real-valued signal
t = np.linspace(0, 1, 100)
x = np.sin(2 * np.pi * 5 * t)
# Compute the analytical signal using Hilbert transform
analytical_signal = hilbert(x)
# Extract the amplitude envelope
amplitude_envelope = np.abs(analytical_signal)
# Extract the instantaneous phase
instantaneous_phase = np.unwrap(np.angle(analytical_signal))
# Plot the original signal, amplitude envelope, and instantaneous phase
import matplotlib.pyplot as plt
fig, axs = plt.subplots(3, 1, figsize=(8, 6), sharex=True)
axs[0].plot(t, x)
axs[0].set_ylabel('Signal')
axs[1].plot(t, amplitude_envelope)
axs[1].set_ylabel('Amplitude Envelope')
axs[2].plot(t, instantaneous_phase)
axs[2].set_ylabel('Instantaneous Phase')
axs[2].set_xlabel('Time')
plt.tight_layout()
plt.show()
```
This example demonstrates how to compute the analytical signal, extract the amplitude envelope, and the instantaneous phase using the `hilbert` function.