Define rect(t) function¶

Define the rect(t) function with a value of 1 when -0.5 < t < 0.5; and a value of 0 everywhere else.

\begin{equation} \Large rect(t) = \begin{cases} 0 & \mbox{if } 0.5 \le t \\ 1 & \mbox{if } -0.5 \le t \le 0.5 \\ 0 & \mbox{if } 0.5 \le t \end{cases} \normalsize \end{equation}

Plot rect(t)¶

Show Python Code
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

import numpy as np
import matplotlib.pyplot as plt

import seaborn as sns

plt.rcdefaults() 
plt.xkcd()

fig = plt.figure(figsize=(6,4))  # sets size and makes it square
ax = plt.axes() 

# Reset default params
#sns.set()

# Set context to paper | talk | notebook | poster
# sns.set_context("poster")

#create rect(t)

def rect(time):
    y = np.zeros(len(time))
    for index in range(len(time)):
        if (-0.5<= time[index] <= 0.5):
            y[index] = 1
        else:
            y[index] = 0
    return(y)


start = -5
stop = 25
points = 201          # odd is easier

t = np.linspace(start, stop, points) 
y = rect(t)

# Major ticks every 5, minor ticks every 1
major_ticks = np.arange(start, stop+5, 5)
minor_ticks = np.arange(start, stop+1, 1)

ax.set_xticks(major_ticks)
ax.set_xticks(minor_ticks, minor=True)

#plt.minorticks_on()

plt.grid(which = 'major', color='g', linestyle='-', linewidth=0.2)
plt.grid(which = 'minor', visible = 'true', color='gray', linestyle='-', linewidth=0.1)

plt.plot(t, y)
plt.title("rect(t)")
plt.xlabel("t (time)")
plt.ylabel("magnitude")
plt.show()

Calculate the Fourier Transform¶

Now use WolframAlpha to check the Fourier Transform:

FourierTransform( {rect(t) }, t, w, FourierParameters -> {1, -1} )

Response is: (I modified this by hand, and created a MathJax representation)

\begin{equation*} \Large \text{rect}(t) \xrightarrow{\mathscr{F}} \text{sinc}\left(\frac{\omega}{2}\right) \normalsize \end{equation*}

Plot time shift and scaling (i)¶

$ \text{rect}\left(\frac{(t-5)}{4}\right) $

Show Python Code
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

import numpy as np
import matplotlib.pyplot as plt

import seaborn as sns

plt.rcdefaults() 
plt.xkcd()

fig = plt.figure(figsize=(6,4))  # sets size and makes it square
ax = plt.axes()             

# Reset default params
#sns.set()

# Set context to paper | talk | notebook | poster
# sns.set_context("poster")

start = -5
stop = 25
points = 201          # odd is easier

t = np.linspace(start, stop, points)
y = rect((t-5)/4)

# Major ticks every 5, minor ticks every 1
major_ticks = np.arange(start, stop+5, 5)
minor_ticks = np.arange(start, stop+1, 1)

ax.set_xticks(major_ticks)
ax.set_xticks(minor_ticks, minor=True)

#plt.minorticks_on()

plt.grid(which = 'major', color='g', linestyle='-', linewidth=0.2)
plt.grid(which = 'minor', visible = 'true', color='gray', linestyle='-', linewidth=0.1)

plt.plot(t, y)
plt.title(r"rect$ (\frac {(t-5)}{4})$")
plt.xlabel("t")
plt.ylabel("magnitude")
plt.show()

Calculate the Fourier Transform¶

Now use WolframAlpha to check the Fourier Transform:

FourierTransform( {rect( (t-5)/ 4 ) }, t, w, FourierParameters -> {1, -1} )

Response is: (I modified this by hand, and created a MathJax representation)

\begin{equation*} \Large \text{rect}\left(\frac{(t-5)}{4}\right) \xrightarrow{\mathscr{F}} {4} {e^{-j 5 \omega}} {\text{sinc}(2{\omega})} \normalsize \end{equation*}

Plot time shift and scaling (ii)¶

$ \text{rect}(\frac{t}{4} -5) $

Show Python Code
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

import numpy as np
import matplotlib.pyplot as plt

import seaborn as sns

plt.rcdefaults() 
plt.xkcd()

fig = plt.figure(figsize=(6,4))  # sets size and makes it square
ax = plt.axes() 

# Reset default params
#sns.set()

# Set context to paper | talk | notebook | poster
# sns.set_context("poster")

start = -5
stop = 25
points = 201          # odd is easier

t = np.linspace(start, stop, points)
y = rect((t/4-5))

# Major ticks every 5, minor ticks every 1
major_ticks = np.arange(start, stop+5, 5)
minor_ticks = np.arange(start, stop+1, 1)

ax.set_xticks(major_ticks)
ax.set_xticks(minor_ticks, minor=True)

#plt.minorticks_on()

plt.grid(which = 'major', color='g', linestyle='-', linewidth=0.2)
plt.grid(which = 'minor', b = 'true', color='gray', linestyle='-', linewidth=0.1)

plt.plot(t, y)
plt.title(r"rect$ (\frac {t}{4} - 5)$")
plt.xlabel("t (time)")
plt.ylabel("magnitude")
plt.show()
C:\Users\leffel\AppData\Local\Temp\ipykernel_7476\1229259475.py:38: MatplotlibDeprecationWarning: The 'b' parameter of grid() has been renamed 'visible' since Matplotlib 3.5; support for the old name will be dropped two minor releases later.
  plt.grid(which = 'minor', b = 'true', color='gray', linestyle='-', linewidth=0.1)

Calculate the Fourier Transform¶

Now use WolframAlpha to check the Fourier Transform:

FourierTransform( {rect( (t/4) - 5 ) }, t, w, FourierParameters -> {1, -1} )

Response is: (I modified this by hand, and created a MathJax representation)

\begin{equation*} \Large \text{rect}\left(\frac{t}{4}-5\right) = \text{rect}\left(\frac{t-20}{4}\right) \normalsize \end{equation*}\begin{equation*} \Large \text{rect}\left(\frac{t-20}{4}\right) \xrightarrow{\mathscr{F}}{4} {e^{-j 20 \omega}} {\text{sinc}(2\omega)} \normalsize \end{equation*}