function H = generateHaarMatrix(n) % generate the normalized Haar matrix of order 2^n % recursive implementation if n == 0 H = 1; % base case else % recursive step H_prev = generateHaarMatrix(n-1); % generate Haar matrix of previous order I = eye(2^(n-1)); % identity matrix of size 2^(n-1) % Kronecker products for constructing the next level Haar matrix top = (1/sqrt(2)) * kron(I, [1 1]); % approximation bottom = (1/sqrt(2)) * kron(H_prev, [1 -1]); % detail H = [top; bottom]; % combine to form the next level Haar matrix end end