-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathtest_simulateDSM_numba.py
More file actions
59 lines (52 loc) · 2.2 KB
/
test_simulateDSM_numba.py
File metadata and controls
59 lines (52 loc) · 2.2 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
# -*- coding: utf-8 -*-
# test_simulateDSM.py
# This module provides the tests for the simulateDSM_numba function.
# Copyright 2014 Giuseppe Venturini & Shayne Hodge
# This file is part of python-deltasigma.
#
# python-deltasigma is a 1:1 Python replacement of Richard Schreier's
# MATLAB delta sigma toolbox (aka "delsigma"), upon which it is heavily based.
# The delta sigma toolbox is (c) 2009, Richard Schreier.
#
# python-deltasigma is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# LICENSE file for the licensing terms.
"""This module provides the test class for the simulateDSM() function.
"""
import unittest
import pkg_resources
import numpy as np
import deltasigma as ds
import scipy.io
from deltasigma import synthesizeNTF, realizeNTF, stuffABCD
class TestSimulateDSM(unittest.TestCase):
"""Test class for simulateDSM_numba()"""
def setUp(self):
fname = pkg_resources.resource_filename(
__name__, "test_data/test_simulateDSM.mat")
self.v_ref = scipy.io.loadmat(fname)['v']
self.xn_ref = scipy.io.loadmat(fname)['xn']
self.xmax_ref = scipy.io.loadmat(fname)['xmax']
self.y_ref = scipy.io.loadmat(fname)['y']
OSR = 32
self.H = synthesizeNTF(5, OSR, 1)
N = 8192
f = 85
self.u = 0.5*np.sin(2*np.pi*f/N*np.arange(N))
a, g, b, c = realizeNTF(self.H, 'CRFB')
self.ABCD = stuffABCD(a, g, b, c, form='CRFB')
def test_simulateDSM_numba(self):
"""Test function for simulateDSM_numba()"""
#print self.ABCD
#print self.u
#print self.H
v, xn, xmax, y = ds._simulateDSM._simulateDSM_numba(
self.u, self.H, 2, 0)
self.assertTrue(np.allclose(
v.reshape(-1), self.v_ref.reshape(-1), atol=1e-6, rtol=1e-4))
self.assertTrue(np.allclose(y, self.y_ref, atol=1e-6, rtol=1e-4))
v, xn, xmax, y = ds._simulateDSM._simulateDSM_numba(
self.u, self.ABCD, 2, 0)
self.assertTrue(np.allclose(v, self.v_ref, atol=1e-6, rtol=1e-4))
self.assertTrue(np.allclose(y, self.y_ref, atol=1e-6, rtol=1e-4))