forked from tyagi-g/EMI-Sense_USRP-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plotting_Script_USRP.py
93 lines (62 loc) · 2.18 KB
/
Plotting_Script_USRP.py
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
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import pandas as pd
import numpy as np
import matplotlib
print matplotlib.get_backend()
matplotlib.use('qt4agg')
print matplotlib.get_backend()
import matplotlib.pyplot as plt
# <codecell>
########################################################
#Plot appliance traces against background noise traces
########################################################
##GLOBALS
#Path to FFT_averaged data stored as CSVs
dirpath='C:\Users\GEETALI\Desktop\\'
#Location of Book.csv containing metadata of traces
bookpath='C:\Users\GEETALI\Desktop\\Book1.csv'
#Index of first trace to be plotted in Book.csv
x=8
#Index of second trace tobe plotted in Book.csv
y=9
x=x-2
y=y-2
# <codecell>
#Read Book.csv data
df = pd.read_csv(bookpath)
#Stores appliances' names in names array
names=df['Appliances'].tolist()
#Stores traces' names (e.g. Trace_xxxx) in names array
traces=df['Traces'].tolist()
# <codecell>
path1 = dirpath+traces[x]+'_FFT_Averaged'
path2 = dirpath+traces[y]+'_FFT_Averaged'
#Read data from both FFT_Averaged CSVs to dataframes DF1 and DF2
DF1 = pd.read_csv(path1+'.csv',header=None, names = ['Frequency','Data'])
DF2 = pd.read_csv(path2+'.csv',header=None, names = ['Frequency','Data'])
# <codecell>
#Print trace numbers and appliance names of traces to be plotted
print traces[x],traces[y]
print names[x],names[y]
# <codecell>
ax = plt.gca();
ax.grid(True); #Create grid in plot
plt.plot(DF1['Frequency'],DF1['Data'],'b') #Plot first trace in blue
plt.plot(DF2['Frequency'],DF2['Data'],'r') #Plot second trace in red
plt.locator_params(axis = 'x', nbins = 10)
plt.xlabel("Frequency ( in Khz )"); #Label x_axis
plt.ylabel("Amplitude ( in dBm )"); #Label y_axis
plt.ylim((-150, -10)) #Set x_axis limits
plt.xlim((10,1000)) #Set y_axis limits
plt.legend([names[x],names[y]]); #Generate legend for plots
plt.xticks(rotation=70) #Rotate x_axis values by 70 degrees
mng = plt.get_current_fig_manager()
mng.window.showMaximized() #Maximize plot window
#Save plot to a Plots directory within current directory
plt.savefig(dirpath+"Plots\\"+str(names[y])+"_"+str(names[x])+"_USRP.png");
#Display plot
plt.show();
# <codecell>
# <codecell>