Exemplo n.º 1
0
import numpy as np
import matplotlib.pyplot as plt
import commlib as cl

T = 4
Tmax = 30.0
N = 1024
Fmax = 5.0 / T

t = cl.time_axis(Tmax, N)  # time axis
x = cl.square(t, T)  # input signal

Hc = lambda f: cl.square_filter(f, Fmax)  # filter callable

y = cl.system_action(t, x, Hc)

plt.close('all')
plt.figure(1)
plt.title('Fmax * T =' + str(Fmax * T))
plt.xlabel('t [ms]')
plt.ylabel('Signal')
plt.plot(t, np.real(x), label='x(t)')
plt.plot(t, np.real(y), label='y(t)')
plt.legend()
plt.xlim(-6, 6)
Exemplo n.º 2
0
import matplotlib.pyplot as plt
import numpy as np
from commlib import time_axis, frequency_axis, square, spectrum

# time axis
T = 4
Tmax = 30.0
N = 1024

t = time_axis(Tmax, N)
f = frequency_axis(t)
x = square(t, T)
X = spectrum(t, x)

# Analytical expression for the spectrum
X2 = T * np.sinc(f * T)

plt.close('all')

# Plot results
plt.figure(1)
plt.xlabel('t [msec]')
plt.ylabel('x(t)')
plt.plot(t, x)
plt.figure(2)

plt.plot(f, X2, f, X, 'o')
plt.xlim([-0.5, 0.5])
plt.legend(['analytical', 'numerical'])
plt.xlabel('f [kHz]')
plt.ylabel('X(f)')
Exemplo n.º 3
0
import commlib as cl
import numpy as np

N = 1024
TS = 1e-9
T = 20 * TS
sa2 = 1.0

t = cl.time_axis(T, N)
p = cl.square(t, TS)
f = cl.frequency_axis(t)
P = cl.spectrum(t, p)

SX = sa2 / TS * np.abs(P)**2.0

cl.plot_signal(f / 1e9, SX, close_all=True, xlabel='f [GHz]', ylabel='SX')

cl.plot_signal(f * TS,
               SX / np.max(SX),
               xlabel='f * TS',
               ylabel='SX [normalized]',
               xlim=[-1, 1],
               show_grid=True)

SX1 = cl.window(f, SX, -1 / TS, +1 / TS)
total = np.trapz(SX, f)
total1 = np.trapz(SX1, f)
print('power fraction :', total1 / total)
Exemplo n.º 4
0
import commlib as cl
import matplotlib.pyplot as plt

T = 10
T1 = 1
N = 1000

t = cl.time_axis(-T, T, N)
x = cl.square(t, T1)
f = cl.frequency_axis(t)
X = cl.spectrum(t, x)

plt.close('all')
cl.plot_signal(t, x, xlabel='t', ylabel='x', figure_no=1)

cl.plot_signal(f, X, xlabel='f', ylabel='X', figure_no=2)

Et = cl.energy(t, x)
Ef = cl.energy(f, X)

print('Energy in the time domain :', Et)
print('Energy in the frequency domain :', Ef)