How do I build a patterned matrix (high-pass and/or low-pass filter bank)?

Taking your self-answer as a guide you can still use SparseArray and Band

n = 5;

SparseArray[{Band[{1, 1}] -> 1, Band[{1, 2}] -> 1}, {n, n}] // Grid

$\begin{matrix} 1 & 1 & 0 & 0 & 0 \\ 0 & 1 & 1 & 0 & 0 \\ 0 & 0 & 1 & 1 & 0 \\ 0 & 0 & 0 & 1 & 1 \\ 0 & 0 & 0 & 0 & 1 \\ \end{matrix}$

SparseArray[{Band[{1, 1}] -> 1, Band[{1, 2}] -> -1}, {n, n}] // Grid

$\begin{matrix} 1 & -1 & 0 & 0 & 0 \\ 0 & 1 & -1 & 0 & 0 \\ 0 & 0 & 1 & -1 & 0 \\ 0 & 0 & 0 & 1 & -1 \\ 0 & 0 & 0 & 0 & 1 \\ \end{matrix}$

Use Normal to convert to a standard list-of-lists if you need it.


One way is to use DiagonalMatrix

n = 5; 
DiagonalMatrix[ConstantArray[1, n]] + DiagonalMatrix[ConstantArray[-1, n - 1], 1]

for the highpass and

DiagonalMatrix[ConstantArray[1, n]] + DiagonalMatrix[ConstantArray[1, n - 1], 1]

for the lowpass.


Also for fun:

lowpass[n_Integer] := ToeplitzMatrix[UnitVector[n, 1], PadRight[{1, 1}, n]]

highpass[n_Integer] := ToeplitzMatrix[UnitVector[n, 1], PadRight[{1, -1}, n]]

In practice, I'd use Wizard's route, however.