Home > atmlab > gridcreation > annealing > join_fast_f_grid.m

join_fast_f_grid

PURPOSE ^

JOIN_FAST_F_GRID combine the optimized f_grids and weights from

SYNOPSIS ^

function join_fast_f_grid(cpara)

DESCRIPTION ^

 JOIN_FAST_F_GRID combine the optimized f_grids and weights from
 individual channels to one dataset

 join_fast_f_grid: Reads the f_grid from the individual channels
 which should be combined together with the annealing results of
 these channels and combines them to
 one long f_grid with the according weights in a sparse matrix

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

join_fast_f_grid.m

SOURCE CODE ^

0001 function join_fast_f_grid(cpara)
0002 % JOIN_FAST_F_GRID combine the optimized f_grids and weights from
0003 % individual channels to one dataset
0004 %
0005 % join_fast_f_grid: Reads the f_grid from the individual channels
0006 % which should be combined together with the annealing results of
0007 % these channels and combines them to
0008 % one long f_grid with the according weights in a sparse matrix
0009 
0010 % FORMAT
0011 %
0012 %   Result=apply_annealing(filename_H,filename_y_mono,nlos,Cloop,C)
0013 %
0014 % IN
0015 %   cpara a structure with required parameters for the function
0016 %
0017 %    cpara.f_grid_files Cell-array which contains all names
0018 %                       of files with the original frequency grids
0019 %                       of the individual channels.
0020 %
0021 %    cpara.annealing_result_files Cell-array which contains all names
0022 %                                of files with the Annealing results
0023 %                                of the individual channels
0024 %
0025 %    cpara.file_f_grid_fast filename where the new reduced
0026 %                           frequency grid shall be written
0027 %
0028 %    cpara.file_Weights filename where the weights for the new
0029 %                           frequencygrid shall be written as
0030 %                           sparse matrix
0031 %
0032 % By Stefan Buehler/Mathias Milz
0033 %
0034 
0035 %
0036 disp('Post-processing...')
0037 
0038 % Now we have to put together the results for the different
0039 % channels. Far from trivial, unfortunately.
0040 
0041 % Collect all frequencies and weights for all channels:
0042 fgf = [];
0043 Wf  = sparse([]);
0044 nchan=length(cpara.f_grid_files)
0045 ncheck=length(cpara.annealing_result_files)
0046 for i=1:nchan
0047    
0048     Annealresfile=cpara.annealing_result_files{i};
0049     load(Annealresfile);
0050     R=Result;
0051     channel_f_grid_file=cpara.f_grid_files{i};
0052     channel_f_grid=xmlLoad(channel_f_grid_file);
0053     
0054 % What we get back for each channel is a logical vector, with those
0055 % indices that we want to keep set to true.
0056 
0057   % Position of this channel in the total fgf:
0058   pos = length(fgf);
0059 
0060   % Get those frequencies and weights for this channel that
0061   % correspond to active channels:
0062   this_f_grid_x = channel_f_grid(R(end).sb)';
0063   this_Wb_x = R(end).Wb(:,R(end).sb);
0064 
0065   % Check if there are frequencies with weight zero, and remove
0066   % them.
0067   this_f_grid = [];
0068   this_Wb     = [];
0069   for j=1:length(this_f_grid_x)
0070 
0071     % Get this column of this_Wb:
0072     tc = this_Wb_x(:,j);
0073 
0074     % Find nonzero elements:
0075     nz = find(tc);
0076 
0077     if (length(nz)>1)
0078       error(sprintf('Internal error in zero weight removal loop, length(nz) = %d.',length(nz)))
0079     end
0080 
0081     % If weight is ok, append to f_grid and Wb:
0082     if (length(nz)==1)
0083       this_f_grid = [this_f_grid, this_f_grid_x(j)];
0084       this_Wb     = [this_Wb,     this_Wb_x(:,j)];
0085     end
0086 
0087     % If weight is zero, ignore this frequency:
0088     if (length(nz)==0)
0089       disp(sprintf(['Ignoring zero weight frequency, number = %d, ' ...
0090                     'value = %f.'], j, this_f_grid_x(j)));
0091     end
0092 
0093   end
0094 
0095   fgf = [fgf, this_f_grid];
0096   Wf(i,pos+1:pos+length(this_f_grid)) = this_Wb;
0097 end
0098 
0099 % Now it gets tricky. We have to sort and remove duplicate values
0100 [f_grid_fast, m, n] = unique(fgf);
0101 
0102 % f_grid_fast is the sorted frequency grid, with duplicate values
0103 % removed. m and n are such that:
0104 %    f_grid_fast = fgf(m) and fgf = f_grid_fast(n)
0105 %
0106 % The n is crucial for us, we can use it to construct the new
0107 % weight matrix.
0108 
0109 W_fast = sparse(nchan, length(f_grid_fast));
0110 for i=1:length(n)
0111   % Get this column of Wf:
0112   tc = Wf(:,i);
0113 
0114   % Find nonzero elements:
0115   nz = find(tc);
0116 
0117   % There should only be a single nonzero element, since each
0118   % channel had its own frequency grid.
0119   if (length(nz)~=1)
0120     error(sprintf('Internal error, length(nz) = %d.',length(nz)))
0121   end
0122 
0123   % Check that field is not already occupied (it should never
0124   % happen, since each channel had its own frequency grid).
0125   if (W_fast(nz,n(i))~=0)
0126     error(sprintf('Internal error, weight position (%d,%d) already occupied.',...
0127                   nz, n(i)));
0128   end
0129 
0130   % Store the weight in the right place:
0131   W_fast(nz,n(i)) = tc(nz);
0132 
0133 end
0134 
0135 disp(sprintf('Removed duplicate frequencies: %d', length(fgf)-length(f_grid_fast)));
0136 
0137 
0138 % Store frequency grid:
0139 xmlStore(cpara.file_f_grid_fast, f_grid_fast, 'Vector');
0140 
0141 % Store weight matrix:
0142 xmlStore(cpara.file_weights, W_fast, 'Sparse');
0143 
0144 
0145 
0146

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005