BMEBW4020 Project1 Q2 Handout

Project1-Q2-Handout

In this problem you are asked to derive and implement a TEM/TDM algorithm for an ASDM with feedback, as depicted in the figure below:

Stimulus and Filter¶
Generate a random, normalized stimulus $u(t)$ with $\max(\|u(t)\|) = 1$, use a sinc basis.
The filter $h$ is given as:
h(t)= 0.01 \cdot \mbox{exp}\left(-100 t\right)\cdot \mathbb{1}_{t\ge 0}
Note that $\mathbb{1}_{t\ge 0}$ is also known as the Heaviside Step function which ensures that the filter $h(t)$ is causal.

Encode and decode the generated stimulus $u$ with the model specified above. Plot your results in the time-domain along with a corresponding SNR plot.

# import libraries
import numpy as np
from scipy.integrate import cumulative_trapezoid as cumtrapz
import matplotlib.pyplot as plt
import typing as tp
np.random.seed(0)

# define stimulus space
def sinc_basis(t, sk, omega):
if np.isscalar(sk):
return omega / np.pi * np.sinc(omega / np.pi * (t – sk))
return omega / np.pi * np.sinc(omega / np.pi * (t[None, :] – sk[:, None]))

def stimulus(t, omega, ck, normalize=True):
Generate a stimulus as a sum of sinc functions

Arguments:
t: 1D array of the time period for the resultant stimulus
omega: scalar frequency of the sinc basis functions
s: 1D array of amplitudes for the sinc functions

1D array containing the stimulus
out = np.zeros_like(t)
T = np.pi / omega # sampling interval at nyquist rate
sk = np.arange(len(ck)) * T # uniform sample at nyquist rate
out = ck @ sinc_basis(t, sk, omega)
if normalize:
return out / np.max(np.abs(out))
return out

# define ASDM model

# create stimulus
f = 50 # Hertz
omega = 2 * np.pi * f
T = np.pi / omega
dt = 1e-5 # seconds
ds = 150 # downsampling factor
t = np.arange(0, 20 * T, dt)
c = np.random.rand(15) – 0.5
u = stimulus(t, omega, c)

# instantiate model

# encode stimulus

# decode stimulus

# plot recovery results