Skip to content

Commit 2a79cc4

Browse files
committed
removed blas and dependencies
1 parent f0e35c6 commit 2a79cc4

36 files changed

+1256
-1496
lines changed

deltasigma/_PlotExampleSpectrum.py

Lines changed: 88 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def PlotExampleSpectrum(ntf, M=1, osr=64, f0=0, quadrature=False):
4141
4242
**Parameters:**
4343
44-
ntf : scipy 'lti' object, tuple or ndarray
44+
ntf : scipy 'dlti' object, tuple or ndarray
4545
The first argument may be one of the various supported
4646
representations for a (SISO) transfer function or an
4747
ABCD matrix. See :func:`evalTF` for a more detailed
@@ -79,66 +79,109 @@ def PlotExampleSpectrum(ntf, M=1, osr=64, f0=0, quadrature=False):
7979
"""
8080
f1, f2 = ds_f1f2(osr, f0, quadrature)
8181
delta = 2
82-
Amp = undbv(-3) # Test tone amplitude, relative to full-scale.
82+
Amp = undbv(-3) # Test tone amplitude, relative to full-scale.
8383
# f below is the test tone frequency offset from f0, relative to bw.
8484
# (It will be adjusted to be an fft bin)
8585
f = 0.3
8686
N = 2**12
87-
f1_bin = int(np.round(f1*N))
88-
f2_bin = int(np.round(f2*N))
89-
fin = round(((1 - f)/2*f1 + (f + 1)/2*f2) * N)
87+
f1_bin = int(np.round(f1 * N))
88+
f2_bin = int(np.round(f2 * N))
89+
fin = round(((1 - f) / 2 * f1 + (f + 1) / 2 * f2) * N)
9090
if not quadrature:
9191
t = np.arange(0, N).reshape((1, -1))
92-
u = Amp*M*np.cos((2*np.pi/N)*fin*t)
93-
v, _, xmax, y = simulateDSM(u, ntf, M+1)
92+
u = Amp * M * np.cos((2 * np.pi / N) * fin * t)
93+
v, _, xmax, y = simulateDSM(u, ntf, M + 1)
9494
else:
9595
t = np.arange(0, N).reshape((1, -1))
96-
u = Amp*M*np.exp((2j*np.pi/N)*fin*t)
97-
v, _, xmax, y = simulateQDSM(u, ntf, M+1)
96+
u = Amp * M * np.exp((2j * np.pi / N) * fin * t)
97+
v, _, xmax, y = simulateQDSM(u, ntf, M + 1)
9898
window = ds_hann(N)
99-
NBW = 1.5/N
100-
spec0 = fft(v * window)/(M*N/4)
99+
NBW = 1.5 / N
100+
spec0 = fft(v * window) / (M * N / 4)
101101
if not quadrature:
102-
freq = np.linspace(0, 0.5, int(N/2) + 1)
103-
plt.plot(freq, dbv(spec0[:int(N/2) + 1]), 'c', linewidth=1)
104-
#plt.hold(True)
105-
spec_smoothed = circ_smooth(np.abs(spec0)**2., 16)
106-
plt.plot(freq, dbp(spec_smoothed[:int(N/2) + 1]), 'b', linewidth=3)
107-
Snn = np.abs(evalTF(ntf, np.exp(2j*np.pi*freq)))**2 * 2/12*(delta/M)**2
108-
plt.plot(freq, dbp(Snn*NBW), 'm', linewidth=1)
109-
snr = calculateSNR(spec0[f1_bin:f2_bin + 1], fin - f1_bin)
110-
msg = 'SQNR = %.1fdB\n @ A = %.1fdBFS & osr = %.0f\n' % \
111-
(snr, dbv(spec0[fin]), osr)
102+
freq = np.linspace(0, 0.5, int(N / 2) + 1)
103+
plt.plot(freq, dbv(spec0[: int(N / 2) + 1]), "c", linewidth=1)
104+
# plt.hold(True)
105+
spec_smoothed = circ_smooth(np.abs(spec0) ** 2.0, 16)
106+
plt.plot(freq, dbp(spec_smoothed[: int(N / 2) + 1]), "b", linewidth=3)
107+
Snn = (
108+
np.abs(evalTF(ntf, np.exp(2j * np.pi * freq))) ** 2
109+
* 2
110+
/ 12
111+
* (delta / M) ** 2
112+
)
113+
plt.plot(freq, dbp(Snn * NBW), "m", linewidth=1)
114+
snr = calculateSNR(spec0[f1_bin : f2_bin + 1], fin - f1_bin)
115+
msg = "SQNR = %.1fdB\n @ A = %.1fdBFS & osr = %.0f\n" % (
116+
snr,
117+
dbv(spec0[fin]),
118+
osr,
119+
)
112120
if f0 < 0.25:
113-
plt.text(f0 + 1 / osr, - 15, msg, horizontalalignment='left',
114-
verticalalignment='center')
121+
plt.text(
122+
f0 + 1 / osr,
123+
-15,
124+
msg,
125+
horizontalalignment="left",
126+
verticalalignment="center",
127+
)
115128
else:
116-
plt.text(f0 - 1 / osr, - 15, msg, horizontalalignment='right',
117-
verticalalignment='center')
118-
plt.text(0.5, - 135, 'NBW = %.1e ' % NBW, horizontalalignment='right',
119-
verticalalignment='bottom')
120-
figureMagic((0, 0.5), 1./16, None, (-140, 0), 10, None)
129+
plt.text(
130+
f0 - 1 / osr,
131+
-15,
132+
msg,
133+
horizontalalignment="right",
134+
verticalalignment="center",
135+
)
136+
plt.text(
137+
0.5,
138+
-135,
139+
"NBW = %.1e " % NBW,
140+
horizontalalignment="right",
141+
verticalalignment="bottom",
142+
)
143+
figureMagic((0, 0.5), 1.0 / 16, None, (-140, 0), 10, None)
121144
else:
122145
spec0 = fftshift(spec0 / 2)
123146
freq = np.linspace(-0.5, 0.5, N + 1)
124147
freq = freq[:-1]
125-
plt.plot(freq, dbv(spec0), 'c', linewidth=1)
126-
#plt.hold(True)
127-
spec_smoothed = circ_smooth(abs(spec0)**2, 16)
128-
plt.plot(freq, dbp(spec_smoothed), 'b', linewidth=3)
129-
Snn = abs(evalTF(ntf, np.exp(2j * np.pi * freq))) ** 2 * 2 / 12 * (delta / M) ** 2
130-
plt.plot(freq, dbp(Snn*NBW), 'm', linewidth=1)
131-
snr = calculateSNR(spec0[N//2 + f1_bin:N//2 + f2_bin + 1], fin - f1_bin)
132-
msg = 'SQNR = %.1fdB\n @ A = %.1fdBFS & osr = %.0f' % \
133-
(snr, dbv(spec0[N//2 + fin]), osr)
134-
if f0 >= 0:
135-
plt.text(f0 - 0.05, - 15, msg, horizontalalignment='right',
136-
verticalalignment='bottom')
148+
plt.plot(freq, dbv(spec0), "c", linewidth=1)
149+
# plt.hold(True)
150+
spec_smoothed = circ_smooth(abs(spec0) ** 2, 16)
151+
plt.plot(freq, dbp(spec_smoothed), "b", linewidth=3)
152+
Snn = (
153+
abs(evalTF(ntf, np.exp(2j * np.pi * freq))) ** 2 * 2 / 12 * (delta / M) ** 2
154+
)
155+
plt.plot(freq, dbp(Snn * NBW), "m", linewidth=1)
156+
snr = calculateSNR(spec0[N // 2 + f1_bin : N // 2 + f2_bin + 1], fin - f1_bin)
157+
msg = "SQNR = %.1fdB\n @ A = %.1fdBFS & osr = %.0f" % (
158+
snr,
159+
dbv(spec0[N // 2 + fin]),
160+
osr,
161+
)
162+
if f0 >= 0:
163+
plt.text(
164+
f0 - 0.05,
165+
-15,
166+
msg,
167+
horizontalalignment="right",
168+
verticalalignment="bottom",
169+
)
137170
else:
138-
plt.text(f0 + 0.05, - 15, msg, horizontalalignment='left',
139-
verticalalignment='bottom')
140-
plt.text(-0.5, -135, ' NBW = %.1e' % NBW, horizontalalignment='left',
141-
verticalalignment='bottom')
171+
plt.text(
172+
f0 + 0.05,
173+
-15,
174+
msg,
175+
horizontalalignment="left",
176+
verticalalignment="bottom",
177+
)
178+
plt.text(
179+
-0.5,
180+
-135,
181+
" NBW = %.1e" % NBW,
182+
horizontalalignment="left",
183+
verticalalignment="bottom",
184+
)
142185
figureMagic((-0.5, 0.5), 0.125, None, (-140, 0), 10, None)
143-
plt.xlabel('frequency')
186+
plt.xlabel("frequency")
144187
return

deltasigma/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@
899899
__copyright__ = "Copyright 2013, Giuseppe Venturini"
900900
__credits__ = ["Giuseppe Venturini"]
901901
__license__ = "BSD 2-Clause License"
902-
__version__ = '0.2.5'
902+
__version__ = "0.2.5"
903903
__maintainer__ = "Giuseppe Venturini"
904904
__email__ = "ggventurini+github@gmail.com"
905905
__status__ = "Stable"
@@ -914,10 +914,11 @@
914914
# if not os.system('python -c "import matplotlib.pyplot as plt;plt.figure()"')
915915
import matplotlib
916916
import os
917-
if not ('DISPLAY' in os.environ
918-
or os.name =='nt'
919-
or os.environ.get('READTHEDOCS', None)):
920-
matplotlib.use('Agg')
917+
918+
if not (
919+
"DISPLAY" in os.environ or os.name == "nt" or os.environ.get("READTHEDOCS", None)
920+
):
921+
matplotlib.use("Agg")
921922

922923
from ._DocumentNTF import DocumentNTF
923924
from ._PlotExampleSpectrum import PlotExampleSpectrum
@@ -983,7 +984,7 @@
983984
from ._rms import rms
984985
from ._rmsGain import rmsGain
985986
from ._scaleABCD import scaleABCD
986-
from ._simulateDSM import simulateDSM, simulation_backends
987+
from ._simulateDSM import simulateDSM
987988
from ._simulateQDSM import simulateQDSM
988989
from ._simulateQSNR import simulateQSNR
989990
from ._simulateSNR import simulateSNR
@@ -998,4 +999,5 @@
998999
from ._undbv import undbv
9991000
from ._utils import circshift, cplxpair, mfloor, mround, pretty_lti, rat, gcd, lcm
10001001
from ._zinc import zinc
1002+
10011003
# from . import PosInvSet

deltasigma/_calculateTF.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
from warnings import warn
2020

2121
import numpy as np
22-
from scipy.signal import lti, ss2zpk
22+
from scipy.signal import dlti, ss2zpk
2323

2424
from ._constants import eps
2525
from ._partitionABCD import partitionABCD
2626
from ._utils import carray, minreal
2727

2828

29-
def calculateTF(ABCD, k=1.):
29+
def calculateTF(ABCD, k=1.0):
3030
"""Calculate the NTF and STF of a delta-sigma modulator.
3131
3232
The calculation is performed for a given loop filter
@@ -48,9 +48,9 @@ def calculateTF(ABCD, k=1.):
4848
**Returns:**
4949
5050
(NTF, STF) : a tuple of two LTI objects (or of two lists of LTI objects).
51-
If a version of the ``scipy`` library equal to 0.16.x or
51+
If a version of the ``scipy`` library equal to 0.16.x or
5252
greater is in use, the objects will be ``ZeroPolesGain``
53-
objects, a subclass of ``scipy.signal.lti``.
53+
objects, a subclass of ``scipy.signal.dlti``.
5454
5555
If the system has multiple quantizers, multiple STFs and NTFs will be
5656
returned.
@@ -123,7 +123,7 @@ def calculateTF(ABCD, k=1.):
123123
"""
124124

125125
nq = len(k) if type(k) in (tuple, list) else 1
126-
A, B, C, D = partitionABCD(ABCD, m=nq+1, r=nq)
126+
A, B, C, D = partitionABCD(ABCD, m=nq + 1, r=nq)
127127
k = carray(k)
128128
diagk = np.atleast_2d(np.diag(k))
129129

@@ -158,25 +158,24 @@ def calculateTF(ABCD, k=1.):
158158

159159
# Find the noise transfer function by forming the closed-loop
160160
# system (sys_cl) in state-space form.
161-
Ct = np.linalg.inv(np.eye(nq) - D2*diagk)
161+
Ct = np.linalg.inv(np.eye(nq) - D2 * diagk)
162162
Acl = A + np.dot(B2, np.dot(Ct, np.dot(diagk, C)))
163-
Bcl = np.hstack((B1 + np.dot(B2, np.dot(Ct, np.dot(diagk, D1))),
164-
np.dot(B2, Ct)))
163+
Bcl = np.hstack((B1 + np.dot(B2, np.dot(Ct, np.dot(diagk, D1))), np.dot(B2, Ct)))
165164
Ccl = np.dot(Ct, np.dot(diagk, C))
166165
Dcl = np.dot(Ct, np.hstack((np.dot(diagk, D1), np.eye(nq))))
167-
tol = min(1e-3, max(1e-6, eps**(1/ABCD.shape[0])))
166+
tol = min(1e-3, max(1e-6, eps ** (1 / ABCD.shape[0])))
168167
ntfs = np.empty((nq, Dcl.shape[0]), dtype=np.object_)
169168
stfs = np.empty((Dcl.shape[0],), dtype=np.object_)
170169

171170
# sweep the outputs 'cause scipy is silly but we love it anyhow.
172171
for i in range(Dcl.shape[0]):
173172
# input #0 is the signal
174173
# inputs #1,... are quantization noise
175-
stf_z, stf_p, stf_k = ss2zpk(Acl, Bcl, Ccl[i, :], Dcl[i, :], input=0)
176-
stf = lti(stf_z, stf_p, stf_k)
174+
stf_z, stf_p, stf_k = ss2zpk(Acl, Bcl, Ccl[i, :], Dcl[i, :], input=0)
175+
stf = dlti(stf_z, stf_p, stf_k)
177176
for j in range(nq):
178-
ntf_z, ntf_p, ntf_k = ss2zpk(Acl, Bcl, Ccl[i, :], Dcl[i, :], input=j+1)
179-
ntf = lti(ntf_z, ntf_p, ntf_k)
177+
ntf_z, ntf_p, ntf_k = ss2zpk(Acl, Bcl, Ccl[i, :], Dcl[i, :], input=j + 1)
178+
ntf = dlti(ntf_z, ntf_p, ntf_k)
180179
stf_min, ntf_min = minreal((stf, ntf), tol)
181180
ntfs[i, j] = ntf_min
182181
stfs[i] = stf_min
@@ -185,4 +184,3 @@ def calculateTF(ABCD, k=1.):
185184
if ntfs.shape == (1, 1):
186185
return [ntfs[0, 0], stfs[0]]
187186
return ntfs, stfs
188-

deltasigma/_cancelPZ.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Copyright 2013 Giuseppe Venturini
55
# This file is part of python-deltasigma.
66
#
7-
# python-deltasigma is a 1:1 Python replacement of Richard Schreier's
7+
# python-deltasigma is a 1:1 Python replacement of Richard Schreier's
88
# MATLAB delta sigma toolbox (aka "delsigma"), upon which it is heavily based.
99
# The delta sigma toolbox is (c) 2009, Richard Schreier.
1010
#
@@ -21,7 +21,7 @@
2121
import copy
2222

2323
import numpy as np
24-
from scipy.signal import lti
24+
from scipy.signal import dlti
2525

2626

2727
def cancelPZ(arg1, tol=1e-6):
@@ -32,7 +32,7 @@ def cancelPZ(arg1, tol=1e-6):
3232
arg1 : LTI system description
3333
Multiple descriptions are supported for the LTI system.
3434
35-
If one argument is used, it is a scipy ``lti`` object.
35+
If one argument is used, it is a scipy ``dlti`` object.
3636
3737
If more arguments are used, they should be arranged in a tuple, the
3838
following gives the number of elements in the tuple and their
@@ -50,12 +50,12 @@ def cancelPZ(arg1, tol=1e-6):
5050
**Returns:**
5151
5252
(z, p, k) : tuple
53-
A tuple containing zeros, poles and gain (unchanged) after poles, zeros
53+
A tuple containing zeros, poles and gain (unchanged) after poles, zeros
5454
cancellation.
5555
5656
"""
57-
if not isinstance(arg1, lti):
58-
arg1 = lti(*arg1)
57+
if not isinstance(arg1, dlti):
58+
arg1 = dlti(*arg1)
5959
z = copy.copy(arg1.zeros)
6060
p = copy.copy(arg1.poles)
6161
k = arg1.gain

deltasigma/_evalTFP.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def evalTFP(Hs, Hz, f):
6969
7070
import numpy as np
7171
import pylab as plt
72-
from scipy.signal import lti
72+
from scipy.signal import dlti
7373
from deltasigma import *
7474
from deltasigma._utils import _get_zpk
7575
Ac = np.array([[0, 0], [1, 0]])
@@ -80,7 +80,7 @@ def evalTFP(Hs, Hz, f):
8080
L0c = _get_zpk((Ac, Bc[:, 0].reshape((-1, 1)), Cc, Dc[0, 0].reshape(1, 1)))
8181
tdac = [0, 1]
8282
LF, Gp = mapCtoD(LFc, tdac)
83-
LF = lti(*LF)
83+
LF = dlti(*LF)
8484
ABCD = np.vstack((np.hstack((LF.A, LF.B)),
8585
np.hstack((LF.C, LF.D))
8686
))
@@ -98,7 +98,7 @@ def evalTFP(Hs, Hz, f):
9898
9999
import numpy as np
100100
import pylab as plt
101-
from scipy.signal import lti
101+
from scipy.signal import dlti
102102
from deltasigma import *
103103
from deltasigma._utils import _get_zpk
104104
Ac = np.array([[0, 0], [1, 0]])
@@ -109,7 +109,7 @@ def evalTFP(Hs, Hz, f):
109109
L0c = _get_zpk((Ac, Bc[:, 0].reshape((-1, 1)), Cc, Dc[0, 0].reshape(1, 1)))
110110
tdac = [0, 1]
111111
LF, Gp = mapCtoD(LFc, tdac)
112-
LF = lti(*LF)
112+
LF = dlti(*LF)
113113
ABCD = np.vstack((np.hstack((LF.A, LF.B)),
114114
np.hstack((LF.C, LF.D))
115115
))

0 commit comments

Comments
 (0)