# HG changeset patch # User Aris Gretsistas # Date 1332430665 0 # Node ID c38d965b5a1de66b3422dfc1424ed581a04bd317 # Parent 8b3c71bb44ebdbc0ed2b199da5829a485b84db54 Moved CVX_add_const_Audio_declipping.m from solvers to the examples/AudioInpainting folder. diff -r 8b3c71bb44eb -r c38d965b5a1d examples/AudioInpainting/CVX_add_const_Audio_declipping.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/AudioInpainting/CVX_add_const_Audio_declipping.m Thu Mar 22 15:37:45 2012 +0000 @@ -0,0 +1,85 @@ +function solver=CVX_add_const_Audio_declipping(Problem, solver, idxFrame) + +%% CVX additional constrains + % Clipping level: take the analysis window into account + % clipping level detection + + signal = Problem.b1; + signalFull = Problem.b(:,idxFrame); + Dict = Problem.A; + DictFull = Problem.B; + Clipped = ~Problem.M(:,idxFrame); + W=1./sqrt(diag(Dict'*Dict)); + + idxCoeff = find(solver.solution~=0); + + solution = solver.solution; + + wa = Problem.wa(Problem.windowSize); % analysis window + + + clippingLevelEst = max(abs(signal./wa(~Clipped)')); + + idxPos = find(signalFull>=0 & Clipped); + idxNeg = find(signalFull<0 & Clipped); + + DictPos=DictFull(idxPos,:); + DictNeg=DictFull(idxNeg,:); + + + wa_pos = wa(idxPos); + wa_neg = wa(idxNeg); + b_ineq_pos = wa_pos(:)*clippingLevelEst; + b_ineq_neg = -wa_neg(:)*clippingLevelEst; + if isfield(Problem,'Upper_Limit') && ~isempty(Problem.Upper_Limit) + b_ineq_pos_upper_limit = wa_pos(:)*Problem.Upper_Limit; + b_ineq_neg_upper_limit = -wa_neg(:)*Problem.Upper_Limit; + else + b_ineq_pos_upper_limit = Inf; + b_ineq_neg_upper_limit = -Inf; + end + + + j = length(idxCoeff); + + if isinf(b_ineq_pos_upper_limit) + %% CVX code + cvx_begin + cvx_quiet(true) + variable solution(j) + minimize(norm(Dict(:,idxCoeff)*solution-signal)) + subject to + DictPos(:,idxCoeff)*(W(idxCoeff).*solution) >= b_ineq_pos + DictNeg(:,idxCoeff)*(W(idxCoeff).*solution) <= b_ineq_neg + cvx_end + if cvx_optval>1e3 + cvx_begin + cvx_quiet(true) + variable solution(j) + minimize(norm(Dict(:,idxCoeff)*solution-xObs)) + cvx_end + end + else + %% CVX code + cvx_begin + cvx_quiet(true) + variable solution(j) + minimize(norm(Dict(:,idxCoeff)*solution-signal)) + subject to + DictPos(:,idxCoeff)*(W(idxCoeff).*solution) >= b_ineq_pos + DictNeg(:,idxCoeff)*(W(idxCoeff).*solution) <= b_ineq_neg + DictPos(:,idxCoeff)*(W(idxCoeff).*solution) <= b_ineq_pos_upper_limit + DictNeg(:,idxCoeff)*(W(idxCoeff).*solution) >= b_ineq_neg_upper_limit + cvx_end + if cvx_optval>1e3 + cvx_begin + cvx_quiet(true) + variable solution(j) + minimize(norm(Dict(:,idxCoeff)*solution-xObs)) + cvx_end + end + end + + solver.solution(idxCoeff) = solution; + + \ No newline at end of file diff -r 8b3c71bb44eb -r c38d965b5a1d solvers/CVX_add_const_Audio_declipping.m --- a/solvers/CVX_add_const_Audio_declipping.m Thu Mar 22 14:41:04 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -function solver=CVX_add_const_Audio_declipping(Problem, solver, idxFrame) - -%% CVX additional constrains - % Clipping level: take the analysis window into account - % clipping level detection - - signal = Problem.b1; - signalFull = Problem.b(:,idxFrame); - Dict = Problem.A; - DictFull = Problem.B; - Clipped = ~Problem.M(:,idxFrame); - W=1./sqrt(diag(Dict'*Dict)); - - idxCoeff = find(solver.solution~=0); - - solution = solver.solution; - - wa = Problem.wa(Problem.windowSize); % analysis window - - - clippingLevelEst = max(abs(signal./wa(~Clipped)')); - - idxPos = find(signalFull>=0 & Clipped); - idxNeg = find(signalFull<0 & Clipped); - - DictPos=DictFull(idxPos,:); - DictNeg=DictFull(idxNeg,:); - - - wa_pos = wa(idxPos); - wa_neg = wa(idxNeg); - b_ineq_pos = wa_pos(:)*clippingLevelEst; - b_ineq_neg = -wa_neg(:)*clippingLevelEst; - if isfield(Problem,'Upper_Limit') && ~isempty(Problem.Upper_Limit) - b_ineq_pos_upper_limit = wa_pos(:)*Problem.Upper_Limit; - b_ineq_neg_upper_limit = -wa_neg(:)*Problem.Upper_Limit; - else - b_ineq_pos_upper_limit = Inf; - b_ineq_neg_upper_limit = -Inf; - end - - - j = length(idxCoeff); - - if isinf(b_ineq_pos_upper_limit) - %% CVX code - cvx_begin - cvx_quiet(true) - variable solution(j) - minimize(norm(Dict(:,idxCoeff)*solution-signal)) - subject to - DictPos(:,idxCoeff)*(W(idxCoeff).*solution) >= b_ineq_pos - DictNeg(:,idxCoeff)*(W(idxCoeff).*solution) <= b_ineq_neg - cvx_end - if cvx_optval>1e3 - cvx_begin - cvx_quiet(true) - variable solution(j) - minimize(norm(Dict(:,idxCoeff)*solution-xObs)) - cvx_end - end - else - %% CVX code - cvx_begin - cvx_quiet(true) - variable solution(j) - minimize(norm(Dict(:,idxCoeff)*solution-signal)) - subject to - DictPos(:,idxCoeff)*(W(idxCoeff).*solution) >= b_ineq_pos - DictNeg(:,idxCoeff)*(W(idxCoeff).*solution) <= b_ineq_neg - DictPos(:,idxCoeff)*(W(idxCoeff).*solution) <= b_ineq_pos_upper_limit - DictNeg(:,idxCoeff)*(W(idxCoeff).*solution) >= b_ineq_neg_upper_limit - cvx_end - if cvx_optval>1e3 - cvx_begin - cvx_quiet(true) - variable solution(j) - minimize(norm(Dict(:,idxCoeff)*solution-xObs)) - cvx_end - end - end - - solver.solution(idxCoeff) = solution; - - \ No newline at end of file