-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,569 additions
and
411 deletions.
There are no files selected for viewing
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import numpy as np | ||
from wifi.preambler import long_training_symbol | ||
|
||
|
||
def undo(long_training, carriers): | ||
long_training = np.array(long_training[32:]) | ||
avg_training = (long_training[:64] + long_training[64:128]) / 2 | ||
channel_estimate = np.fft.fft(avg_training) / long_training_symbol() | ||
equalizer = 1 / channel_estimate | ||
|
||
result = np.array(carriers) * equalizer | ||
return result.tolist() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import List | ||
import numpy as np | ||
from hypothesis import given | ||
from hypothesis._strategies import lists, complex_numbers | ||
from wifi.to_time_domain import OFDMFrame | ||
|
||
SIZE = 16 | ||
|
||
|
||
def do(frames: List[OFDMFrame]) -> List[OFDMFrame]: | ||
return [frame[-SIZE:] + frame for frame in frames] | ||
|
||
|
||
def undo(frames: List[OFDMFrame]) -> List[OFDMFrame]: | ||
return [frame[SIZE:] for frame in frames] | ||
|
||
|
||
@given(lists(lists(complex_numbers(), min_size=64, max_size=64), min_size=1, max_size=32)) | ||
def test_hypothesis(data): | ||
un = undo(do(data)) | ||
np.testing.assert_equal(data, un) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from hypothesis import given | ||
from hypothesis._strategies import lists, complex_numbers | ||
from more_itertools import flatten, chunked | ||
|
||
from wifi import guard_interval | ||
|
||
|
||
def do(train_short, train_long, frames): | ||
parts = [train_short] + [train_long] + frames | ||
|
||
for i in range(1, len(parts)): | ||
parts[i][0] = (parts[i - 1][-64] + parts[i][0]) / 2 | ||
|
||
result = list(flatten(parts)) | ||
|
||
# smoother power on/off | ||
result[0] /= 2 | ||
result.append(result[-64] / 2) | ||
|
||
return result | ||
|
||
|
||
# not a perfect reconstuction! | ||
def undo(iq): | ||
short = iq[:160] | ||
long = iq[160:320] | ||
|
||
frame_size = guard_interval.SIZE + 64 | ||
frames = list(chunked(iq[320:], frame_size)) | ||
if len(frames[-1]) != frame_size: | ||
frames = frames[:-1] | ||
|
||
return short, long, frames | ||
|
||
|
||
@given(lists(lists(complex_numbers(), min_size=80, max_size=80), min_size=1, max_size=32)) | ||
def test_hypothesis(frames): | ||
from wifi import preambler | ||
short = preambler.short_training_sequence() | ||
long = preambler.long_training_sequence() | ||
|
||
res_short, res_long, res_frames = undo(do(short, long, frames)) | ||
|
||
# 'do' contaminates the first sample of each symbol, cannot be restored with 'undo' | ||
assert res_short[1:] == short[1:] | ||
assert res_long[1:] == long[1:] | ||
for frame, res_frame in zip(frames, res_frames): | ||
assert frame[1:] == res_frame[1:] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from typing import List | ||
import numpy as np | ||
from hypothesis import given | ||
from hypothesis._strategies import lists, complex_numbers | ||
from wifi.subcarrier_mapping import Carriers | ||
|
||
PILOT_POLARITY = [1, 1, 1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, | ||
-1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, | ||
-1, -1, 1, 1, -1, -1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1, 1, | ||
1, -1, 1, -1, 1, -1, 1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, 1, | ||
1, 1, -1, -1, -1, -1, -1, -1, -1] | ||
|
||
|
||
def do_one(carriers: Carriers, index_in_package: int) -> Carriers: | ||
pilots = np.array([1, 1, 1, -1], dtype=complex) * PILOT_POLARITY[index_in_package % 127] | ||
carriers[-21] = pilots[0] | ||
carriers[-7] = pilots[1] | ||
carriers[7] = pilots[2] | ||
carriers[21] = pilots[3] | ||
|
||
return carriers | ||
|
||
|
||
def undo_one(carriers: Carriers, index_in_package: int) -> Carriers: | ||
|
||
pilots = np.empty(4, dtype=complex) | ||
pilots[0] = carriers[-21] | ||
pilots[1] = carriers[-7] | ||
pilots[2] = carriers[7] | ||
pilots[3] = carriers[21] | ||
|
||
# remove latent frequency offset by using pilot symbols | ||
pilots *= PILOT_POLARITY[index_in_package % 127] | ||
mean_phase_offset = np.angle(np.mean(pilots)) | ||
carriers = np.array(carriers) * np.exp(-1j * mean_phase_offset) | ||
|
||
return carriers.tolist() | ||
|
||
|
||
def do(carriers: List[Carriers]) -> List[Carriers]: | ||
return [do_one(carrier, index) for index, carrier in enumerate(carriers)] | ||
|
||
|
||
def undo(carriers: List[Carriers]) -> List[Carriers]: | ||
return [undo_one(carrier, index) for index, carrier in enumerate(carriers)] | ||
|
||
|
||
@given(lists(lists(complex_numbers(allow_nan=False, allow_infinity=False), min_size=64, max_size=64), min_size=1, max_size=32)) | ||
def test_hypothesis(data): | ||
un = undo(do(data)) | ||
np.testing.assert_allclose(data, un, rtol=1e-16, atol=1e-16) |
Oops, something went wrong.