In [1]:
 

$$\require{color} \require{cancel} \def\tf#1{{\mathrm{FT}\left\{ #1 \right\}}} \def\flecheTF{\rightleftharpoons } \def\TFI#1#2#3{{\displaystyle{\int_{-\infty}^{+\infty} #1 ~e^{j2\pi #2 #3} ~\dr{#2}}}} \def\TF#1#2#3{{\displaystyle{\int_{-\infty}^{+\infty} #1 ~e^{-j2\pi #3 #2} ~\dr{#2}}}} \def\sha{ш} \def\dr#1{\mathrm{d}#1} \def\egalpardef{\mathop{=}\limits^\triangle} \def\sinc#1{{\mathrm{sinc}\left( #1 \right)}} \def\rect{\mathrm{rect}} \definecolor{lightred}{rgb}{1,0.1,0} \def\myblueeqbox#1{{\fcolorbox{blue}{lightblue}{$ extcolor{blue}{ #1}$}}} \def\myeqbox#1#2{{\fcolorbox{#1}{light#1}{$ extcolor{#1}{ #2}$}}} \def\eqbox#1#2#3#4{{\fcolorbox{#1}{#2}{$\textcolor{#3}{ #4}$}}} % border|background|text \def\eqboxa#1{{\boxed{#1}}} \def\eqboxb#1{{\eqbox{green}{white}{green}{#1}}} \def\eqboxc#1{{\eqbox{blue}{white}{blue}{#1}}} \def\eqboxd#1{{\eqbox{blue}{lightblue}{blue}{#1}}} \def\E#1{\mathbb{E}\left[#1\right]} \def\ta#1{\left<#1\right>} \def\egalparerg{{\mathop{=}\limits_\mathrm{erg}}} \def\expo#1{\exp\left(#1\right)} \def\d#1{\mathrm{d}#1} \def\wb{\mathbf{w}} \def\sb{\mathbf{s}} \def\xb{\mathbf{x}} \def\Rb{\mathbf{R}} \def\rb{\mathbf{r}} \def\mystar{{*}} \def\ub{\mathbf{u}} \def\wbopt{\mathop{\mathbf{w}}\limits^\triangle} \def\deriv#1#2{\frac{\mathrm{d}#1}{\mathrm{d}#2}} \def\Ub{\mathbf{U}} \def\db{\mathbf{d}} \def\eb{\mathbf{e}} \def\vb{\mathbf{v}} \def\Ib{\mathbf{I}} \def\Vb{\mathbf{V}} \def\Lambdab{\mathbf{\Lambda}} \def\Ab{\mathbf{A}} \def\Bb{\mathbf{B}} \def\Cb{\mathbf{C}} \def\Db{\mathbf{D}} \def\Kb{\mathbf{K}} \def\sinc#1{\mathrm{sinc\left(#1\right)}} $$


A basic introduction to signals and systems

Effects of delays and scaling on signals

In this simple exercise, we recall the effect of delays and scaling on signals. It is important for students to experiments with that to ensure that they master these simple transformations.

Study the code below and experiment with the parameters

In [2]:
# Define a simple function
def f(t):
    return np.exp(-0.25*t) if t>0 else 0


T= np.linspace(-10,20,200)
L=len(T)
x=np.zeros(L)  # reserve some space for x

t0=0; a=1 # initial values

# Compute x as f(a*t+t0) 
k=0
for t in T:
    x[k]=f(a*t+t0)
    k=k+1

# Plotting the signal    
plt.plot(T,x)
plt.xlabel("Time")
plt.ylabel("Amplitude")
plt.grid(b=True)


# Experiment with several values of a and t0:
# a=1 t0=0
# a=1 t0=+5  (advance)
# a=1 t0=-5  (delay) 
# a=-1 t0=0  (time reverse) 
# a=-1 t0=5  (time reverse + advance) 
# a=-1 t0=-5 (...) 

This to show that you do automatically several tests and plot the results all together.

In [3]:
def compute_x(a,t0):
    k=0
    for t in T:
        x[k]=f(a*t+t0)
        k=k+1
    return x    

list_tests=[(1,0),(1,5), (1,-5)]#,(-1,0),(-1,3), (-1,-3) ]
for (a,t0) in list_tests:
    x=compute_x(a,t0)
    plt.plot(T,x,label="a={},t0={}".format(a,t0))

plt.xlabel("Time")
plt.ylabel("Amplitude")
plt.grid(b=True)
_=plt.legend()

And finally an interactive version

In [4]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (8,4)

def f(t):
    out=np.zeros(len(t))
    tpos=np.where(t>0)             
    out[tpos]=np.exp(-0.25*t[tpos])
    return out

t= np.linspace(-10,20,200)
L=len(t)
x=np.zeros(L)

def compute_xx(t0,a):
        x=f(a*t+t0)
        plt.plot(t,x)
        plt.axis([-10, 20, 0, 1])

s_t0=widgets.FloatSlider(min=-20,max=20,step=1)
s_a=widgets.FloatSlider(min=0.1,max=5,step=0.1,value=2)
_=interact(compute_xx,t0=s_t0,a=s_a)