-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQPSK2.py
More file actions
104 lines (80 loc) · 2.01 KB
/
Copy pathQPSK2.py
File metadata and controls
104 lines (80 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*- coding: utf-8 -*-
##
## Author: Emil Svendsen
## Date: 27/11-2018
## Last edit: 27/11-2018
##
## QPSK
import scipy.signal as signal
import scipy.fftpack as fft
import numpy as np
import matplotlib.pyplot as plt
## Local files
import lowpass
import noise
a = 2 * np.random.randint(0, 2, 8) -1
b = np.add(np.multiply(2, [1,0,1,0,1,0,1,0]), -1)
Nbits = len(a)
## Pulse length
T = 0.01
## Sampling periode
Ts = 1e-4
## Sampling frequency
fs = 1 / Ts
## Makes 1D array with length of (T / Ts)
g = np.ones(int(T / Ts))
## Makes one big matrix size (g x a)
x = np.outer(g, a)
## Make it into one big 1D array
x = np.matrix.flatten(x, order='F')
## Makes one big matrix size (g x b)
y = np.outer(g, b)
## Make it into one big 1D array
y = np.matrix.flatten(y, order='F')
## Number of samples
Nsamples = (T / Ts) * Nbits
## Time vector
t = np.arange(0, (Nsamples) * Ts, Ts)
## Carrier frequency
fc = 2000
## Carrier waves
cosfc = np.cos(2 * np.pi * fc * t)
sinfc = np.sin(2 * np.pi * fc * t)
## Element wise multiply and add
v = np.add(np.multiply(x, cosfc), np.multiply(y, sinfc))
## Frequency definition # Sample frequency / Nsamples
df = fs / Nsamples
## Only positive frequencies
f = np.arange(0, (df * Nsamples / 2), df)
## Only negative frequencies
fNeg = np.multiply(np.fliplr([np.arange(0+df, (df * Nsamples / 2) + df, df)]), -1)
## All frequencies
f = np.concatenate((fNeg, f), axis = None)
## Add noise
noise = noise.noise(Nsamples)
v = np.add(v, noise)
## Demodulate
i = np.multiply(v, cosfc)
q = np.multiply(v, sinfc)
## Lowpass
test1 = lowpass.lowpass(i, Ts, fs, 1000)
test2 = lowpass.lowpass(q, Ts, fs, 1000)
plt.subplot(5,2,1)
plt.plot(x)
plt.subplot(5,2,2)
plt.plot(y)
plt.subplot(5,2,3)
plt.plot(t, np.multiply(x, cosfc))
plt.subplot(5,2,4)
plt.plot(t, np.multiply(y, sinfc))
plt.subplot(5,2,5)
plt.plot(t, i)
plt.subplot(5,2,6)
plt.plot(t, q)
plt.subplot(5,2,7)
plt.plot(t, test1[np.arange(10,810)])
plt.subplot(5,2,8)
plt.plot(t, test2[np.arange(10,810)])
plt.subplot(5,2,9)
plt.plot(t, v)
plt.show()