# Upsampling implementation

I have problem with upsampling implementation in the following way: My code:

def expand(x, L, t=None):
"""
This function expands a given signal L-times. It also returns new timestamps if they were given.

Parameters:
x - Vector to expand.
L - Expansion factor. It should be an integer.

Returns:
y_L - Expanded signal.
t_L - New timestamps.
"""

n =  L * len(x)

y_L = np.empty(n)
t_L = np.zeros(n)
#delta_t = np.abs(t-t)

#delta_t_L = delta_t/L

for i in range(n):
if i % L == 0:
y_L[i] = x[i//L]
else:
y_L[i] = 0

t_L = np.arange(n)/L

#t_L = np.arange(0,len(x),delta_t_L).tolist() (Working only for [1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1])

if t is None:
return y_L

return y_L, t_L


The problem is with 't_L' array. I don't know how to define it correct.

It's working for this signal '[1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1]' but then I tried to decimate this signal and then extend it in this way

K = 5
L = 3

y_K, t_K = decimate(x, K, t)
y_L, t_L = expand(y_K, L, t_K)


For [1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1], L = 2: For [1. 6. 3.], K = 5 (Decimation factor): Could you help me find the solution for this problem?

For a signal that occupies BW $$\in [0, \omega_1]$$ with original sampling frequency at $$\omega = 2\pi$$ and is interpolated by $$I$$, after zero insert, the new sampling frequency will be at $$I2\pi$$ and $$I-1$$ images $$2\omega_1$$ wide will be centered at every multiple of the original sampling rate ($$N2\pi$$) for $$N \in [1,2,\ldots I-1]$$ within the new interpolated sampling rate $$\omega \in [0, I2\pi]$$.
In terms of the normalized angular output frequency with sampling rate $$\omega = 2\pi$$, the bandwidth of the original signal will be BW $$\in [0, \omega_1/I]$$ and the $$I-1$$ images will each be $$2\omega_1/I$$ wide and centered at multiples of $$N2\pi/I$$ for $$N \in [1,2,\ldots I-1/I]$$.
scipy.signal.firls() is a good choice for creating an interpolation filter and supports multiband filters to maximize rejection at the image frequencies. Decimation will follow a similar image folding where the $$D-1$$ locations that would be folded in should also be considered for filtering prior to decimation.