-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter.py
More file actions
39 lines (34 loc) · 1.37 KB
/
plotter.py
File metadata and controls
39 lines (34 loc) · 1.37 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
#Plotter to plot data in F(t) -> time domain
# F(x) -> frequency domain( Fourier )
from constants import F_SAMPLING, BITRATE, N_PRINTBITS, N, F_CARRIER, DEVIATION
import numpy as np
import pylab as pl
def plot(signal,m):
#view the data in time and frequency domain
#calculate the frequency domain for viewing purposes
N_FFT = float(len(signal))
f = np.arange(0,F_SAMPLING/2,F_SAMPLING/N_FFT)
w = np.hanning(len(signal))
y_f = np.fft.fft(np.multiply(signal,w))
y_f = 10*np.log10(np.abs(y_f[0:int(N_FFT/2)]/N_FFT))
t = np.arange(0,float(N)/float(BITRATE),1/float(F_SAMPLING), dtype=np.float)
pl.subplot(3,1,1)
pl.plot(t[0:F_SAMPLING*N_PRINTBITS/BITRATE],m[0:F_SAMPLING*N_PRINTBITS/BITRATE])
pl.xlabel('Time (s)')
pl.ylabel('Frequency (Hz)')
pl.title('Original VCO output versus time')
pl.grid(True)
pl.subplot(3,1,2)
pl.plot(t[0:F_SAMPLING*N_PRINTBITS/BITRATE],signal[0:F_SAMPLING*N_PRINTBITS/BITRATE])
pl.xlabel('Time (s)')
pl.ylabel('Amplitude (V)')
pl.title('Amplitude of carrier versus time')
pl.grid(True)
pl.subplot(3,1,3)
pl.plot(f[0:int((F_CARRIER+DEVIATION*2)*N_FFT/F_SAMPLING)],y_f[0:int((F_CARRIER+DEVIATION*2)*N_FFT/F_SAMPLING)])
pl.xlabel('Frequency (Hz)')
pl.ylabel('Amplitude (dB)')
pl.title('Spectrum')
pl.grid(True)
pl.tight_layout()
pl.show()