Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import random
- import matplotlib as mpl
- import math
- from scipy.io import wavfile
- sum_am = 9
- bits = 36
- samples = 500
- Tb = 0.2
- # 1o Eρώτημα (a)
- Amplitude = sum_am
- sequence = np.empty(bits,dtype = int) #δημιουργία πίνακα 36 θέσεων
- #σε κάθε θέση του πίνακα sequence θα μπεί 0 ή 1
- for i in range (bits):
- sequence[i] = random.randint(0,1)
- print(sequence)
- #Δημιουργία πίνακα για το BPAM , όπου θα είναι bits*samples θέσεων έτσι ώστε
- #για κάθε bit na υπάρχουν τόσα samples
- BPAM = np.empty(bits*samples,dtype = int)
- #αρχικοποίηση μεταβλητών που θα χρησιμοποιηθούν στα loops
- lowbound = 0
- upperbound = samples
- #Για κάθε 0 το πλάτος είναι -Αmplitude για κάθε 1 το πλάτος είναι +Amplitude
- for a in sequence :
- if(a == 0):
- for j in range (lowbound,upperbound):
- BPAM[j]= -Amplitude
- else:
- for j in range (lowbound,upperbound):
- BPAM[j] = Amplitude
- lowbound+=samples
- upperbound+=samples
- t = np.linspace(0,bits*Tb,bits*samples)
- plt.figure(figsize=(12,9))
- plt.figure(1)
- plt.plot(t, BPAM, label = 'Kωδικοποιημένο κατα BPAM ')
- plt.xlabel("Time (sec)")
- plt.ylabel("B-PAM modulation")
- plt.title("B-PAM modulation")
- plt.grid()
- plt.show()
- # 1o Eρώτημα (b)
- E=Amplitude**2*Tb
- f= BPAM/math.sqrt(E)
- Em = np.empty(bits*samples)
- for i in range (bits*samples):
- Em[i]=math.sqrt(E)
- plt.scatter(f,Em)
- plt.xlabel("φ1(t)")
- plt.ylabel("B-PAM modulation")
- plt.title("Διάγραμμα αστερισμού BPAM")
- plt.grid()
- plt.show()
- #1ο Ερώτημα (c)
- t2 = np.zeros(bits*samples)
- signal_power = Amplitude**2
- SNR1 = 6
- SNR2 = 12
- noise_power = signal_power/(2*math.sqrt(10**(SNR1/10)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement