function C = modifyCoefficients(C, L, cD, level) % replace detail coefficients of a DWT at specified level len = length(cD); idxStart = sum(L(1:end-1)) - sum(L(end-level:end-1)) + 1; C(idxStart:idxStart+len-1) = cD; end