-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvisualization.py
More file actions
69 lines (55 loc) · 1.95 KB
/
visualization.py
File metadata and controls
69 lines (55 loc) · 1.95 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
68
69
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""Visualization functions for PyHHT."""
import matplotlib.pyplot as plt
import numpy as np
def plot_imfs(signal, time_samples, imfs, fignum=None):
"""Visualize decomposed signals.
:param signal: Analyzed signal
:param time_samples: time instants
:param imfs: intrinsic mode functions of the signal
:param fignum: (optional) number of the figure to display
:type signal: array-like
:type time_samples: array-like
:type imfs: array-like of shape (n_imfs, length_of_signal)
:type fignum: int
:return: None
:Example:
>>> plot_imfs(signal)
.. plot:: ../../docs/examples/emd_fmsin.py
"""
n_imfs = imfs.shape[0]
plt.figure(num=fignum)
axis_extent = max(np.max(np.abs(imfs[:-1, :]), axis=0))
# Plot original signal
ax = plt.subplot(n_imfs, 1, 1)
ax.plot(time_samples, signal)
ax.axis([time_samples[0], time_samples[-1], signal.min(), signal.max()])
ax.tick_params(which='both', left=False, bottom=False, labelleft=False,
labelbottom=False)
ax.grid(False)
ax.set_ylabel('Signal')
ax.set_title('Empirical Mode Decomposition')
# Plot the IMFs
for i in range(n_imfs - 1):
ax = plt.subplot(n_imfs, 1, i + 2)
ax.plot(time_samples, imfs[i, :])
ax.axis([time_samples[0], time_samples[-1], -axis_extent, axis_extent])
ax.tick_params(which='both', left=False, bottom=False, labelleft=False,
labelbottom=False)
ax.grid(False)
ax.set_ylabel('imf' + str(i + 1))
# Plot the residue
ax = plt.subplot(n_imfs + 1, 1, n_imfs + 1)
ax.plot(time_samples, imfs[-1, :], 'r')
ax.axis('tight')
ax.tick_params(which='both', left=False, bottom=False, labelleft=False,
labelbottom=False)
ax.grid(False)
ax.set_ylabel('res.')
plt.show()