Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
peads committed Jul 30, 2024
1 parent 12cf3f0 commit 3acd1bc
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions test/dsp/iq_correction_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from dsp.iq_correction import IQCorrection
# from dsp.iq_correction import IQCorrection

DEFAULT_SAMPLE_RATE = 2000
DEFAULT_IMPEDANCE = 50
Expand All @@ -10,33 +10,27 @@


@pytest.fixture
def correctors():
ret = [IQCorrection(DEFAULT_SAMPLE_RATE), ]
def corrector():
try:
from dsp.fast import iq_correction
print('Imported pre-compiled IQCorrection class')
ret.append(iq_correction.IQCorrection(DEFAULT_SAMPLE_RATE))
return iq_correction.IQCorrection(DEFAULT_SAMPLE_RATE)
except ImportError:
pass
return ret


def test_iqCorrection(correctors):
someData = np.array([[0j, 1 + 2j, 2 + 3j, 3 + 4j, 4 + 5j, 5 + 6j, 6 + 7j, 7 + 8j],
[0j, 1 + 2j, 2 + 3j, 3 + 4j, 4 + 5j, 5 + 6j, 6 + 7j, 7 + 8j],
[0j, 1 + 2j, 2 + 3j, 3 + 4j, 4 + 5j, 5 + 6j, 6 + 7j, 7 + 8j]])
offset = np.zeros(3, dtype=np.complex128)
someCorrectedData = np.array(someData)
inductance = np.array((DEFAULT_IMPEDANCE, NEXT_IMPEDANCE))/ DEFAULT_SAMPLE_RATE
inductance = np.append(inductance, NEXT_IMPEDANCE / NEXT_SAMPLE_RATE)

for i in range(someData.shape[0]):
# someCorrectedData[i][:] = someCorrectedData[i][:] - offset
for j in range(someData.shape[1]):
someCorrectedData[i][j] -= offset[i]
offset[i] += someCorrectedData[i][j] * inductance[i]

for i, corrector in enumerate(correctors):
return None


def test_iqCorrection(corrector):
if corrector is not None:
someData = np.array([0j, 1 + 2j, 2 + 3j, 3 + 4j, 4 + 5j, 5 + 6j, 6 + 7j, 7 + 8j])
offset = np.array([0j])
off = np.array(0j)
someCorrectedData = np.array(someData)
inductance = NEXT_IMPEDANCE / NEXT_SAMPLE_RATE

for j in range(someData.shape[0]):
someCorrectedData[j] -= off
off += someCorrectedData[j] * inductance

assert corrector.fs == DEFAULT_SAMPLE_RATE
assert corrector.inductance == DEFAULT_IMPEDANCE / DEFAULT_SAMPLE_RATE

Expand All @@ -45,11 +39,11 @@ def test_iqCorrection(correctors):
assert corrector.inductance == DEFAULT_IMPEDANCE / NEXT_SAMPLE_RATE

corrector.impedance = NEXT_IMPEDANCE
assert corrector.inductance == NEXT_IMPEDANCE / NEXT_SAMPLE_RATE
assert corrector.inductance == inductance

size = someData.size
corrector.correctIq(someData[i])
corrector.correctIq(someData, offset)
assert someData.size == size
assert someCorrectedData.size == size
for x, y in zip(someData[i], someCorrectedData[2]):
assert x == y
for x, y in zip(someData, someCorrectedData):
assert np.fabs(np.abs(x - y)) < 10E-2

0 comments on commit 3acd1bc

Please sign in to comment.