Skip to content

Commit

Permalink
ENH: FIX: Bug fixes and first notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
ilayn committed May 23, 2018
1 parent 139a836 commit b625181
Show file tree
Hide file tree
Showing 9 changed files with 996 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ v.1.0.0
+ Unit tests are significantly improved(>80%)
+ Lots and lots of bug fixes.
+ Change the documentation theme to guzzle
+ Added first order hold discretization method
- Removed FAQ from docs

v.0.1.1rc1
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Contents:
tut_model_props
tut_polyfuncs
tut_freq_domain
tut_time_domain


Additional Information
Expand Down
2 changes: 2 additions & 0 deletions docs/tut_discrete.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Method Aliases
``lft``
----------------------- ------------------------
``zoh``
----------------------- ------------------------
``foh``
======================= ========================

Hence, if a model with ``DiscretizedWith`` property set to
Expand Down
11 changes: 11 additions & 0 deletions docs/tut_time_domain.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Time Domain Computations and Plots
==================================

.. py:currentmodule:: harold
.. autofunction:: simulate_linear_system
.. autofunction:: simulate_step_response
.. autofunction:: simulate_impulse_response
.. autofunction:: step_response_plot
.. autofunction:: impulse_response_plot


8 changes: 5 additions & 3 deletions harold/_frequency_domain_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ def bode_plot(G, w=None, use_db=False, use_hz=True, use_degree=True):
frequencies are in Hz.
use_degree : bool, optional
The phase angle is shown in degrees or in radians.
Returns
-------
plot : matplotlib.figure.Figure
plot : matplotlib.axes._subplots.AxesSubplot
"""
_check_for_state_or_transfer(G)
Expand Down Expand Up @@ -114,7 +115,8 @@ def bode_plot(G, w=None, use_db=False, use_hz=True, use_degree=True):
axs[2*row, col].set_ylabel(r'Magnitude {}'.format('(dB)'
if use_db else
r'($\mathregular{10^x}$)'))
axs[2*row+1, col].set_ylabel(r'Phase (deg)')
axs[2*row+1, col].set_ylabel(r'Phase ({})'.format(
'deg' if use_degree else 'rad'))
if row == p - 1:
axs[2*row+1, col].set_xlabel(r'Frequency ({})'.format(f_unit))

Expand All @@ -136,7 +138,7 @@ def nyquist_plot(G, w=None):
Returns
-------
plot : matplotlib.figure.Figure
plot : matplotlib.axes._subplots.AxesSubplot
"""
_check_for_state_or_transfer(G)
Expand Down
2 changes: 1 addition & 1 deletion harold/_system_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def _minimal_realization_state(A, B, C, tol=1e-6):
bs = int(sum(blocks_c))
A, B, C = Ac[:bs, :bs], Bc[:bs, :], Cc[:, :bs]
else:
bs = n - int(sum(blocks_o))
bs = int(sum(blocks_o))
A, B, C = Ao[bs:, bs:], Bo[bs:, :], Co[:, bs:]

return A, B, C
Expand Down
26 changes: 24 additions & 2 deletions harold/_time_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ def simulate_step_response(sys, t=None):
discrete time models increments different than the sampling period also
raises an error. On the other hand for discrete models this can be
omitted and a time sequence will be generated automatically.
Returns
-------
yout : ndarray
The resulting response array. The array is 1D if sys is SISO and
has p columns if sys has p outputs. If there are also m inputs the
array is 3D array with the shape (<num of samples>, p, m)
tout : ndarray
The time sequence used in the simulation. If the parameter t is not
None then a copy of t is given.
"""
_check_for_state_or_transfer(sys)
# Always works with State Models
Expand All @@ -215,7 +226,7 @@ def simulate_step_response(sys, t=None):
def simulate_impulse_response(sys, t=None):
"""
Compute the linear model response to an Dirac delta pulse (or all-zeros
array except the first sample being 1. at each channel) sampled at given
array except the first sample being 1/dt at each channel) sampled at given
time instances.
If the time array is omitted then a time sequence is generated based on
Expand All @@ -231,6 +242,17 @@ def simulate_impulse_response(sys, t=None):
discrete time models increments different than the sampling period also
raises an error. On the other hand for discrete models this can be
omitted and a time sequence will be generated automatically.
Returns
-------
yout : ndarray
The resulting response array. The array is 1D if sys is SISO and
has p columns if sys has p outputs. If there are also m inputs the
array is 3D array with the shape (<num of samples>, p, m)
tout : ndarray
The time sequence used in the simulation. If the parameter t is not
None then a copy of t is given.
"""
_check_for_state_or_transfer(sys)
# Always works with State Models
Expand All @@ -245,7 +267,7 @@ def simulate_impulse_response(sys, t=None):

m = sys.shape[1]
u = np.zeros([len(t), m], dtype=float)
u[0] = 1.
u[0] = 1./ts

return simulate_linear_system(sys, u=u, t=t, per_channel=1)

Expand Down
4 changes: 2 additions & 2 deletions harold/_time_domain_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def step_response_plot(sys, t=None):
Returns
-------
fig : matplotlib.figure.Figure
fig : matplotlib.axes._subplots.AxesSubplot
Returns the figure handle of the step response
"""
Expand Down Expand Up @@ -95,7 +95,7 @@ def impulse_response_plot(sys, t=None):
Returns
-------
fig : matplotlib.figure.Figure
fig : matplotlib.axes._subplots.AxesSubplot
Returns the figure handle of the impulse response
"""
Expand Down
Loading

0 comments on commit b625181

Please sign in to comment.