Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def czasProbkowania2(t,f):
- #funkcja do probkowania czasu
- #input:
- #t - czas, przez ktory probkujemy
- #f - czestotliwoac probkowania
- # dla t = 1 i f = 10 stworzy nam wartosci od 0 do 1 z krokiem co 0.1
- #output lista z momentami w ktorych probkujemy
- iloscProbek = int(t / (1 / f))
- time = []
- time.append(0)
- for x in range(iloscProbek):
- time.append((1 / f) * (x + 1))
- return time
- def word_to_ascii(word):
- """
- :param word: word in ascii code numbered from 32 to 127
- :return: string with concatenate binary values
- """
- txt = ''
- for c in word:
- txt += str(bin(ord(c))[2:].zfill(8))
- return txt
- def kluczowanie_amplitudy(binary, T, fn, N):
- """
- :param binary: string value with binary 8bits values
- :param T: time list with subsequent frequencies
- :param fn: frequency
- :return: modulated signal list with elements
- """
- # parametry A1 i A2 przy czym A1 != A2 określają wielkość amplitudy
- A1 = 5
- A2 = 10
- result = []
- # dla każdej wartości z czasu
- for t in T:
- #print(t)
- index = int(T.index(t)/N)
- #print("index " +str(index))
- if(int(binary[index]) == 0):
- result.append(A1 * mt.sin(2*mt.pi * fn * index))
- elif(int(binary[index]) == 1):
- result.append(A2 * mt.sin(2*mt.pi * fn * index))
- return result
- def kluczowanie_czestotliwosci(binary, T, N, Tb):
- """
- :param binary: string value with binary 8bits values
- :param T: time list with subsequent frequencies
- :param N: wielokrotność Tb
- :param Tb: single bit processing time
- :return: modulated signal list with elements
- """
- fn1 = (N+1)/Tb
- fn2 = (N+2)/Tb
- result = []
- # dla każdej wartości z ciagu znakowego
- for t in T:
- index = int(T.index(t) / N)
- if (int(binary[index]) == 0):
- result.append(mt.sin(2*mt.pi * fn1 * index))
- elif (int(binary[index]) == 1):
- result.append(mt.sin(2*mt.pi * fn2 * index))
- return result
- def kluczowanie_fazy(binary, T, fn):
- """
- :param binary: string value with binary 8bits values
- :param T: time list with subsequent frequencies
- :param fn: frequency
- :return: modulated signal list with elements
- """
- result = []
- # dla każdej wartości z ciagu znakowego
- for t in T:
- index = int(T.index(t) / N)
- if (int(binary[index]) == 0):
- result.append(mt.sin(2*mt.pi * fn))
- elif (int(binary[index]) == 1):
- result.append(mt.sin(2*mt.pi * fn + mt.pi))
- return result
- # string
- s = "KUBAW"
- # czas trwania sygnału w sekundach
- czas = 8
- # ilość bitów przetwarzanych na sekunde
- ilosc_bitow = len(s)*8
- # czas pojedynczego bitu
- Tb = czas/(ilosc_bitow)
- print("Tb " + str(Tb))
- # wielokrotność odwrotności Tb
- N=2
- # czestotliwosc
- fn = (N)/mt.pow(Tb, -1)
- print("fn " + str(fn))
- binary = word_to_ascii(s)
- print(binary)
- # mnożniki do generowania sygnału czasowego
- factor1 = 10000
- factor2 = 0.0001
- # zmienne tymczasowe
- tt = int(czas*factor1 + fn*factor1)
- diff = int(fn*factor1)
- # generowanie czasu
- T = [x*factor2 for x in range(0, tt, diff)]
- print(T)
- # ------------- obliczanie sygnałów zmodulowanych
- klucz_1 = kluczowanie_amplitudy(binary, T, fn, N)
- plt.plot(T, klucz_1)
- plt.show()
- # dla pojedynczego czasu Tb
- TT = czasProbkowania(Tb, 20)
- TT.pop()
- print(len(TT))
- A1 = 2
- A2 = 4
- result = []
- fn = 20
- for t in TT:
- if (int(binary[0]) == 0):
- result.append(A1 * mt.sin(2 * mt.pi * fn * t))
- elif (int(binary[0]) == 1):
- result.append(A2 * mt.sin(2 * mt.pi * fn * t))
- print(TT)
- print(result)
- plt.plot(TT, result)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement