-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting.py
More file actions
2050 lines (1692 loc) · 101 KB
/
plotting.py
File metadata and controls
2050 lines (1692 loc) · 101 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# =================================================================================================================================== #
# ----------------------------------------------------------- DESCRIPTION ----------------------------------------------------------- #
# This script connects to the MQTT broker, subscribes to the topics 'data/meas' and 'rfid/tde', and handles the received data. #
# It sends a message to the topic 'data/meas' with the parameters 'pos_x', 'pos_y', 'pos_z', and 'moist'. The script receives the #
# RFID data from the topic 'rfid/tde' and writes the data to a file. #
# =================================================================================================================================== #
# =================================================================================================================================== #
# --------------------------------------------------------- EXTERNAL IMPORTS -------------------------------------------------------- #
import pandas as pd # Data manipulation and analysis. #
import matplotlib.pyplot as plt # Data visualization. #
from mpl_toolkits.mplot3d import Axes3D # 3D plotting. #
import scipy.constants as sc # Physical and mathematical constants. #
import numpy as np # Mathematical functions. #
import src.data_management as dm # Data management functions. #
# =================================================================================================================================== #
# =================================================================================================================================== #
# ---------------------------------------------------- EXPECTED BEHAVIOUR (FRIIS) --------------------------------------------------- #
def MHz_to_Hz(frequency: float) -> float:
"""
Convert the frequency from MHz to Hz.
Parameters:
frequency (float): The frequency to convert from MHz to Hz.
Returns:
The frequency in Hz. [float]
"""
return frequency * 1e6
def dB_to_dBm(power: float) -> float:
"""
Convert the power from dB to dBm.
Parameters:
power (float): The power to convert from dB to dBm.
Returns:
The power in dBm. [float]
"""
return power + 30
def dBm_to_dB(power: float) -> float:
"""
Convert the power from dBm to dB.
Parameters:
power (float): The power to convert from dBm to dB.
Returns:
The power in dB. [float]
"""
return power - 30
def dBm_to_W(power: float) -> float:
"""
Convert the power from dBm to W.
Parameters:
power (float): The power to convert from dBm to W.
Returns:
The power in W. [float]
"""
return 10 ** (power / 10) / 1000
def get_lambda(frequency: float) -> float:
"""
Calculate the wavelength (lambda) from the frequency.
Parameters:
frequency (float): The frequency to calculate the wavelength from [Hz].
Returns:
The wavelength (lambda) from the frequency. [float]
"""
return sc.speed_of_light / frequency
def friis_equation_outward(power_tx: float, gain_tx: float, gain_rx: float, distance: float, wavelength: float) -> float:
"""
Calculate the expected power, in dB, by applying the Friis equation from the transmitter to the tag.
Parameters:
- power_tx: The power transmitted by the transmitter, in dB [float]
- gain_tx: The gain of the transmitter, in dBiL [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- distance: The distance between the transmitter and the receiver, in meters. [float]
- wavelength: The wavelength of the signal, in meters. [float]
Returns:
- The power received by the tag, in dB. [float]
"""
return power_tx + gain_tx + gain_rx + 20 * np.log10(wavelength / (4 * np.pi * distance))
def friis_equation_return(power_tx: float, gain_tx: float, gain_rx: float, distance: float, wavelength: float) -> float:
"""
Calculate the expected power, in dB, by applying the Friis equation from the tag to the receiver.
Parameters:
- power_tx: The power transmitted by the transmitter, in dB [float]
- gain_tx: The gain of the transmitter, in dBiL [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- distance: The distance between the transmitter and the receiver, in meters. [float]
- wavelength: The wavelength of the signal, in meters. [float]
Returns:
- The power received by the receiver, in dB. [float]
"""
return power_tx + gain_tx + gain_rx + 20 * np.log10(wavelength / (4 * np.pi * distance))
def friis_equation(power_tx: float, gain_tx: float, gain_rx: float, distance: float, frequency: float) -> float:
"""
Calculate the expected power, in dB, by applying the Friis equation twice. The first time, the power is calculated from the
transmitter to the tag, and the second time, from the tag to the receiver.
Parameters:
- power_tx: The power transmitted by the transmitter, in dB [float]
- gain_tx: The gain of the transmitter, in dBiL [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- distance: The distance between the transmitter and the receiver, in meters. [float]
- frequency: The frequency of the signal, in MHz. [float]
Returns:
- The power received by the receiver, in dB. [float]
"""
wavelength = get_lambda(MHz_to_Hz(frequency))
power_tag = friis_equation_outward(power_tx, gain_tx, gain_rx, distance, wavelength)
return friis_equation_return(power_tag, gain_tx, gain_rx, distance, wavelength)
def expected_behaviour(power_tx: float, gain_tx: float, gain_rx: float, distance: list, frequency: float) -> tuple:
"""
Obtains important information to plot: the double wavelength (Far Field), the triple wavelength (Far Field), and the expected
behaviour of the signal.
Parameters:
- power_tx: The power transmitted by the transmitter, in dB [float]
- gain_tx: The gain of the transmitter, in dBiL [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- distance: The distances between the transmitter and the receiver, in meters. [list]
- frequency: The frequency of the signal, in MHz. [float]
Returns:
- The double wavelength (Far Field), the triple wavelength (Far Field), and the expected behaviour of the signal. [tuple]
"""
wavelength = get_lambda(MHz_to_Hz(frequency))
two_lambda = 2 * wavelength
three_lambda = 3 * wavelength
return two_lambda, three_lambda, [friis_equation(power_tx, gain_tx, gain_rx, d, frequency) for d in distance]
def expected_fitted(power_tx: float, gain_tx: float, gain_rx: float, distance: list, frequency: float) -> list:
"""
Obtains important information to plot: the double wavelength (Far Field), the triple wavelength (Far Field), and the expected
behaviour of the signal. The parameters are the ones obtained from fitting.
Parameters:
- power_tx: The power transmitted by the transmitter, in dB [float]
- gain_tx: The gain of the transmitter, in dBiL [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- distance: The distances between the transmitter and the receiver, in meters. [list]
- frequency: The frequency of the signal, in MHz. [float]
Returns:
- The expected behaviour of the signal. [list]
"""
return [friis_equation(power_tx, gain_tx, gain_rx, d, frequency) for d in distance]
# =================================================================================================================================== #
# =================================================================================================================================== #
# ------------------------------------------------------ PLOTTING FUNCTIONS --------------------------------------------------------- #
def plot_rssi_distance(filenames: list, tag_name: str, frequency: float, obstacle: str, power_tx: float, gain_tx: float, gain_rx: float,
real_distances: list, distances: list, gain_antenna: float, gain_tag: float, fit: bool = False, individual_markers: bool = True):
"""
Plot the RSSI data (scatter) from the specified files (CSV) with the expected behaviour of the signal. The expected behaviour is
plotted as a line (a function representing perfect conditions), while the RSSI data from the files is plotted underneath, in a
scatter subplot. The distances are plotted in the x-axis, and the RSSI values are plotted in the y-axis. The distance of two lambda
and three lambda are also marked, and set as different colored areas. The RSSI values are plotted in dBm, and the distances are
plotted in meters.
Parameters:
- filenames: The files to read the RSSI data from. Each file contains data from a specific tag at a specific distance. [list]
- tag_name: The name of the tag. [str]
- frequency: The frequency of the signal, in MHz. [float]
- obstacle: The obstacle between the transmitter and the receiver. [str]
- power_tx: The power transmitted by the transmitter, in dBm. [float]
- gain_tx: The gain of the transmitter, in dBiL. [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- real_distances: The real distances between the transmitter and the receiver, in meters. [list]
- distances: The distances to plot the expected behaviour of the signal. [list]
- gain_antenna: The gain of the antenna, in dBiL. [float]
- gain_tag: The gain of the tag, in dBiL. [float]
- fit: Whether to plot the fitted expected behaviour. [bool]
Returns:
- None
"""
# Use LaTeX for plot typography
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plot_title = f"{tag_name} @ {frequency} MHz, {power_tx} dBm ({round(dBm_to_W(power_tx), 1)}W) - Obstacle: {obstacle}"
plot_x_axis_title = "Distance [m]"
plot_y_axis_title = "RSSI [dBm]"
# Get the expected behaviour of the signal
two_lambda, three_lambda, expected = expected_behaviour(dBm_to_dB(power_tx), gain_tx, gain_rx, distances, frequency)
expected_fit = expected_fitted(dBm_to_dB(power_tx), gain_antenna, gain_tag, distances, frequency)
mean_rssi = []
std_rssi = []
for i, filename in enumerate(filenames):
data = pd.read_csv(filename)
mean_rssi.append(data['peakRssi'].mean())
std_rssi.append(data['peakRssi'].std())
# Plot each point with its own label
for i in range(len(real_distances)):
if individual_markers:
plt.errorbar(real_distances[i], mean_rssi[i], yerr=std_rssi[i], fmt='o', label=f'{real_distances[i]:.3f} m')
else:
plt.errorbar(real_distances[i], mean_rssi[i], yerr=std_rssi[i], fmt='o', c='red', label='RSSI' if i == 0 else "")
if fit:
# Plot the expected behaviour of the signal
plt.plot(distances, expected, c='black', label='Expected Behaviour')
plt.plot(distances, expected_fit, c='red', label='Expected Behaviour (Fitted)')
# Format the gains to 2 decimal places
og_antenna_text = f'Antenna Gain: {gain_tx:.2f} dBiL'
og_tag_text = f'Tag Gain: {gain_rx:.2f} dBiL'
gain_antenna_text = f'Fitted Antenna Gain: {gain_antenna:.2f} dBiL'
gain_tag_text = f'Fitted Tag Gain: {gain_tag:.2f} dBiL'
# Define the box properties
box_props = dict(boxstyle='round,pad=0.3', facecolor='white', alpha=0.85, edgecolor='black')
# Place the text in the bottom left corner with a semi-transparent box
plt.text(0.10, 0.80, f'{og_antenna_text}\n{og_tag_text}\n{gain_antenna_text}\n{gain_tag_text}', transform=plt.gca().transAxes, fontsize=10, verticalalignment='bottom', bbox=box_props)
plt.axvline(x=two_lambda/8, color='black', linestyle='--', label=r'$\frac{\lambda}{4}$')
plt.axvline(x=two_lambda/4, color='gray', linestyle='--', label=r'$\frac{\lambda}{2}$')
plt.axvline(x=two_lambda/2, color='blue', linestyle='--', label=r'$\lambda$')
plt.axvline(x=two_lambda, color='red', linestyle='--', label=r'$2 \lambda$')
plt.axvline(x=three_lambda, color='green', linestyle='--', label=r'$3 \lambda$')
# Set the title and labels
plt.title(plot_title)
plt.xlabel(plot_x_axis_title)
plt.ylabel(plot_y_axis_title)
plt.legend()
plt.show()
def plot_rssi_distance_phase(filenames: list, tag_name: str, frequency: float, obstacle: str, power_tx: float, gain_tx: float, gain_rx: float,
real_distances: list, distances: list, gain_antenna: float, gain_tag: float, fit: bool = False, individual_markers: bool = True):
"""
Plot the RSSI data (scatter) from the specified files (CSV) with the expected behaviour of the signal. The expected behaviour is
plotted as a line (a function representing perfect conditions), while the RSSI data from the files is plotted underneath, in a
scatter subplot. The distances are plotted in the x-axis, and the RSSI values are plotted in the y-axis. The distance of two lambda
and three lambda are also marked, and set as different colored areas. The RSSI values are plotted in dBm, and the distances are
plotted in meters.
Parameters:
- filenames: The files to read the RSSI data from. Each file contains data from a specific tag at a specific distance. [list]
- tag_name: The name of the tag. [str]
- frequency: The frequency of the signal, in MHz. [float]
- obstacle: The obstacle between the transmitter and the receiver. [str]
- power_tx: The power transmitted by the transmitter, in dBm. [float]
- gain_tx: The gain of the transmitter, in dBiL. [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- real_distances: The real distances between the transmitter and the receiver, in meters. [list]
- distances: The distances to plot the expected behaviour of the signal. [list]
- gain_antenna: The gain of the antenna, in dBiL. [float]
- gain_tag: The gain of the tag, in dBiL. [float]
- fit: Whether to plot the fitted expected behaviour. [bool]
Returns:
- None
"""
# Use LaTeX for plot typography
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plot_title = f"{tag_name} @ {frequency} MHz, {power_tx} dBm ({round(dBm_to_W(power_tx), 1)}W) - Obstacle: {obstacle}"
plot_x_axis_title = "Distance [m]"
plot_y_axis_title = "RSSI [dBm]"
# Phase
plot_y_axis_title_phase = "Phase [degrees]"
# Get the expected behaviour of the signal
two_lambda, three_lambda, expected = expected_behaviour(dBm_to_dB(power_tx), gain_tx, gain_rx, distances, frequency)
expected_fit = expected_fitted(dBm_to_dB(power_tx), gain_antenna, gain_tag, distances, frequency)
mean_rssi = []
std_rssi = []
mean_phase = []
std_phase = []
for i, filename in enumerate(filenames):
data = pd.read_csv(filename)
mean_rssi.append(data['peakRssi'].mean())
std_rssi.append(data['peakRssi'].std())
mean_phase.append(data['phase'].mean())
std_phase.append(data['phase'].std())
fig, ax1 = plt.subplots()
# Plot RSSI
color = 'tab:red'
ax1.set_xlabel(plot_x_axis_title)
ax1.set_ylabel(plot_y_axis_title, color=color)
for i in range(len(real_distances)):
ax1.errorbar(real_distances[i], mean_rssi[i], yerr=std_rssi[i], fmt='o', color=color, label='RSSI' if i == 0 else "")
ax1.tick_params(axis='y', labelcolor=color)
# Create a second y-axis for phase
ax2 = ax1.twinx()
color = 'tab:blue'
ax2.set_ylabel(plot_y_axis_title_phase, color=color)
for i in range(len(real_distances)):
ax2.errorbar(real_distances[i], mean_phase[i], yerr=std_phase[i], fmt='o', color=color, label='Phase' if i == 0 else "")
ax2.tick_params(axis='y', labelcolor=color)
if fit:
# Plot the expected behaviour of the signal
plt.plot(distances, expected, c='black', label='Expected Behaviour')
plt.plot(distances, expected_fit, c='red', label='Expected Behaviour (Fitted)')
# Format the gains to 2 decimal places
og_antenna_text = f'Antenna Gain: {gain_tx:.2f} dBiL'
og_tag_text = f'Tag Gain: {gain_rx:.2f} dBiL'
gain_antenna_text = f'Fitted Antenna Gain: {gain_antenna:.2f} dBiL'
gain_tag_text = f'Fitted Tag Gain: {gain_tag:.2f} dBiL'
# Define the box properties
box_props = dict(boxstyle='round,pad=0.3', facecolor='white', alpha=0.85, edgecolor='black')
# Place the text in the bottom left corner with a semi-transparent box
plt.text(0.10, 0.80, f'{og_antenna_text}\n{og_tag_text}\n{gain_antenna_text}\n{gain_tag_text}', transform=plt.gca().transAxes, fontsize=10, verticalalignment='bottom', bbox=box_props)
plt.axvline(x=two_lambda/8, color='black', linestyle='--', label=r'$\frac{\lambda}{4}$')
plt.axvline(x=two_lambda/4, color='gray', linestyle='--', label=r'$\frac{\lambda}{2}$')
plt.axvline(x=two_lambda/2, color='blue', linestyle='--', label=r'$\lambda$')
plt.axvline(x=two_lambda, color='red', linestyle='--', label=r'$2 \lambda$')
plt.axvline(x=three_lambda, color='green', linestyle='--', label=r'$3 \lambda$')
# Set the title and labels
plt.suptitle(plot_title)
ax1.legend(loc='upper left')
ax2.legend(loc='upper right')
fig.tight_layout()
plt.show()
def plot_rssi_distance_indoor_vs_outdoor(filenames_outdoor: list, filenames_indoor: list, tag_name: str, frequency: float, obstacle: str,
power_tx: float, gain_tx: float, gain_rx: float, real_distances_outdoor: list,
real_distances_indoor: list, distances: list, gain_antenna_outdoor: float, gain_tag_outdoor: float,
gain_antenna_indoor: float, gain_tag_indoor: float, fit: bool = False):
"""
Plot the RSSI data (scatter) from the specified files (CSV) with the expected behaviour of the signal. The expected behaviour is
plotted as a line (a function representing perfect conditions), while the RSSI data from the files is plotted underneath, in a
scatter subplot. The distances are plotted in the x-axis, and the RSSI values are plotted in the y-axis. The distance of two lambda
and three lambda are also marked, and set as different colored areas. The RSSI values are plotted in dBm, and the distances are
plotted in meters.
Parameters:
- filenames_outdoor: The files to read the RSSI data from (outdoor). Each file contains data from a specific tag at a specific distance. [list]
- filenames_indoor: The files to read the RSSI data from (indoor). Each file contains data from a specific tag at a specific distance. [list]
- tag_name: The name of the tag. [str]
- frequency: The frequency of the signal, in MHz. [float]
- obstacle: The obstacle between the transmitter and the receiver. [str]
- power_tx: The power transmitted by the transmitter, in dBm. [float]
- gain_tx: The gain of the transmitter, in dBiL. [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- real_distances_outdoor: The real distances between the transmitter and the receiver (outdoor), in meters. [list]
- real_distances_indoor: The real distances between the transmitter and the receiver (indoor), in meters. [list]
- distances: The distances to plot the expected behaviour of the signal. [list]
- gain_antenna_outdoor: The gain of the antenna (outdoor), in dBiL. [float]
- gain_tag_outdoor: The gain of the tag (outdoor), in dBiL. [float]
- gain_antenna_indoor: The gain of the antenna (indoor), in dBiL. [float]
- gain_tag_indoor: The gain of the tag (indoor), in dBiL. [float]
- fit: Whether to plot the fitted expected behaviour. [bool]
Returns:
- None
"""
# Use LaTeX for plot typography
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plot_title = f"{tag_name} @ {frequency} MHz, {power_tx} dBm ({round(dBm_to_W(power_tx), 1)}W) - Indoor vs Outdoor"
plot_x_axis_title = "Distance [m]"
plot_y_axis_title = "RSSI [dBm]"
# Get the expected behaviour of the signal
two_lambda, three_lambda, expected = expected_behaviour(dBm_to_dB(power_tx), gain_tx, gain_rx, distances, frequency)
expected_fit_indoor = expected_fitted(dBm_to_dB(power_tx), gain_antenna_indoor, gain_tag_indoor, distances, frequency)
expected_fit_outdoor = expected_fitted(dBm_to_dB(power_tx), gain_antenna_outdoor, gain_tag_outdoor, distances, frequency)
# INDOOR
mean_rssi_indoor = []
std_rssi_indoor = []
for i, filename in enumerate(filenames_indoor):
data = pd.read_csv(filename)
mean_rssi_indoor.append(data['peakRssi'].mean())
std_rssi_indoor.append(data['peakRssi'].std())
# Plot each point with its own label
for i in range(len(real_distances_indoor)):
plt.errorbar(real_distances_indoor[i], mean_rssi_indoor[i], yerr=std_rssi_indoor[i], fmt='o', color='red', label='Indoor RSSI' if i == 0 else "")
# OUTDOOR
mean_rssi_outdoor = []
std_rssi_outdoor = []
for i, filename in enumerate(filenames_outdoor):
data = pd.read_csv(filename)
mean_rssi_outdoor.append(data['peakRssi'].mean())
std_rssi_outdoor.append(data['peakRssi'].std())
# Plot each point with its own label
for i in range(len(real_distances_outdoor)):
plt.errorbar(real_distances_outdoor[i], mean_rssi_outdoor[i], yerr=std_rssi_outdoor[i], fmt='o', color='blue', label='Outdoor RSSI' if i == 0 else "")
# Plot the expected behaviour of the signal
plt.plot(distances, expected, c='black', label='Expected Behaviour')
if fit:
plt.plot(distances, expected_fit_outdoor, c='blue', label='Expected Behaviour Outdoor (Fitted)')
plt.plot(distances, expected_fit_indoor, c='red', label='Expected Behaviour Indoor (Fitted)')
# Format the gains to 2 decimal places
indoor_gain_antenna_text = f'Indoor Gain Antenna: {gain_antenna_indoor:.2f} dBiL'
indoor_gain_tag_text = f'Indoor Gain Tag: {gain_tag_indoor:.2f} dBiL'
outdoor_gain_antenna_text = f'Outdoor Gain Antenna: {gain_antenna_outdoor:.2f} dBiL'
outdoor_gain_tag_text = f'Outdoor Gain Tag: {gain_tag_outdoor:.2f} dBiL'
# Define the box properties
box_props = dict(boxstyle='round,pad=0.3', facecolor='white', alpha=0.5, edgecolor='black')
# Place the text in the bottom left corner with a semi-transparent box
plt.text(0.02, 0.02, f'{indoor_gain_antenna_text}\n{indoor_gain_tag_text}\n{outdoor_gain_antenna_text}\n{outdoor_gain_tag_text}', transform=plt.gca().transAxes, fontsize=10, verticalalignment='bottom', bbox=box_props)
plt.axvline(x=two_lambda/8, color='black', linestyle='--', label=r'$\frac{\lambda}{4}$')
plt.axvline(x=two_lambda/4, color='gray', linestyle='--', label=r'$\frac{\lambda}{2}$')
plt.axvline(x=two_lambda/2, color='blue', linestyle='--', label=r'$\lambda$')
plt.axvline(x=two_lambda, color='red', linestyle='--', label=r'$2 \lambda$')
plt.axvline(x=three_lambda, color='green', linestyle='--', label=r'$3 \lambda$')
# Set the title and labels
plt.title(plot_title)
plt.xlabel(plot_x_axis_title)
plt.ylabel(plot_y_axis_title)
plt.legend()
plt.show()
def plot_rssi_distance_no_obstacle_vs_wood_vs_water(filenames_no_obstacle: list, filenames_wood: list, filenames_water: list, tag_name: str,
frequency: float, power_tx: float, gain_tx: float, gain_rx: float, real_distances: list,
distances: list, gain_antenna: float, gain_tag: float, fit: bool = False):
"""
Plot the RSSI data (scatter) from the specified files (CSV) with the expected behaviour of the signal. The expected behaviour is
plotted as a line (a function representing perfect conditions), while the RSSI data from the files is plotted underneath, in a
scatter subplot. The distances are plotted in the x-axis, and the RSSI values are plotted in the y-axis. The distance of two lambda
and three lambda are also marked, and set as different colored areas. The RSSI values are plotted in dBm, and the distances are
plotted in meters.
Parameters:
- filenames_no_obstacle: The files to read the RSSI data from (no obstacle). Each file contains data from a specific tag at a specific distance. [list]
- filenames_wood: The files to read the RSSI data from (wood). Each file contains data from a specific tag at a specific distance. [list]
- filenames_water: The files to read the RSSI data from (water). Each file contains data from a specific tag at a specific distance. [list]
- tag_name: The name of the tag. [str]
- frequency: The frequency of the signal, in MHz. [float]
- power_tx: The power transmitted by the transmitter, in dBm. [float]
- gain_tx: The gain of the transmitter, in dBiL. [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
Returns:
- None
"""
# Use LaTeX for plot typography
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plot_title = f"{tag_name} @ {frequency} MHz, {power_tx} dBm ({round(dBm_to_W(power_tx), 1)}W) - Obstacle Comparison"
plot_x_axis_title = "Distance [m]"
plot_y_axis_title = "RSSI [dBm]"
# Get the expected behaviour of the signal
two_lambda, three_lambda, expected = expected_behaviour(dBm_to_dB(power_tx), gain_tx, gain_rx, distances, frequency)
expected_fit = expected_fitted(dBm_to_dB(power_tx), gain_antenna, gain_tag, distances, frequency)
# NO OBSTACLE
mean_rssi_no_obstacle = []
std_rssi_no_obstacle = []
for i, filename in enumerate(filenames_no_obstacle):
data = pd.read_csv(filename)
mean_rssi_no_obstacle.append(data['peakRssi'].mean())
std_rssi_no_obstacle.append(data['peakRssi'].std())
# Plot each point with its own label
for i in range(len(real_distances)):
plt.errorbar(real_distances[i], mean_rssi_no_obstacle[i], yerr=std_rssi_no_obstacle[i], fmt='o', color='red', label='No Obstacle' if i == 0 else "")
plt.plot(real_distances, mean_rssi_no_obstacle, color='red')
# WOOD
mean_rssi_wood = []
std_rssi_wood = []
for i, filename in enumerate(filenames_wood):
data = pd.read_csv(filename)
mean_rssi_wood.append(data['peakRssi'].mean())
std_rssi_wood.append(data['peakRssi'].std())
# Plot each point with its own label
for i in range(len(real_distances)):
plt.errorbar(real_distances[i], mean_rssi_wood[i], yerr=std_rssi_wood[i], fmt='o', color='green', label='Wood Plank' if i == 0 else "")
plt.plot(real_distances, mean_rssi_wood, color='green')
# WATER
mean_rssi_water = []
std_rssi_water = []
for i, filename in enumerate(filenames_water):
data = pd.read_csv(filename)
mean_rssi_water.append(data['peakRssi'].mean())
std_rssi_water.append(data['peakRssi'].std())
# Plot each point with its own label
for i in range(len(real_distances)):
plt.errorbar(real_distances[i], mean_rssi_water[i], yerr=std_rssi_water[i], fmt='o', color='blue', label='Container w/ Water' if i == 0 else "")
plt.plot(real_distances, mean_rssi_water, color='blue')
if fit:
plt.plot(distances, expected, c='black', label='Expected Behaviour')
plt.plot(distances, expected_fit, c='red', label='Expected Behaviour (Fitted)')
# Format the gains to 2 decimal places
og_antenna_text = f'Antenna Gain: {gain_tx:.2f} dBiL'
og_tag_text = f'Tag Gain: {gain_rx:.2f} dBiL'
gain_antenna_text = f'Fitted Antenna Gain: {gain_antenna:.2f} dBiL'
gain_tag_text = f'Fitted Tag Gain: {gain_tag:.2f} dBiL'
# Define the box properties
box_props = dict(boxstyle='round,pad=0.3', facecolor='white', alpha=0.85, edgecolor='black')
# Place the text in the bottom left corner with a semi-transparent box
plt.text(0.10, 0.80, f'{og_antenna_text}\n{og_tag_text}\n{gain_antenna_text}\n{gain_tag_text}', transform=plt.gca().transAxes, fontsize=10, verticalalignment='bottom', bbox=box_props)
plt.axvline(x=two_lambda/8, color='black', linestyle='--', label=r'$\frac{\lambda}{4}$')
plt.axvline(x=two_lambda/4, color='gray', linestyle='--', label=r'$\frac{\lambda}{2}$')
plt.axvline(x=two_lambda/2, color='blue', linestyle='--', label=r'$\lambda$')
plt.axvline(x=two_lambda, color='red', linestyle='--', label=r'$2 \lambda$')
plt.axvline(x=three_lambda, color='green', linestyle='--', label=r'$3 \lambda$')
# Set the title and labels
plt.title(plot_title)
plt.xlabel(plot_x_axis_title)
plt.ylabel(plot_y_axis_title)
plt.legend()
plt.show()
def plot_rssi_distance_all_tags(filenames: list, tag_names: list, frequency: float, obstacle: str, power_tx: float, gain_tx: float, gain_rx: float,
real_distances: list, distances: list):
"""
Plot the RSSI data (scatter) from the specified files (CSV) with the expected behaviour of the signal. The expected behaviour is
plotted as a line (a function representing perfect conditions), while the RSSI data from the files is plotted underneath, in a
scatter subplot. The distances are plotted in the x-axis, and the RSSI values are plotted in the y-axis. The distance of two lambda
and three lambda are also marked, and set as different colored areas. The RSSI values are plotted in dBm, and the distances are plotted
in meters.
Parameters:
- filenames: List of lists with the files to read the RSSI data from. Each list item is a list of the files from a specific tag
at a specific range of distances, specified in real_distances. [list]
- tag_names: The names of the tags, in the same order as the list items in filenames [list]
- frequency: The frequency of the signal, in MHz. [float]
- obstacle: The obstacle between the transmitter and the receiver. [str]
- power_tx: The power transmitted by the transmitter, in dBm. [float]
- gain_tx: The gain of the transmitter, in dBiL. [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- real_distances: The real distances between the transmitter and the receiver, in meters. [list]
- distances: The distances to plot the expected behaviour of the signal. [list]
Returns:
- The RSSI data (scatter) from the specified files (CSV) with the expected behaviour of the signal. [None]
"""
# Use LaTeX for plot typography
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plot_title = f"{power_tx} dBm ({round(dBm_to_W(power_tx), 1)}W) @ {frequency} MHz - Obstacle: {obstacle}"
plot_x_axis_title = "Distance [m]"
plot_y_axis_title = "RSSI [dBm]"
# Get the expected behaviour of the signal
two_lambda, three_lambda, expected = expected_behaviour(dBm_to_dB(power_tx), gain_tx, gain_rx, distances, frequency)
# Dictionaries to store the mean & standard deviation of RSSI values for each tag at each distance
mean_rssi = {}
std_rssi = {}
for i, tag in enumerate(tag_names):
mean_rssi[tag] = []
std_rssi[tag] = []
for j, filename in enumerate(filenames[i]):
data = pd.read_csv(filename)
mean_rssi[tag].append(data['peakRssi'].mean())
std_rssi[tag].append(data['peakRssi'].std())
# Get a colormap
colors = plt.cm.get_cmap('tab10', len(tag_names))
# Plot the RSSI data for each tag with its label
for i, tag in enumerate(tag_names):
plt.errorbar(real_distances, mean_rssi[tag], yerr=std_rssi[tag], fmt='o', label=tag, color=colors(i))
# Plot the expected behaviour of the signal
plt.plot(distances, expected, c='black', label='Expected Behaviour')
# Plot the two lambda and three lambda distances
plt.axvline(x=two_lambda, color='red', linestyle='--', label=r'$2 \lambda$')
plt.axvline(x=three_lambda, color='green', linestyle='--', label=r'$3 \lambda$')
# Set the title and labels
plt.title(plot_title)
plt.xlabel(plot_x_axis_title)
plt.ylabel(plot_y_axis_title)
plt.legend()
plt.show()
def plot_rssi_distance_average(filenames: list, frequency: float, obstacle: str, power_tx: float, gain_tx: float, gain_rx: float,
real_distances: list, distances: list):
"""
Plot the RSSI data (scatter) from the specified files (CSV) with the expected behaviour of the signal. The expected behaviour is
plotted as a line (a function representing perfect conditions), while the RSSI data from the files is plotted underneath, in a
scatter subplot (average and std of all tags at a certain distance). The distances are plotted in the x-axis, and the RSSI values
are plotted in the y-axis. The distance of two lambda and three lambda are also marked, and set as different colored areas. The RSSI
values are plotted in dBm, and the distances are plotted in meters.
Parameters:
- filenames: List of lists with the files to read the RSSI data from. Each list item is a list of the files from a specific tag
at a specific range of distances, specified in real_distances. [list]
- frequency: The frequency of the signal, in MHz. [float]
- obstacle: The obstacle between the transmitter and the receiver. [str]
- power_tx: The power transmitted by the transmitter, in dBm. [float]
- gain_tx: The gain of the transmitter, in dBiL. [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- real_distances: The real distances between the transmitter and the receiver, in meters. [list]
- distances: The distances to plot the expected behaviour of the signal. [list]
Returns:
- The RSSI data (scatter) from the specified files (CSV) with the expected behaviour of the signal. [None]
"""
# Use LaTeX for plot typography
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plot_title = f"{power_tx} dBm ({round(dBm_to_W(power_tx), 1)}W) @ {frequency} MHz - Obstacle: {obstacle}"
plot_x_axis_title = "Distance [m]"
plot_y_axis_title = "RSSI [dBm]"
# Get the expected behaviour of the signal
two_lambda, three_lambda, expected = expected_behaviour(dBm_to_dB(power_tx), gain_tx, gain_rx, distances, frequency)
# Lists to store the mean & standard deviation of RSSI values at each distance
mean_rssi = []
std_rssi = []
# Aggregate RSSI values across all tags for each distance
for i in range(len(real_distances)):
rssi_values = []
for tag_files in filenames:
data = pd.read_csv(tag_files[i])
rssi_values.extend(data['peakRssi'].values)
mean_rssi.append(np.mean(rssi_values))
std_rssi.append(np.std(rssi_values))
# Plot the mean RSSI values with their standard deviation
plt.errorbar(real_distances, mean_rssi, yerr=std_rssi, fmt='o', label='Mean RSSI')
# Plot the expected behaviour of the signal
plt.plot(distances, expected, c='black', label='Expected Behaviour')
# Plot the two lambda and three lambda distances
plt.axvline(x=two_lambda, color='red', linestyle='--', label=r'$2 \lambda$')
plt.axvline(x=three_lambda, color='green', linestyle='--', label=r'$3 \lambda$')
# Set the title and labels
plt.title(plot_title)
plt.xlabel(plot_x_axis_title)
plt.ylabel(plot_y_axis_title)
plt.legend()
plt.show()
def plot_rssi_distance_average_indoor_outdoor(filenames_outdoor: list, filenames_indoor: list,
frequency: float, obstacle: str, power_tx: float, gain_tx: float, gain_rx: float,
real_distances_outdoor: list, real_distances_indoor: list, distances: list):
"""
Plot the RSSI data (scatter) from the specified files (CSV) with the expected behaviour of the signal. The expected behaviour is
plotted as a line (a function representing perfect conditions), while the RSSI data from the files is plotted underneath, in a
scatter subplot (average and std of all tags at a certain distance). The distances are plotted in the x-axis, and the RSSI values
are plotted in the y-axis. The distance of two lambda and three lambda are also marked, and set as different colored areas. The RSSI
values are plotted in dBm, and the distances are plotted in meters.
Parameters:
- filenames_outdoor: List of lists with the files to read the RSSI data from (outdoor). Each list item is a list of the files from a specific tag
at a specific range of distances, specified in real_distances_outdoor. [list]
- filenames_indoor: List of lists with the files to read the RSSI data from (indoor). Each list item is a list of the files from a specific tag
at a specific range of distances, specified in real_distances_indoor. [list]
- frequency: The frequency of the signal, in MHz. [float]
- obstacle: The obstacle between the transmitter and the receiver. [str]
- power_tx: The power transmitted by the transmitter, in dBm. [float]
- gain_tx: The gain of the transmitter, in dBiL. [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- real_distances_outdoor: The real distances between the transmitter and the receiver (outdoor), in meters. [list]
- real_distances_indoor: The real distances between the transmitter and the receiver (indoor), in meters. [list]
- distances: The distances to plot the expected behaviour of the signal. [list]
Returns:
- The RSSI data (scatter) from the specified files (CSV) with the expected behaviour of the signal. [None]
"""
# Use LaTeX for plot typography
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plot_title = f"{power_tx} dBm ({round(dBm_to_W(power_tx), 1)}W) @ {frequency} MHz - - Indoor vs Outdoor"
plot_x_axis_title = "Distance [m]"
plot_y_axis_title = "RSSI [dBm]"
# Get the expected behaviour of the signal
two_lambda, three_lambda, expected = expected_behaviour(dBm_to_dB(power_tx), gain_tx, gain_rx, distances, frequency)
# INDOOR
# Lists to store the mean & standard deviation of RSSI values at each distance
mean_rssi_indoor = []
std_rssi_indoor = []
# Aggregate RSSI values across all tags for each distance
for i in range(len(real_distances_indoor)):
rssi_values = []
for tag_files in filenames_indoor:
data = pd.read_csv(tag_files[i])
rssi_values.extend(data['peakRssi'].values)
mean_rssi_indoor.append(np.mean(rssi_values))
std_rssi_indoor.append(np.std(rssi_values))
# Plot the mean RSSI values with their standard deviation
plt.errorbar(real_distances_indoor, mean_rssi_indoor, yerr=std_rssi_indoor, fmt='o', label='Mean RSSI (Indoor)')
# OUTDOOR
# Lists to store the mean & standard deviation of RSSI values at each distance
mean_rssi_outdoor = []
std_rssi_outdoor = []
# Aggregate RSSI values across all tags for each distance
for i in range(len(real_distances_outdoor)):
rssi_values = []
for tag_files in filenames_outdoor:
data = pd.read_csv(tag_files[i])
rssi_values.extend(data['peakRssi'].values)
mean_rssi_outdoor.append(np.mean(rssi_values))
std_rssi_outdoor.append(np.std(rssi_values))
# Plot the mean RSSI values with their standard deviation
plt.errorbar(real_distances_outdoor, mean_rssi_outdoor, yerr=std_rssi_outdoor, fmt='o', label='Mean RSSI (Outdoor)')
# Plot the expected behaviour of the signal
plt.plot(distances, expected, c='black', label='Expected Behaviour')
# Plot the two lambda and three lambda distances
plt.axvline(x=two_lambda, color='red', linestyle='--', label=r'$2 \lambda$')
plt.axvline(x=three_lambda, color='green', linestyle='--', label=r'$3 \lambda$')
# Set the title and labels
plt.title(plot_title)
plt.xlabel(plot_x_axis_title)
plt.ylabel(plot_y_axis_title)
plt.legend()
plt.show()
def create_combined_plot(filenames_outdoor, filenames_indoor, tag_name, frequency, obstacle, power_tx, gain_tx, gain_rx,
real_distances_outdoor, real_distances_indoor, distances, gain_antenna_outdoor, tag00_gain_outdoor,
gain_antenna_indoor, tag00_gain_indoor):
"""
Create a combined plot with four subplots.
Parameters:
- All parameters required by the plotting functions.
Returns:
- None
"""
# Use LaTeX for plot typography
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
fig, axs = plt.subplots(2, 2, figsize=(15, 10))
# Subplot 1
plt.sca(axs[0, 0])
plot_rssi_distance(filenames_outdoor, tag_name, frequency, obstacle, power_tx, gain_tx, gain_rx,
real_distances_outdoor, distances, gain_antenna_outdoor, tag00_gain_outdoor)
# Subplot 2
plt.sca(axs[0, 1])
plot_rssi_distance(filenames_outdoor, tag_name, frequency, obstacle, power_tx, gain_tx, gain_rx,
real_distances_outdoor, distances, gain_antenna_outdoor, tag00_gain_outdoor, True)
# Subplot 3
plt.sca(axs[1, 0])
plot_rssi_distance_indoor_vs_outdoor(filenames_outdoor, filenames_indoor, tag_name, frequency, obstacle, power_tx, gain_tx, gain_rx,
real_distances_outdoor, real_distances_indoor, distances, gain_antenna_outdoor, tag00_gain_outdoor,
gain_antenna_indoor, tag00_gain_indoor)
# Subplot 4
plt.sca(axs[1, 1])
plot_rssi_distance_indoor_vs_outdoor(filenames_outdoor, filenames_indoor, tag_name, frequency, obstacle, power_tx, gain_tx, gain_rx,
real_distances_outdoor, real_distances_indoor, distances, gain_antenna_outdoor, tag00_gain_outdoor,
gain_antenna_indoor, tag00_gain_indoor, True)
plt.tight_layout()
plt.subplots_adjust(top=0.9, bottom=0.1, left=0.1, right=0.9, hspace=0.4, wspace=0.4)
plt.show()
def create_combined_plot_obstacles(no_obstacle, wood, water, tag_name, frequency, transmission_power, antenna_gain, tag_gain,
real_distances, expected_distances, antenna_gain_fitted, tag_gain_fitted, fit):
"""
Create a combined plot with four subplots.
Parameters:
- All parameters required by the plotting functions.
Returns:
- None
"""
# Use LaTeX for plot typography
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
fig, axs = plt.subplots(2, 2, figsize=(15, 10))
# Subplot 1 - No Obstacle
plt.sca(axs[0, 0])
plot_rssi_distance(no_obstacle, tag_name, frequency, "None", transmission_power, antenna_gain,
tag_gain, real_distances, expected_distances, antenna_gain_fitted, tag_gain_fitted, fit, False)
# Subplot 2 - Wood
plt.sca(axs[0, 1])
plot_rssi_distance(wood, tag_name, frequency, "Wood", transmission_power, antenna_gain,
tag_gain, real_distances, expected_distances, antenna_gain_fitted, tag_gain_fitted, fit, False)
# Subplot 3 - Container with Water
plt.sca(axs[1, 0])
plot_rssi_distance(water, tag_name, frequency, "Container w/ Water", transmission_power, antenna_gain,
tag_gain, real_distances, expected_distances, antenna_gain_fitted, tag_gain_fitted, fit, False)
# Subplot 4 - All Obstacles
plt.sca(axs[1, 1])
plot_rssi_distance_no_obstacle_vs_wood_vs_water(no_obstacle, wood, water, tag_name, frequency,
transmission_power, antenna_gain, tag_gain, real_distances, expected_distances, antenna_gain_fitted, tag_gain_fitted, fit)
plt.tight_layout()
plt.subplots_adjust(top=0.9, bottom=0.1, left=0.1, right=0.9, hspace=0.4, wspace=0.4)
plt.show()
# =================================================================================================================================== #
# =================================================================================================================================== #
# ---------------------------------------------------- 3D Plots - RSSI & Phase ------------------------------------------------------ #
def basic_3D_plot2(filenames:list, distances:list, tag_name:str, frequency:float, obstacle:str, power_tx:float, gain_tx:float, gain_rx:float):
# Use LaTeX for plot typography
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plot_title = f"{tag_name} @ {frequency} MHz, {power_tx} dBm ({round(dBm_to_W(power_tx), 1)}W) - Obstacle: {obstacle}"
plot_x_axis_title = "Distance [m]"
plot_z_axis_title = "RSSI [dBm]"
plot_y_axis_title = "Phase [degrees]"
# Obtain the RSSI and Phase data
all_rssi = []
all_phase = []
all_distances = []
for i, filename in enumerate(filenames):
data = pd.read_csv(filename)
all_rssi.extend(data['peakRssi'].values)
all_phase.extend(data['phase'].values)
all_distances.extend([distances[i]] * len(data))
# Create the 3D plot
fig = plt.figure(figsize=(14, 14))
# First subplot
ax1 = fig.add_subplot(221, projection='3d')
scatter1 = ax1.scatter(all_distances, all_phase, all_rssi, c=all_distances, cmap='viridis', s=100, alpha=0.6)
ax1.set_xlabel(plot_x_axis_title)
ax1.set_ylabel(plot_y_axis_title)
ax1.set_zlabel(plot_z_axis_title)
ax1.set_title('View Angle 1')
ax1.view_init(elev=20., azim=30)
# Second subplot
ax2 = fig.add_subplot(222, projection='3d')
scatter2 = ax2.scatter(all_distances, all_phase, all_rssi, c=all_distances, cmap='viridis', s=100, alpha=0.6)
ax2.set_xlabel(plot_x_axis_title)
ax2.set_ylabel(plot_y_axis_title)
ax2.set_zlabel(plot_z_axis_title)
ax2.set_title('View Angle 2')
ax2.view_init(elev=30., azim=60)
# Third subplot
ax3 = fig.add_subplot(223, projection='3d')
scatter3 = ax3.scatter(all_distances, all_phase, all_rssi, c=all_distances, cmap='viridis', s=100, alpha=0.6)
ax3.set_xlabel(plot_x_axis_title)
ax3.set_ylabel(plot_y_axis_title)
ax3.set_zlabel(plot_z_axis_title)
ax3.set_title('View Angle 3')
ax3.view_init(elev=40., azim=90)
# Fourth subplot
ax4 = fig.add_subplot(224, projection='3d')
scatter4 = ax4.scatter(all_distances, all_phase, all_rssi, c=all_distances, cmap='viridis', s=100, alpha=0.6)
ax4.set_xlabel(plot_x_axis_title)
ax4.set_ylabel(plot_y_axis_title)
ax4.set_zlabel(plot_z_axis_title)
ax4.set_title('View Angle 4')
ax4.view_init(elev=50., azim=120)
fig.suptitle(plot_title)
fig.colorbar(scatter1, ax=[ax1, ax2, ax3, ax4], label='Distance [m]')
plt.show()
def plot_rssi_distance_all_points(filenames: list, tag_name: str, frequency: float, obstacle: str, power_tx: float, gain_tx: float, gain_rx: float,
real_distances: list, distances: list, gain_antenna: float, gain_tag: float, fit: bool = False, individual_markers: bool = True):
"""
Plot the RSSI data (scatter) from the specified files (CSV) with the expected behaviour of the signal. The expected behaviour is
plotted as a line (a function representing perfect conditions), while the RSSI data from the files is plotted underneath, in a
scatter subplot. The distances are plotted in the x-axis, and the RSSI values are plotted in the y-axis. The distance of two lambda
and three lambda are also marked, and set as different colored areas. The RSSI values are plotted in dBm, and the distances are
plotted in meters.
Parameters:
- filenames: The files to read the RSSI data from. Each file contains data from a specific tag at a specific distance. [list]
- tag_name: The name of the tag. [str]
- frequency: The frequency of the signal, in MHz. [float]
- obstacle: The obstacle between the transmitter and the receiver. [str]
- power_tx: The power transmitted by the transmitter, in dBm. [float]
- gain_tx: The gain of the transmitter, in dBiL. [float]
- gain_rx: The gain of the receiver, in dBiL. [float]
- real_distances: The real distances between the transmitter and the receiver, in meters. [list]
- distances: The distances to plot the expected behaviour of the signal. [list]
- gain_antenna: The gain of the antenna, in dBiL. [float]
- gain_tag: The gain of the tag, in dBiL. [float]
- fit: Whether to plot the fitted expected behaviour. [bool]
Returns:
- None
"""
# Use LaTeX for plot typography
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plot_title = f"{tag_name} @ {frequency} MHz, {power_tx} dBm ({round(dBm_to_W(power_tx), 1)}W) - Obstacle: {obstacle}"
plot_x_axis_title = "Distance [m]"
plot_y_axis_title = "RSSI [dBm]"
# Get the expected behaviour of the signal
two_lambda, three_lambda, expected = expected_behaviour(dBm_to_dB(power_tx), gain_tx, gain_rx, distances, frequency)
expected_fit = expected_fitted(dBm_to_dB(power_tx), gain_antenna, gain_tag, distances, frequency)
all_rssi = []
all_distances = []
for i, filename in enumerate(filenames):
data = pd.read_csv(filename)
all_rssi.extend(data['peakRssi'].values)
all_distances.extend([real_distances[i]] * len(data))
# Plot each point
plt.scatter(all_distances, all_rssi, c='red', label='RSSI')
if fit:
# Plot the expected behaviour of the signal
plt.plot(distances, expected, c='black', label='Expected Behaviour')
plt.plot(distances, expected_fit, c='red', label='Expected Behaviour (Fitted)')
# Format the gains to 2 decimal places
og_antenna_text = f'Antenna Gain: {gain_tx:.2f} dBiL'
og_tag_text = f'Tag Gain: {gain_rx:.2f} dBiL'
gain_antenna_text = f'Fitted Antenna Gain: {gain_antenna:.2f} dBiL'
gain_tag_text = f'Fitted Tag Gain: {gain_tag:.2f} dBiL'
# Define the box properties
box_props = dict(boxstyle='round,pad=0.3', facecolor='white', alpha=0.85, edgecolor='black')
# Place the text in the bottom left corner with a semi-transparent box
plt.text(0.10, 0.80, f'{og_antenna_text}\n{og_tag_text}\n{gain_antenna_text}\n{gain_tag_text}', transform=plt.gca().transAxes, fontsize=10, verticalalignment='bottom', bbox=box_props)
plt.axvline(x=two_lambda/8, color='black', linestyle='--', label=r'$\frac{\lambda}{4}$')
plt.axvline(x=two_lambda/4, color='gray', linestyle='--', label=r'$\frac{\lambda}{2}$')
plt.axvline(x=two_lambda/2, color='blue', linestyle='--', label=r'$\lambda$')
plt.axvline(x=two_lambda, color='red', linestyle='--', label=r'$2 \lambda$')
plt.axvline(x=three_lambda, color='green', linestyle='--', label=r'$3 \lambda$')
# Set the title and labels
plt.title(plot_title)
plt.xlabel(plot_x_axis_title)
plt.ylabel(plot_y_axis_title)
plt.legend()