-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
Introduce Spatial Consistencyy Closes #210 and #208 See merge request barkhauseninstitut/wicon/hermespy!186
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,68 +11,58 @@ | |
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
from hermespy.modem import Modem, RootRaisedCosineWaveform, SingleCarrierCorrelationSynchronization, SingleCarrierLeastSquaresChannelEstimation, SingleCarrierZeroForcingChannelEqualization | ||
from hermespy.core.scenario import Scenario | ||
from hermespy.modem.waveform_single_carrier import SingleCarrierSynchronization | ||
from hermespy.simulation import SimulatedDevice | ||
from hermespy.modem.bits_source import StreamBitsSource | ||
from hermespy.channel import TDL, TDLType | ||
from hermespy.fec import Scrambler3GPP | ||
from hermespy.modem import SimplexLink, RootRaisedCosineWaveform, SingleCarrierLeastSquaresChannelEstimation, SingleCarrierZeroForcingChannelEqualization, StreamBitsSource | ||
from hermespy.simulation import SimulationScenario | ||
|
||
__author__ = "Jan Adler" | ||
__copyright__ = "Copyright 2023, Barkhausen Institut gGmbH" | ||
__copyright__ = "Copyright 2024, Barkhausen Institut gGmbH" | ||
__credits__ = ["Jan Adler"] | ||
__license__ = "AGPLv3" | ||
__version__ = "0.2.7" | ||
__version__ = "1.2.0" | ||
__maintainer__ = "Jan Adler" | ||
__email__ = "[email protected]" | ||
__status__ = "Prototype" | ||
|
||
|
||
# Create a new HermesPy simulation scenario | ||
scenario = Scenario[SimulatedDevice]() | ||
scenario = SimulationScenario() | ||
|
||
# Create a new simulated device | ||
device = SimulatedDevice() | ||
scenario.add_device(device) | ||
carrier_frequency = 1e8 | ||
tx_device = scenario.new_device(carrier_frequency=carrier_frequency) | ||
rx_device = scenario.new_device(carrier_frequency=carrier_frequency) | ||
scenario.set_channel(rx_device, tx_device, TDL(TDLType.E)) | ||
|
||
waveform = RootRaisedCosineWaveform(symbol_rate=1e6, num_preamble_symbols=0, num_data_symbols=40, oversampling_factor=8, roll_off=.9) | ||
waveform = RootRaisedCosineWaveform(symbol_rate=1e6, num_preamble_symbols=0 , num_data_symbols=120, oversampling_factor=4, roll_off=.9) | ||
waveform.num_preamble_symbols = 128 | ||
waveform.num_data_symbols = 1024 | ||
waveform.modulation_order = 4 | ||
waveform.synchronization = SingleCarrierSynchronization() | ||
waveform.num_data_symbols = 2048 | ||
waveform.modulation_order = 256 | ||
waveform.channel_estimation = SingleCarrierLeastSquaresChannelEstimation() | ||
waveform.channel_equalization = SingleCarrierZeroForcingChannelEqualization() | ||
|
||
device.sampling_rate = waveform.sampling_rate | ||
|
||
source = StreamBitsSource(os.path.join(os.path.dirname(__file__), '../resources/leena.raw')) | ||
leena_num_bits = 512 * 512 * 8 | ||
image_buffer = np.zeros((512, 512), dtype=np.uint8) | ||
image_buffer[0, 0] = 255 | ||
|
||
# Add a modem at the simulated device | ||
modem = Modem() | ||
modem.device = device | ||
modem.bits_source = source | ||
modem.waveform = waveform | ||
link = SimplexLink(tx_device, rx_device, waveform=waveform) | ||
link.encoder_manager.add_encoder(Scrambler3GPP()) | ||
link.bits_source = StreamBitsSource(os.path.join(os.path.dirname(__file__), '../resources/leena.raw')) | ||
|
||
# Compute number of required frames | ||
bits_per_frame = modem.num_data_bits_per_frame | ||
bits_per_frame = link.num_data_bits_per_frame | ||
byte_per_frame = int(bits_per_frame / 8) | ||
num_frames = int(leena_num_bits / bits_per_frame) | ||
|
||
plt.ion() | ||
fig, axes = plt.subplots() | ||
image = axes.imshow(image_buffer) | ||
image = axes.imshow(image_buffer, cmap='gray', vmin=0, vmax=255) | ||
|
||
for f in range(num_frames): | ||
|
||
tx_signal, tx_symbols, tx_bits = modem.transmit() | ||
device_transmissions = device.transmit(clear_cache=True) | ||
device.receive_signal(device_transmissions[0]) # , snr=8.) | ||
rx_signal, rx_symbols, data_bits = modem.receive() | ||
|
||
if len(data_bits) > 0: | ||
image_buffer.flat[f*byte_per_frame:(f+1)*byte_per_frame] = np.packbits(data_bits) | ||
drop = scenario.drop() | ||
if link.reception.bits.size > 0: | ||
image_buffer.flat[f*byte_per_frame:(f+1)*byte_per_frame] = np.packbits(link.reception.bits) | ||
image.set_data(image_buffer) | ||
fig.canvas.flush_events() | ||
|
||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.