Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
ADC Testing
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
ADC Testing
Commits
5f4c89b1
Commit
5f4c89b1
authored
Jan 20, 2011
by
Juan David González Cobas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Temporary commit of changes made to the DNL/INL computations
parent
7049c394
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
8 deletions
+77
-8
Signal.py
Signal.py
+77
-8
No files found.
Signal.py
View file @
5f4c89b1
...
...
@@ -35,6 +35,7 @@ class Signal(object):
self
.
nbits
=
nbits
self
.
rate
=
rate
self
.
data
=
data
self
.
nsamples
=
len
(
data
)
def
histogram_resolution
(
self
):
bins
=
2
**
self
.
nbits
...
...
@@ -48,9 +49,28 @@ class Signal(object):
returns: an array of 2**signal.nbits numbers (frequencies)
"""
bins
=
self
.
histogram_resolution
()
hist
,
bins
=
histogram
(
array
(
self
.
data
),
bins
)
return
hist
# bins = self.histogram_resolution()
# hist, bins = histogram(array(self.data), bins)
bins
=
2
**
self
.
nbits
hist
,
discard
=
histogram
(
array
(
self
.
data
),
bins
)
return
hist
[
1
:
-
1
]
def
_ideal_histogram
(
self
):
"""Produce an ideal vector of frequencies (histogram) for the
nsamples samples of a perfect nbits ADC. Mostly for auxiliary and
display purposes
returns: an array of 2**signal.nbits numbers (frequencies)
"""
Mt
=
len
(
self
.
data
)
A
=
sin
(
pi
/
2
*
Mt
/
(
Mt
+
self
.
data
[
0
]
+
self
.
data
[
-
1
]))
range
=
2
**
self
.
nbits
midrange
=
range
/
2
n
=
arange
(
1
,
range
-
1
)
p
=
arcsin
(
A
/
midrange
*
(
n
-
midrange
))
q
=
arcsin
(
A
/
midrange
*
(
n
-
1
-
midrange
))
p
=
(
p
-
q
)
/
pi
return
Mt
*
p
def
ideal_histogram
(
self
):
"""Produce an ideal vector of frequencies (histogram) for the
...
...
@@ -59,9 +79,18 @@ class Signal(object):
returns: an array of 2**signal.nbits numbers (frequencies)
"""
bins
=
self
.
histogram_resolution
()
x
=
linspace
(
-
1.0
,
1.0
,
num
=
bins
)
return
(
1
/
pi
)
/
sqrt
(
1
-
x
**
2
)
Mt
=
len
(
self
.
data
)
A
=
sin
(
pi
/
2
*
Mt
/
(
Mt
+
self
.
data
[
0
]
+
self
.
data
[
-
1
]))
range
=
2
**
self
.
nbits
midrange
=
range
/
2
n
=
arange
(
1
,
range
-
1
)
p
=
arcsin
(
A
/
midrange
*
(
n
-
midrange
))
q
=
arcsin
(
A
/
midrange
*
(
n
-
1
-
midrange
))
p
=
(
p
-
q
)
/
pi
# t = linspace(-1, 1, 2**self.nbits)[1:-1]
# print sum(1/pi * 1/sqrt(1-t**2) / 2**self.nbits * Mt)
# return 1/pi * 1/sqrt(1-t**2) / 2**self.nbits * Mt
return
Mt
*
p
def
DNL
(
self
):
"""Compute differential non-linearity vector for a given time-domain
...
...
@@ -71,7 +100,11 @@ class Signal(object):
- dnl is an array of 2**signal.nbits real values and
- total is a real value (computed from dnl)
"""
return
[
3
]
*
(
2
*
self
.
nbits
),
0.3
ideal
=
self
.
ideal_histogram
()
real
=
self
.
histogram
()
print
size
(
ideal
),
size
(
real
)
dnl
=
real
/
ideal
-
1
return
dnl
,
max
(
abs
(
dnl
))
def
INL
(
self
):
...
...
@@ -81,7 +114,9 @@ class Signal(object):
- inl is an array of 2**signal.nbits real values and
- total is a real (computed from inl)
"""
return
[
4
]
*
(
2
*
self
.
nbits
),
0.4
dnl
,
discard
=
self
.
DNL
()
inl
=
cumsum
(
dnl
)
return
inl
,
max
(
abs
(
inl
))
def
FFT
(
self
,
navg
,
window
):
"""Compute the amplitudes (in dB) of the FFT of signal, averaging navg
...
...
@@ -93,3 +128,37 @@ class Signal(object):
returns: an FFTSignal object
"""
return
FFTSignal
(
self
.
data
,
1
,
1
)
def
makesine
(
samples
,
periods
,
bits
,
amplitude
=
1
,
noise
=
0
):
t
=
arange
(
samples
)
/
float
(
samples
)
sine
=
amplitude
*
sin
(
2
*
pi
*
periods
*
t
)
sine
+=
noise
*
((
t
%
0.02
)
/
0.02
-
0.01
)
sine
=
(
sine
*
2
**
bits
+
0.5
)
.
astype
(
int
)
place
(
sine
,
sine
>=
2
**
bits
,
2
**
bits
)
place
(
sine
,
sine
<=
-
2
**
bits
,
-
2
**
bits
)
out
=
file
(
'data'
,
'w'
)
for
datum
in
sine
:
out
.
write
(
str
(
datum
)
+
'
\n
'
)
out
.
close
()
return
sine
if
__name__
==
'__main__'
:
from
matplotlib
import
pyplot
bits
=
12
makesine
(
20000
,
20
,
bits
,
1.1
)
f
=
[
int
(
sample
)
for
sample
in
file
(
'data'
)]
s
=
Signal
(
nbits
=
bits
,
rate
=
123
,
data
=
f
)
ideal
=
s
.
ideal_histogram
()
real
=
s
.
histogram
()
# pyplot.plot(ideal)
# pyplot.plot(real)
dnl
=
real
/
ideal
-
1
pyplot
.
plot
(
dnl
)
pyplot
.
plot
(
cumsum
(
dnl
))
# pyplot.plot(f)
pyplot
.
show
()
print
dnl
[
0
:
5
],
dnl
[
-
5
:]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment