Skip to content

Commit

Permalink
state tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdi committed Nov 21, 2023
1 parent f0f4f30 commit 4c8e508
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__pycache__
*.egg-info
env

.coverage
.vscode

14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ The book represents algorithms as:
1. matlab code
1. described in English in the textbook body

## Pour Moi
## Chapters

1. Introduction
2. Background
3. Discrete-Time Random Processes
4. Signal Modeling
5. The Levinson Recursion
6. Lattice Filters
7. Optimum Filters
8. Spectrum Estimation
9. Adaptive Filters

### TODO

Expand All @@ -25,3 +35,5 @@ The book represents algorithms as:
- stub files?
- VS code add-ons
- use matlab-equivalent psuedo-inverse ("X \ R") operation to match the book
- switch linting to Ruff?
- performance benchmarking would be cool
9 changes: 9 additions & 0 deletions pyssp/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
"""The import root for the book sections."""

# import system as Chapter3
# import modeling as Chapter4
# import levinson as Chapter5
# import lattice as Chapter6
# import optimal as Chapter7
# import spectrum as Chapter8
# import adaptive as Chapter9
# import state as Appendix
2 changes: 1 addition & 1 deletion pyssp/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def covm(x, p):
x0 = x.copy().ravel().reshape(-1, 1)
N = len(x0)
if p >= len(x0):
raise ValueError("p (all-pole model) too large")
raise ValueError(f"{p=} all-pole model too large")

X = convm(x0, p + 1)
Xq = X[p - 1:N - 1, :p].copy()
Expand Down
31 changes: 31 additions & 0 deletions tests/test_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Test the state module."""


import numpy as np

from pyssp import state


def test_convm():
x = np.array([1, 2, 3])
p = 4

expected = np.array([[1, 0, 0, 0],
[2, 1, 0, 0],
[3, 2, 1, 0],
[0, 3, 2, 1],
[0, 0, 3, 2],
[0, 0, 0, 3]], dtype=float)
assert np.array_equal(expected, state.convm(x, p))


def test_covar():
x = np.array([1, 2, 3])
p = 4

expected = np.array([[1, 0, -0.5, 0, 0],
[0, 1, 0, -0.5, 0],
[-0.5, 0, 1, 0, -0.5],
[0, -0.5, 0, 1, 0],
[0, 0, -0.5, 0, 1]], dtype=float)
assert np.array_equal(expected, state.covar(x, p))

0 comments on commit 4c8e508

Please sign in to comment.