Skip to content

Commit cf379a3

Browse files
committed
TEST: rewrite tests for sinc_decimate()
1 parent ee48187 commit cf379a3

1 file changed

Lines changed: 17 additions & 42 deletions

File tree

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
# _sinc_decimate.py
3-
# This module provides the sinc_decimate function.
4-
# Copyright 2013 Giuseppe Venturini
5-
# This file is part of python-deltasigma.
6-
#
7-
# python-deltasigma is a 1:1 Python replacement of Richard Schreier's
8-
# MATLAB delta sigma toolbox (aka "delsigma"), upon which it is heavily based.
9-
# The delta sigma toolbox is (c) 2009, Richard Schreier.
10-
#
11-
# python-deltasigma is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
# LICENSE file for the licensing terms.
15-
16-
"""This module provides the sinc_decimate() function, which decimates a vector
17-
by a sinc filter of specified order and length.
18-
"""
19-
20-
from __future__ import division
21-
import numpy as np
22-
23-
def sinc_decimate(x, m, r):
24-
"""Decimate ``x`` by an ``m``-th order sinc filter of length ``r``.
25-
"""
26-
x = x[:]
27-
for _ in range(m):
28-
x = np.cumsum(x)
29-
x = np.concatenate((x[:r], x[r:] - x[:-r]), axis=0)/r
30-
return x[r::r]
31-
32-
331
# -*- coding: utf-8 -*-
342
# test_sinc_decimate.py
353
# This module provides the tests for the sinc_decimate function.
@@ -55,14 +23,21 @@ def sinc_decimate(x, m, r):
5523
class TestSincDecimate(unittest.TestCase):
5624
"""Test class for sinc_decimate()"""
5725

58-
def setUp(self):
59-
self.r = [-1.33907057e-17, -3.55951662e-17, -2.28847549e-18,
60-
-3.55951662e-17, -1.02208548e-16, -4.35275455e-16,
61-
4.97311886e-16, -4.57479916e-16, 4.30698504e-16]
62-
63-
def test_sinc_decimate(self):
64-
"""Test function for sinc_decimate()"""
65-
tv = np.sin(2*np.pi*.1*np.arange(0, 100))
66-
res = ds.sinc_decimate(tv, 1, 10)
67-
self.assertTrue(np.allclose(res, self.r, rtol=1e-5, atol=1e-8))
26+
def test_sinc_decimate_1(self):
27+
"""Test function for sinc_decimate() 1/3"""
28+
x = [1]*10
29+
self.assertTrue(np.allclose(ds.sinc_decimate(x, 1, 10), [1.]))
30+
31+
def test_sinc_decimate_2(self):
32+
"""Test function for sinc_decimate() 2/3"""
33+
x = [1]*10
34+
self.assertTrue(np.allclose(ds.sinc_decimate(x, 2, 5), [.6, 1.]))
35+
36+
def test_sinc_decimate_3(self):
37+
"""Test function for sinc_decimate() 3/3"""
38+
x = [1]*10
39+
x = np.cumsum(np.asarray(x))
40+
self.assertTrue(np.allclose(ds.sinc_decimate(x, 1, 5), [3., 8.]))
41+
self.assertTrue(np.allclose(ds.sinc_decimate(x, 2, 5), [1.4, 6.]))
42+
self.assertTrue(np.allclose(ds.sinc_decimate(x, 3, 3), [0.55555556, 3., 6.]))
6843

0 commit comments

Comments
 (0)