I would like to calculate the Hilbert spectrum as a 3D plot (ie 2D array) in Python. The Hilbert spectrum is a function of the form time x frequency -> amplitude
which assigns each time and frequency pair an amplitude value.
The method for calculating the spectrum takes one or more 2D signals as input which each have two components: time -> frequency
and time -> amplitude
. Take one single signal a
as an example. y1
would be the frequency values, y2
the amplitude values.
a_x = [1,2,3]
a_y1 = [1,2,1]
a_y2 = [4,5,6]
I would like to transform these two 2D plots into one 3D plot, such that X x Y1 -> Y2
.
a(1,1) = 4
a(2,2) = 5
a(3,1) = 6
The real-life values would be floats. My solution so far has been to take the max and min values in y1
and to initialise a grid with a predetermined precision such as 0.01. In this example:
y1_max = np.amax(a_y1)
y1_min = np.amin(a_y2)
# Initialise 2d array of zeros
hilbert_spectrum = np.zeros((len(a_x), len(np.linspace(y1_min, y1_max, 0.01)))
I would then fill in the grid as such:
# Fit the old y1 values into new grid
y1_grid = np.floor((a_y1 - y1_min) / 0.01).astype(np.int)
# Fill the 2D hilbert spectrum
hilbert_spectrum[1, y1_grid[0]] = 4
hilbert_spectrum[2, y1_grid[1]] = 5
hilbert_spectrum[3, y1_grid[2]] = 6
However, this gets complicated when there is more than one input signal. Is there a more mathematical/concise way to do this? The output should be a 2D array which can be used for further calculations.
following: http://matplotlib.org/examples/mplot3d/trisurf3d_demo2.html
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.tri as mtri
a_x = [1,2,3]
a_y1 = [1,2,1]
a_y2 = [4,5,6]
# Triangulate parameter space to determine the triangles
tri = mtri.Triangulation(a_x, a_y1)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
# The triangles in parameter space determine which x, y, z points are
# connected by an edge
ax.plot_trisurf(a_x, a_y1, a_y2, triangles=tri.triangles, cmap=plt.cm.Spectral)
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.