Beispiel #1
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()
Beispiel #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)')