I've been trying to implement the MATLAB code of Prof.Selesnick's DWT implementation in Python for learning purposes.
function [lo, hi] = afb(x, af)
% [lo, hi] = afb(x, af)
%
% Analysis filter bank
% x -- N-point vector (N even); the resolution should be 2x filter length
%
% af -- analysis filters
% af(:, 1): lowpass filter (even length)
% af(:, 2): highpass filter (even length)
%
% lo: Low frequency
% hi: High frequency
%
N = length(x);
L = length(af)/2;
x = cshift(x,-L);
% lowpass filter
lo = upfirdn(x, af(:,1), 1, 2);
lo(1:L) = lo(N/2+[1:L]) + lo(1:L);
lo = lo(1:N/2);
% highpass filter
hi = upfirdn(x, af(:,2), 1, 2);
hi(1:L) = hi(N/2+[1:L]) + hi(1:L);
hi = hi(1:N/2);
I'm specifically stuck at lo(1:L) = lo(N/2+[1:L]) + lo(1:L);
I attempted lo[np.arange(0,L)]=lo[N // 2 + np.concatenate([np.arange(0,L)])) + lo[np.arange(0,L)]
but it seems not to be working. Will appreciate any help.
I have an input signal x with a size of 10,000, when I execute the code it stops right at that specific line and says index 5001 is out of bounds for axis 0 with size 5001
. I seem to be out of bounds.