Esempio 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)
Esempio n. 2
0
import numpy as np
import matplotlib.pyplot as plt
import commlib as cl

T = 4;
Tmax = 30.0
N = 1024
Fmax = 20.0/T

t = cl.time_axis(-Tmax, +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)

f = cl.frequency_axis(t)
X = cl.spectrum(t,x)
Y = cl.spectrum(t,y)

plt.close('all')
plt.figure(1)
plt.title('Fmax * T =' + str(Fmax*T))
plt.xlabel('f [kHz]')
plt.ylabel('Spectrum')
plt.plot(t, np.abs(X), '--', label='|X(f)|')
plt.plot(t, np.abs(Y), label='|Y(f)|')
plt.xlim([-10, 10])
plt.legend()
import commlib as cl
import matplotlib.pyplot as plt
import numpy as np

f0 = 50
T = 1 / f0
Tmin = -T / 2
Tmax = +T / 2
A = 1

# number of points considered in each simulation
Ns = np.arange(10, 1000, 10)
Ps = np.zeros(Ns.size)

for i, N in enumerate(Ns):
    t = cl.time_axis(Tmin, Tmax, N)
    x = cl.cos_signal(A, f0, t)
    Ps[i] = cl.average_power(t, x)
    print('Power computed using trapezium rule using ', N, ' points is : ',
          Ps[i])

plt.close('all')
plt.plot(Ns, Ps)
plt.xlabel('N')
plt.ylabel('P')
Esempio n. 4
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)
Esempio n. 5
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)')
Esempio n. 6
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)