annotate toolboxes/AudioInpaintingToolbox/Problems/generateMissingGroupsProblem.m @ 216:a986ee86651e luisf_dev

Calls SMALLboxInit in the beginning of both solve and learn, in order not to lose the SMALL_path variable.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 22 Mar 2012 11:41:04 +0000
parents 56d719a5fd31
children
rev   line source
ivan@138 1 function [problemData, solutionData] = generateMissingGroupsProblem(xFrame,problemParameters)
ivan@138 2 %
ivan@138 3 %
ivan@138 4 % Usage:
ivan@138 5 %
ivan@138 6 %
ivan@138 7 % Inputs:
ivan@138 8 % -
ivan@138 9 % -
ivan@138 10 % -
ivan@138 11 % -
ivan@138 12 % -
ivan@138 13 % -
ivan@138 14 % -
ivan@138 15 % -
ivan@138 16 %
ivan@138 17 % Outputs:
ivan@138 18 % -
ivan@138 19 % -
ivan@138 20 % -
ivan@138 21 % -
ivan@138 22 %
ivan@138 23 % Note that the CVX library is needed.
ivan@138 24 %
ivan@138 25 % -------------------
ivan@138 26 %
ivan@138 27 % Audio Inpainting toolbox
ivan@138 28 % Date: June 28, 2011
ivan@138 29 % By Valentin Emiya, Amir Adler, Maria Jafari
ivan@138 30 % This code is distributed under the terms of the GNU Public License version 3 (http://www.gnu.org/licenses/gpl.txt).
ivan@138 31
ivan@138 32 % Generate a clipping problem: normalize and clip a signal.
ivan@138 33 %
ivan@138 34 % Usage:
ivan@138 35 % [problemData, solutionData] = makeClippedSignal(x,clippingLevel,GR)
ivan@138 36 %
ivan@138 37 % Inputs:
ivan@138 38 % - x: input signal (may be multichannel)
ivan@138 39 % - clippingLevel: clipping level, between 0 and 1
ivan@138 40 % - GR (default: false): flag to generate an optional graphical display
ivan@138 41 %
ivan@138 42 % Outputs:
ivan@138 43 % - problemData.xClipped: clipped signal
ivan@138 44 % - problemData.IClipped: boolean vector (same size as problemData.xClipped) that indexes clipped
ivan@138 45 % samples
ivan@138 46 % - problemData.clipSizes: size of the clipped segments (not necessary
ivan@138 47 % for solving the problem)
ivan@138 48 % - solutionData.xClean: clean signal (input signal after normalization
ivan@138 49 %
ivan@138 50 % Note that the input signal is normalized to 0.9999 (-1 is not allowed in
ivan@138 51 % wav files) to provide problemData.xClipped and solutionData.xClean.
ivan@138 52
ivan@138 53 %function [xFrame,xFrameObs,Imiss] = aux_getFrame(xFrame,holeSize,NHoles)%,param,frameParam,kFrame)
ivan@138 54
ivan@138 55 N = length(xFrame); % frame length
ivan@138 56
ivan@138 57 % Load frame
ivan@138 58 % xFrame = wavread(param.wavFiles{frameParam.kFrameFile(kFrame)},frameParam.kFrameBegin(kFrame)+[0,N-1]);
ivan@138 59
ivan@138 60 % Window
ivan@138 61 %xFrame = xFrame.*param.wa(N).';
ivan@138 62
ivan@138 63 % Normalize
ivan@138 64 xFrame = xFrame/max(abs(xFrame));
ivan@138 65
ivan@138 66 % Build random measurement matrix with NHoles of length holeSize
ivan@138 67 [M IMiss] = makeRandomMeasurementMatrix(N,problemParameters.NHoles,problemParameters.holeSize);
ivan@138 68 xFrameObs = xFrame;
ivan@138 69 xFrameObs(IMiss) = 0;
ivan@138 70
ivan@138 71 problemData.x = xFrameObs;
ivan@138 72 problemData.IMiss = IMiss;
ivan@138 73 solutionData.xClean = xFrame;
ivan@138 74 return
ivan@138 75
ivan@138 76
ivan@138 77 function [M Im] = makeRandomMeasurementMatrix(N,NMissingBlocks,blockSize)
ivan@138 78 % [M Im] = makeRandomMeasurementMatrix(N,NMissingBlocks,blockSize)
ivan@138 79 % Create a random measurement matrix M where NMissingBlocks blocks with
ivan@138 80 % size blockSize each are randomly inserted. The boolean vector Im
ivan@138 81 % indicates the location of the NMissingBlocks*blockSize missing
ivan@138 82 % samples.
ivan@138 83 % If the number of missing samples is large, there may be very few solutions
ivan@138 84 % so that after a few failing attempts, the results is generated in a deterministic
ivan@138 85 % way (groups separated by one sample). This happens for example when the number of
ivan@138 86 % missing samples is close to half the frame length, for isolated samples (blockSize=1).
ivan@138 87
ivan@138 88 nTry = 1;
ivan@138 89 while true
ivan@138 90 try
ivan@138 91 Im = false(N,1);
ivan@138 92
ivan@138 93 possibleStart = 1:N-blockSize+1;
ivan@138 94
ivan@138 95 for k=1:NMissingBlocks
ivan@138 96 if isempty(possibleStart)
ivan@138 97 error('makeRandomMeasurementMatrix:tooMuchMissingSamples',...
ivan@138 98 'Too much missing segments');
ivan@138 99 end
ivan@138 100 I = ceil(rand*(length(possibleStart)-1));
ivan@138 101 I = possibleStart(I);
ivan@138 102 Im(I+(0:blockSize-1)) = true;
ivan@138 103 possibleStart(possibleStart>=I-blockSize & possibleStart<=I+blockSize) = [];
ivan@138 104 end
ivan@138 105 break
ivan@138 106 catch
ivan@138 107 fprintf('makeRandomMeasurementMatrix:retry (%d)\n',nTry);
ivan@138 108 nTry = nTry+1;
ivan@138 109 if nTry>10
ivan@138 110 Im = [true(blockSize,NMissingBlocks);false(1,NMissingBlocks)];
ivan@138 111 Im = Im(:);
ivan@138 112 while length(Im)<N
ivan@138 113 N0 = sum(~Im);
ivan@138 114 I0 = find(~Im,randi(N0),'first');
ivan@138 115 I0 = I0(end);
ivan@138 116 Im = [Im(1:I0);false;Im(I0+1:end)];
ivan@138 117 end
ivan@138 118 Im = circshift(Im,randi(N));
ivan@138 119 break;
ivan@138 120 end
ivan@138 121 end
ivan@138 122 end
ivan@138 123 M = eye(N);
ivan@138 124 M(Im,:) = [];
ivan@138 125
ivan@138 126 return