-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
235 lines (187 loc) · 7.38 KB
/
app.py
File metadata and controls
235 lines (187 loc) · 7.38 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
from dotenv import load_dotenv
from flask import Flask,render_template,request,redirect,url_for
from flask_cors import CORS
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import os
import base64
from modulation import *
from binascii import unhexlify
import logging
import json
logger = logging.getLogger('waitress')
logger.setLevel(logging.INFO)
matplotlib.use('WebAgg')
load_dotenv()
app=Flask(__name__,static_url_path='/static')
CORS(app)
@app.template_filter('decode_hex')
def decode_hex(s):
return unhexlify(s)
@app.template_filter('b64encode')
def b64encode(s):
return base64.b64encode(s).decode('utf-8')
@app.route('/',methods=['GET'])
def home():
f = open('./data.json')
data = json.load(f)["Home"]
return render_template('home.html',data=data)
@app.route('/references',methods=['GET'])
def references():
return render_template('references.html')
@app.route('/theory/<modulation_type>',methods=["GET"])
def theory(modulation_type):
return render_template(f'theory/{modulation_type}.html')
# ---------- Analog Modulation -------------------
@app.route('/AM',methods=['GET'])
def AM_page():
f = open('./data.json')
data = json.load(f)["AM"]
return render_template('Analog_Modulation.html',data=data)
@app.route('/AM/<am_type>',methods=['GET','POST'])
def Amplitutde_Modulation(am_type):
title = {"MAIN":"Amplitutde Modulation","SSB":"SSB Modulation","DSBSC":"DSB Modulation","QAM":"QAM Modulation"}
print(am_type)
plots = []
x_message = []
x_carrier = []
content_type = request.headers.get('Content-Type')
if (request.method=='POST'):
if (content_type == 'application/json'):
content = request.json
else:
content = request.form
print(content)
fm=int (content['fm'])
fc=int (content['fc'])
Am=int (content['Am'])
Ac=int (content['Ac'])
message_signal = str(content['message_signal'])
inputs = [Am,Ac,fm,fc,message_signal]
if am_type == "MAIN":
plots = AM_main_graph(inputs)
elif am_type == "SSB":
plots = AM_ssb_modulation(inputs)
elif am_type == "DSBSC":
phi = float(request.form['phi'])
inputs.append(phi)
plots = AM_double_sideband_modulation(inputs)
elif am_type == "QAM":
message_signal_2 = request.form['message_signal_2']
inputs.append(message_signal_2)
plots = AM_QAM(inputs)
return render_template('AM_graphs.html',am_type=am_type.upper(),title=title[am_type],plots = plots,inputs=inputs)
return render_template('AM_graphs.html',am_type=am_type.upper(),title=title[am_type],plots = plots)
@app.route('/FM/<index>',methods=['GET','POST'])
def FM(index):
images = []
index = int(index)
title={1:"Frequency modulation",2:"Phase modulation"}
if request.method == 'POST':
fm=int (request.form['fm'])
fc=int (request.form['fc'])
Am=int (request.form['Am'])
Ac=int (request.form['Ac'])
message_signal = str(request.form['message_signal'])
K = int(request.form['K'])
inputs = [Am,Ac,fm,fc,message_signal,K]
x = np.linspace(-200,200,10000) #domain for the modulated_wave
s = [1 for i in x]
if(index==1):
images = FM_MAIN(x,inputs)
elif(index==2):
images = PHASE_MAIN(x,inputs)
# elif(index==3):
# PULSE_MAIN(x,inputs)
return render_template('fm_graphs.html',title=title[index],index=index,plots=images)
# ---------- End of Analog Modulation ------------
# ---------- Digital Modulation ---------------------
@app.route('/DM',methods=['GET'])
def DM_page():
f = open('./data.json')
data = json.load(f)["DM"]
return render_template('Digital_Modulation.html',data=data)
@app.route('/DM/<dmtype>', methods=['GET','POST'])
def DigitalModulation(dmtype):
title = {"BPSK":"BPSK Modulation","BFSK":"BFSK Modulation","BASK":"BASK Modulation","QPSK":"QPSK Modulation"}
plots = []
if (request.method=='POST'):
Tb=float (request.form['Tb'])
fc=int (request.form['fc'])
binaryInput = str(request.form['inputBinarySeq'])
fc2=1
if(dmtype=='BFSK'):
fc2=int (request.form['fc2'])
# Change Binary string to array
inputBinarySeq = np.array(list(binaryInput), dtype=int)
if dmtype.upper() == 'BASK':
plots = BASK(Tb, fc, inputBinarySeq)
elif dmtype.upper() == 'BFSK':
plots = BFSK(Tb, fc, fc2, inputBinarySeq)
elif dmtype.upper() == 'BPSK':
plots = BPSK(Tb, fc, inputBinarySeq)
elif dmtype.upper() == 'QPSK':
plots = QPSK(Tb, fc, inputBinarySeq)
return render_template('DM_graphs.html',dmtype=dmtype.upper(),title=title[dmtype], plots=plots)
@app.route('/DM2/<dmtype>', methods=['GET','POST'])
def GMSK_Modulation(dmtype):
title = {"GMSK":"GMSK Modulation"}
plots = []
if (request.method=='POST'):
fm=int (request.form['fm'])
am=int (request.form['am'])
pm=int (request.form['pm'])
fc=int (request.form['fc'])
ac=int (request.form['ac'])
pc=int (request.form['pc'])
# --
if dmtype.upper() == 'GMSK':
plots = GMSK(fm, am, pm, fc, ac, pc)
return render_template('GMSK_graphs.html',dmtype=dmtype.upper(),title=title[dmtype], plots=plots)
# ------------ End of Digital Modulation -------------
# ---------- Pulse Modulation ---------------------
@app.route('/PM',methods=['GET'])
def PM_page():
f = open('./data.json')
data = json.load(f)["PM"]
return render_template('Pulse_Modulation.html',data=data)
@app.route('/PM/<pmtype>', methods=['GET','POST'])
def PulseModulation(pmtype):
title = {"Sampling":"Sampling",
"Quantization":"Quantization",
"PAM":"Pulse Amplitude Modulation",
"PPM":"Pulse Phase Modulation",
"PCM":"Pulse Position Modulation",
"PWM":"Pulse Width Modulation"
}
plots = []
inputs = []
print(request.form)
if (request.method=='POST'):
fm = int (request.form['fm'])
am = int (request.form['am'])
fc = int (request.form['fc'])
ac = int (request.form['ac'])
message_type = str(request.form["message_signal"])
inputs = [am,ac,fm,fc,message_type]
# Change Binary string to array
print(pmtype)
if pmtype.upper() == 'PPM':
ppm_ratio = float(request.form['ppm_ratio'])
inputs.append(ppm_ratio)
plots = PPM(inputs)
elif pmtype.upper() == 'PAM':
inputs.append(int(request.form['fs']))
plots = PAM(inputs)
elif pmtype.upper() == 'BPSK':
plots = BPSK(Tb, fc, inputBinarySeq)
elif pmtype.upper() == 'QPSK':
plots = QPSK(Tb, fc, inputBinarySeq)
return render_template('PM_graphs.html',pmtype=pmtype.upper(),title=title[pmtype], plots=plots)
def create_app():
from waitress import serve
PORT = int(os.environ.get("PORT",8000))
serve(app, host="0.0.0.0", port=PORT)
if __name__ == "__main__":
create_app()