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