Open in the MATLAB editor: c09fc_example
function c09fc_example fprintf('c09fc example results\n\n'); % Data m = int64(7); n = int64(6); fr = int64(5); a = zeros(m, n, fr); a(:, :, 1) = [3, 2, 2, 2, 1, 1; 2, 9, 1, 2, 1, 3; 2, 5, 1, 2, 1, 1; 1, 6, 2, 2, 7, 2; 5, 3, 2, 2, 4, 7; 2, 2, 1, 1, 2, 1; 6, 2, 1, 3, 6, 9]; a(:, :, 2) = [2, 1, 5, 1, 2, 3; 2, 9, 5, 2, 1, 2; 2, 3, 2, 7, 1, 1; 2, 1, 1, 2, 3, 1; 2, 1, 2, 8, 3, 3; 1, 4, 5, 1, 2, 7; 8, 1, 3, 9, 1, 2]; a(:, :, 3) = [3, 1, 4, 1, 1, 1; 1, 1, 2, 1, 2, 6; 4, 1, 7, 2, 5, 6; 3, 2, 1, 5, 9, 5; 1, 1, 2, 2, 2, 1; 2, 6, 3, 9, 5, 1; 1, 1, 8, 2, 1, 3]; a(:, :, 4) = [5, 8, 1, 2, 2, 1; 1, 2, 2, 9, 2, 9; 2, 2, 2, 1, 1, 3; 1, 1, 1, 5, 1, 2; 3, 2, 8, 1, 9, 2; 2, 1, 9, 1, 2, 2; 3, 6, 5, 3, 2, 2]; a(:, :, 5) = [5, 2, 1, 2, 1, 1; 3, 1, 9, 1, 2, 1; 2, 3, 1, 1, 7, 2; 7, 2, 2, 6, 1, 1; 5, 1, 7, 2, 1, 1; 2, 1, 3, 2, 2, 1; 5, 3, 9, 1, 4, 1]; % Query wavelet filter dimensions wavnam = 'Bior1.1'; mode = 'period'; wtrans = 'Multilevel'; [nwl, nf, nwct, nwcn, nwcfr, icomm, ifail] = ... c09ac(... wavnam, wtrans, mode, m, n, fr); % Perform Discrete Wavelet transform [c, dwtlvm, dwtlvn, dwtlvfr, icomm, ifail] = ... c09fc(... n, fr, a, nwct, nwl, icomm); fprintf(' Number of Levels : %d\n\n', nwl); fprintf(' Number of coefficients in 1st dimension for each level:\n'); fprintf(' %8d', dwtlvm(1:nwl)); fprintf('\n'); fprintf(' Number of coefficients in 2nd dimension for each level:\n'); fprintf(' %8d', dwtlvn(1:nwl)); fprintf('\n'); fprintf(' Number of coefficients in 3rd dimension for each level:\n'); fprintf(' %8d', dwtlvfr(1:nwl)); fprintf('\n'); % Print the first level HLL detail coefficients want_level = int64(1); want_coeffs = int64(4); cpass = char('LLH','LHL','LHH','HLL','HLH','HHL','HHH'); if (want_coeffs==0) title = 'Approximation coefficients (LLL)' else title = sprintf('Detail coefficients (%s)',cpass(want_coeffs,:)); end % Extract coefficients [d, icomm, ifail] = c09fy(... want_level, want_coeffs, c, icomm); fprintf('\n%s\n Level %2d, Coefficients %2d :\n',title, want_level, ... want_coeffs ); % Matrix printing arguments matrix = 'General'; diag = 'Non-unit'; fmt = 'F9.4'; labrow = 'Integer'; labcol = labrow; rlabs = {' '}; clabs = rlabs; ncols = int64(80); indent = int64(0); nk = dwtlvfr(nwl-want_level+1); for k = 1:nk title = sprintf('Frame: %3d',k); [ifail] = x04cb(... matrix, diag, d(:,:,k), fmt, title, labrow, ... rlabs, labcol, clabs, ncols, indent); end % Reconstruct original data [b, ifail] = c09fd(nwl, c, m, n, fr, icomm); % Check reconstruction matches original eps = 10*double(m*n*fr)*x02aj; err = a-b; frob = 0; for i=1:fr fnew = sqrt(sum(sum(err(:,:,i).^2))); frob = max(frob,fnew); end if frob < eps fprintf('\nSuccess: the reconstruction matches the original.\n'); else fprintf('\nFail: Frobenius norm of b-a is too large.\n'); end
c09fc example results Number of Levels : 2 Number of coefficients in 1st dimension for each level: 2 4 Number of coefficients in 2nd dimension for each level: 2 3 Number of coefficients in 3rd dimension for each level: 2 3 Detail coefficients (HLL) Level 1, Coefficients 4 : Frame: 1 1 2 3 1 -4.9497 0.0000 0.0000 2 0.7071 1.7678 -3.1820 3 0.7071 2.1213 1.7678 4 0.0000 0.0000 0.0000 Frame: 2 1 2 3 1 4.2426 -2.1213 -4.9497 2 0.7071 -0.0000 -0.7071 3 -1.4142 -3.1820 1.4142 4 0.0000 0.0000 0.0000 Frame: 3 1 2 3 1 2.1213 -4.9497 -0.7071 2 -2.8284 -4.2426 4.9497 3 2.1213 2.8284 -0.7071 4 0.0000 0.0000 0.0000 Success: the reconstruction matches the original.