0
$\begingroup$

I have problem with upsampling implementation in the following way: enter image description here

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[0]-t[1])

#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: enter image description here

For [1. 6. 3.], K = 5 (Decimation factor): enter image description here

Could you help me find the solution for this problem?

$\endgroup$

1 Answer 1

0
$\begingroup$

After upsampling with zero-insert, the higher frequency images need to be filtered out, which will serve the purpose of growing the zero insert values to the correct interpolated value in between samples. Once this is done, subsequent decimation operations can be properly done since every sample will then properly represent the signal.

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.

For further details see related post: Choosing right cut-off frequency for a LP filter in upsampler

$\endgroup$
1
  • $\begingroup$ Thank you so much for comprehensive explanation. I dealt with the problem :) $\endgroup$
    – Alex
    Commented May 17, 2020 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.