|
|
@@ -297,14 +297,14 @@ class ModulationModel(tf.keras.Model):
|
|
|
plt.show()
|
|
|
pass
|
|
|
|
|
|
- def plot(self, inputs, signal, size):
|
|
|
- t = np.arange(self.messages_per_block * self.samples_per_symbol)
|
|
|
+ def plot(self, inputs, signal):
|
|
|
+ t = np.arange(self.messages_per_block * self.samples_per_symbol*3)
|
|
|
frequency = SAMPLING_FREQUENCY*1e-9
|
|
|
t = np.divide(t, frequency)
|
|
|
plt.figure()
|
|
|
- plt.plot(t, signal.flatten()[:self.messages_per_block * self.samples_per_symbol], label='Received Signal')
|
|
|
+ plt.plot(t, signal.flatten()[:self.messages_per_block * self.samples_per_symbol*3], label='Received Signal')
|
|
|
inputs = np.square(inputs)
|
|
|
- plt.plot(t, inputs.flatten()[:self.messages_per_block * self.samples_per_symbol], label='Transmitted Signal')
|
|
|
+ plt.plot(t, inputs.flatten()[:self.messages_per_block * self.samples_per_symbol*3], label='Transmitted Signal')
|
|
|
plt.xlabel('Time (ns)')
|
|
|
plt.ylabel('Power')
|
|
|
plt.title('Effect of Chromatic Dispersion and Noise on Generated Signal')
|
|
|
@@ -312,11 +312,13 @@ class ModulationModel(tf.keras.Model):
|
|
|
plt.show()
|
|
|
|
|
|
def demodulate(self, validation, outputs):
|
|
|
- b, a = bessel(5, 2 / 45, btype='low', analog=False)
|
|
|
+ symbol_rate = SAMPLING_FREQUENCY/SAMPLES_PER_SYMBOL
|
|
|
+
|
|
|
+ b, a = bessel(5, 10*(symbol_rate)/(SAMPLING_FREQUENCY/2), btype='low', analog=False)
|
|
|
outputsfilt = filtfilt(b, a, outputs)
|
|
|
demodulate = np.sqrt(outputsfilt)
|
|
|
- modulation_scheme.plot(inputs, demodulate, size)
|
|
|
- average = np.mean(outputs.reshape(1000, -1, SAMPLES_PER_SYMBOL), axis=2).flatten()
|
|
|
+ #modulation_scheme.plot(inputs, demodulate)
|
|
|
+ average = np.mean(demodulate.reshape(1000, -1, SAMPLES_PER_SYMBOL), axis=2).flatten()
|
|
|
validation = validation.flatten()
|
|
|
decisions = []
|
|
|
for symbol in average:
|
|
|
@@ -329,7 +331,15 @@ class ModulationModel(tf.keras.Model):
|
|
|
else:
|
|
|
decisions.append(3)
|
|
|
decisions = np.array(decisions)
|
|
|
- return decisions
|
|
|
+ error = 0
|
|
|
+ index = 0
|
|
|
+ while index < len(validation):
|
|
|
+ if validation[index] != decisions[index]:
|
|
|
+ error += 1
|
|
|
+ index += 1
|
|
|
+
|
|
|
+ #print("ber = " + str(error/len(validation)))
|
|
|
+ return error/len(validation)
|
|
|
|
|
|
|
|
|
def call(self, inputs, training=None, mask=None):
|
|
|
@@ -337,15 +347,50 @@ class ModulationModel(tf.keras.Model):
|
|
|
rx = self.channel(tx)
|
|
|
outputs = self.decoder(rx)
|
|
|
return outputs
|
|
|
+def plot_output_graphs():
|
|
|
+ inputs, validation = modulation_scheme.generate_random_inputs(num_of_blocks=size)
|
|
|
+ outputs = optical_channel(inputs).numpy()
|
|
|
+ b, a = bessel(5, 10 * (SAMPLING_FREQUENCY/SAMPLES_PER_SYMBOL) / (SAMPLING_FREQUENCY / 2), btype='low', analog=False)
|
|
|
+ outputsfilt = filtfilt(b, a, outputs)
|
|
|
+ modulation_scheme.plot(inputs, outputs)
|
|
|
+ modulation_scheme.plot(inputs, outputsfilt)
|
|
|
+
|
|
|
+ #ber.append(modulation_scheme.demodulate(validation, outputs))
|
|
|
+def plot_fibre_length_vs_ber():
|
|
|
+ lengths = np.linspace(5, 50, 200)
|
|
|
+ ber =[]
|
|
|
+ for length in lengths:
|
|
|
+ optical_channel = OpticalChannel(fs=SAMPLING_FREQUENCY,
|
|
|
+ num_of_samples=MESSAGES_PER_BLOCK * SAMPLES_PER_SYMBOL,
|
|
|
+ dispersion_factor=DISPERSION_FACTOR,
|
|
|
+ fiber_length=length)
|
|
|
+
|
|
|
+ inputs, validation = modulation_scheme.generate_random_inputs(num_of_blocks=size)
|
|
|
+ outputs = optical_channel(inputs).numpy()
|
|
|
+ ber.append(modulation_scheme.demodulate(validation, outputs))
|
|
|
+
|
|
|
+ plt.figure()
|
|
|
+ plt.semilogy(lengths, ber, label='ber')
|
|
|
+ plt.xlabel('Fibre Length (km)')
|
|
|
+ plt.ylabel('BER')
|
|
|
+ plt.title('Effect of Fibre Length on BER of 4PAM System')
|
|
|
+ # Show the major grid lines with dark grey lines
|
|
|
+ plt.grid(b=True, which='major', color='#666666', linestyle='-')
|
|
|
+
|
|
|
+ # Show the minor grid lines with very faint and almost transparent grey lines
|
|
|
+ plt.minorticks_on()
|
|
|
+ plt.grid(b=True, which='minor', color='#999999', linestyle='-', alpha=0.2)
|
|
|
+ plt.legend()
|
|
|
+ plt.show()
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
SAMPLING_FREQUENCY = 336e9
|
|
|
CARDINALITY = 4
|
|
|
- SAMPLES_PER_SYMBOL = 128
|
|
|
+ SAMPLES_PER_SYMBOL = 64
|
|
|
MESSAGES_PER_BLOCK = 9
|
|
|
DISPERSION_FACTOR = -21.7 * 1e-24
|
|
|
- FIBER_LENGTH = 50
|
|
|
+ FIBER_LENGTH = 30
|
|
|
|
|
|
optical_channel = OpticalChannel(fs=SAMPLING_FREQUENCY,
|
|
|
num_of_samples=MESSAGES_PER_BLOCK * SAMPLES_PER_SYMBOL,
|
|
|
@@ -358,9 +403,10 @@ if __name__ == '__main__':
|
|
|
channel=optical_channel)
|
|
|
|
|
|
size = 1000
|
|
|
- inputs, validation = modulation_scheme.generate_random_inputs(num_of_blocks=size)
|
|
|
- outputs = optical_channel(inputs).numpy()
|
|
|
- decisions = modulation_scheme.demodulate(validation, outputs)
|
|
|
+ #inputs, validation = modulation_scheme.generate_random_inputs(num_of_blocks=size)
|
|
|
+ #outputs = optical_channel(inputs).numpy()
|
|
|
+ #decisions = modulation_scheme.demodulate(validation, outputs)
|
|
|
+ plot_fibre_length_vs_ber()
|
|
|
#modulation_scheme.plot(inputs, outputs, size)
|
|
|
print("done")
|
|
|
|