annotate examples/AudioInpainting/CVX_add_const_Audio_declipping.m @ 236:5f4e47b78f2b ver_2.0_alpha1

Added example.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 19 Apr 2012 17:59:08 +0100
parents c38d965b5a1d
children 1fbd28dfb99e
rev   line source
aris@218 1 function solver=CVX_add_const_Audio_declipping(Problem, solver, idxFrame)
aris@218 2
aris@218 3 %% CVX additional constrains
aris@218 4 % Clipping level: take the analysis window into account
aris@218 5 % clipping level detection
aris@218 6
aris@218 7 signal = Problem.b1;
aris@218 8 signalFull = Problem.b(:,idxFrame);
aris@218 9 Dict = Problem.A;
aris@218 10 DictFull = Problem.B;
aris@218 11 Clipped = ~Problem.M(:,idxFrame);
aris@218 12 W=1./sqrt(diag(Dict'*Dict));
aris@218 13
aris@218 14 idxCoeff = find(solver.solution~=0);
aris@218 15
aris@218 16 solution = solver.solution;
aris@218 17
aris@218 18 wa = Problem.wa(Problem.windowSize); % analysis window
aris@218 19
aris@218 20
aris@218 21 clippingLevelEst = max(abs(signal./wa(~Clipped)'));
aris@218 22
aris@218 23 idxPos = find(signalFull>=0 & Clipped);
aris@218 24 idxNeg = find(signalFull<0 & Clipped);
aris@218 25
aris@218 26 DictPos=DictFull(idxPos,:);
aris@218 27 DictNeg=DictFull(idxNeg,:);
aris@218 28
aris@218 29
aris@218 30 wa_pos = wa(idxPos);
aris@218 31 wa_neg = wa(idxNeg);
aris@218 32 b_ineq_pos = wa_pos(:)*clippingLevelEst;
aris@218 33 b_ineq_neg = -wa_neg(:)*clippingLevelEst;
aris@218 34 if isfield(Problem,'Upper_Limit') && ~isempty(Problem.Upper_Limit)
aris@218 35 b_ineq_pos_upper_limit = wa_pos(:)*Problem.Upper_Limit;
aris@218 36 b_ineq_neg_upper_limit = -wa_neg(:)*Problem.Upper_Limit;
aris@218 37 else
aris@218 38 b_ineq_pos_upper_limit = Inf;
aris@218 39 b_ineq_neg_upper_limit = -Inf;
aris@218 40 end
aris@218 41
aris@218 42
aris@218 43 j = length(idxCoeff);
aris@218 44
aris@218 45 if isinf(b_ineq_pos_upper_limit)
aris@218 46 %% CVX code
aris@218 47 cvx_begin
aris@218 48 cvx_quiet(true)
aris@218 49 variable solution(j)
aris@218 50 minimize(norm(Dict(:,idxCoeff)*solution-signal))
aris@218 51 subject to
aris@218 52 DictPos(:,idxCoeff)*(W(idxCoeff).*solution) >= b_ineq_pos
aris@218 53 DictNeg(:,idxCoeff)*(W(idxCoeff).*solution) <= b_ineq_neg
aris@218 54 cvx_end
aris@218 55 if cvx_optval>1e3
aris@218 56 cvx_begin
aris@218 57 cvx_quiet(true)
aris@218 58 variable solution(j)
aris@218 59 minimize(norm(Dict(:,idxCoeff)*solution-xObs))
aris@218 60 cvx_end
aris@218 61 end
aris@218 62 else
aris@218 63 %% CVX code
aris@218 64 cvx_begin
aris@218 65 cvx_quiet(true)
aris@218 66 variable solution(j)
aris@218 67 minimize(norm(Dict(:,idxCoeff)*solution-signal))
aris@218 68 subject to
aris@218 69 DictPos(:,idxCoeff)*(W(idxCoeff).*solution) >= b_ineq_pos
aris@218 70 DictNeg(:,idxCoeff)*(W(idxCoeff).*solution) <= b_ineq_neg
aris@218 71 DictPos(:,idxCoeff)*(W(idxCoeff).*solution) <= b_ineq_pos_upper_limit
aris@218 72 DictNeg(:,idxCoeff)*(W(idxCoeff).*solution) >= b_ineq_neg_upper_limit
aris@218 73 cvx_end
aris@218 74 if cvx_optval>1e3
aris@218 75 cvx_begin
aris@218 76 cvx_quiet(true)
aris@218 77 variable solution(j)
aris@218 78 minimize(norm(Dict(:,idxCoeff)*solution-xObs))
aris@218 79 cvx_end
aris@218 80 end
aris@218 81 end
aris@218 82
aris@218 83 solver.solution(idxCoeff) = solution;
aris@218 84
aris@218 85