ivan@138: function [problemData, solutionData] = generateMissingGroupsProblem(xFrame,problemParameters) ivan@138: % ivan@138: % ivan@138: % Usage: ivan@138: % ivan@138: % ivan@138: % Inputs: ivan@138: % - ivan@138: % - ivan@138: % - ivan@138: % - ivan@138: % - ivan@138: % - ivan@138: % - ivan@138: % - ivan@138: % ivan@138: % Outputs: ivan@138: % - ivan@138: % - ivan@138: % - ivan@138: % - ivan@138: % ivan@138: % Note that the CVX library is needed. ivan@138: % ivan@138: % ------------------- ivan@138: % ivan@138: % Audio Inpainting toolbox ivan@138: % Date: June 28, 2011 ivan@138: % By Valentin Emiya, Amir Adler, Maria Jafari ivan@138: % This code is distributed under the terms of the GNU Public License version 3 (http://www.gnu.org/licenses/gpl.txt). ivan@138: ivan@138: % Generate a clipping problem: normalize and clip a signal. ivan@138: % ivan@138: % Usage: ivan@138: % [problemData, solutionData] = makeClippedSignal(x,clippingLevel,GR) ivan@138: % ivan@138: % Inputs: ivan@138: % - x: input signal (may be multichannel) ivan@138: % - clippingLevel: clipping level, between 0 and 1 ivan@138: % - GR (default: false): flag to generate an optional graphical display ivan@138: % ivan@138: % Outputs: ivan@138: % - problemData.xClipped: clipped signal ivan@138: % - problemData.IClipped: boolean vector (same size as problemData.xClipped) that indexes clipped ivan@138: % samples ivan@138: % - problemData.clipSizes: size of the clipped segments (not necessary ivan@138: % for solving the problem) ivan@138: % - solutionData.xClean: clean signal (input signal after normalization ivan@138: % ivan@138: % Note that the input signal is normalized to 0.9999 (-1 is not allowed in ivan@138: % wav files) to provide problemData.xClipped and solutionData.xClean. ivan@138: ivan@138: %function [xFrame,xFrameObs,Imiss] = aux_getFrame(xFrame,holeSize,NHoles)%,param,frameParam,kFrame) ivan@138: ivan@138: N = length(xFrame); % frame length ivan@138: ivan@138: % Load frame ivan@138: % xFrame = wavread(param.wavFiles{frameParam.kFrameFile(kFrame)},frameParam.kFrameBegin(kFrame)+[0,N-1]); ivan@138: ivan@138: % Window ivan@138: %xFrame = xFrame.*param.wa(N).'; ivan@138: ivan@138: % Normalize ivan@138: xFrame = xFrame/max(abs(xFrame)); ivan@138: ivan@138: % Build random measurement matrix with NHoles of length holeSize ivan@138: [M IMiss] = makeRandomMeasurementMatrix(N,problemParameters.NHoles,problemParameters.holeSize); ivan@138: xFrameObs = xFrame; ivan@138: xFrameObs(IMiss) = 0; ivan@138: ivan@138: problemData.x = xFrameObs; ivan@138: problemData.IMiss = IMiss; ivan@138: solutionData.xClean = xFrame; ivan@138: return ivan@138: ivan@138: ivan@138: function [M Im] = makeRandomMeasurementMatrix(N,NMissingBlocks,blockSize) ivan@138: % [M Im] = makeRandomMeasurementMatrix(N,NMissingBlocks,blockSize) ivan@138: % Create a random measurement matrix M where NMissingBlocks blocks with ivan@138: % size blockSize each are randomly inserted. The boolean vector Im ivan@138: % indicates the location of the NMissingBlocks*blockSize missing ivan@138: % samples. ivan@138: % If the number of missing samples is large, there may be very few solutions ivan@138: % so that after a few failing attempts, the results is generated in a deterministic ivan@138: % way (groups separated by one sample). This happens for example when the number of ivan@138: % missing samples is close to half the frame length, for isolated samples (blockSize=1). ivan@138: ivan@138: nTry = 1; ivan@138: while true ivan@138: try ivan@138: Im = false(N,1); ivan@138: ivan@138: possibleStart = 1:N-blockSize+1; ivan@138: ivan@138: for k=1:NMissingBlocks ivan@138: if isempty(possibleStart) ivan@138: error('makeRandomMeasurementMatrix:tooMuchMissingSamples',... ivan@138: 'Too much missing segments'); ivan@138: end ivan@138: I = ceil(rand*(length(possibleStart)-1)); ivan@138: I = possibleStart(I); ivan@138: Im(I+(0:blockSize-1)) = true; ivan@138: possibleStart(possibleStart>=I-blockSize & possibleStart<=I+blockSize) = []; ivan@138: end ivan@138: break ivan@138: catch ivan@138: fprintf('makeRandomMeasurementMatrix:retry (%d)\n',nTry); ivan@138: nTry = nTry+1; ivan@138: if nTry>10 ivan@138: Im = [true(blockSize,NMissingBlocks);false(1,NMissingBlocks)]; ivan@138: Im = Im(:); ivan@138: while length(Im)