Skip to content

Commit

Permalink
added remaining fusion frame fields@
Browse files Browse the repository at this point in the history
  • Loading branch information
allthatsounds committed Oct 16, 2023
1 parent 340d3fa commit 8d97f53
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 0 deletions.
56 changes: 56 additions & 0 deletions comp/comp_checkfudim.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function F = comp_checkfudim(F, L)
%CHECKFUDIM check Fusion Frame Dimension
%
% Usage: checkfudim(G);
%
% Input parameters:
% F frame
% L desired framelength
%
% Output parameters:
% F frame with additional parameter .cdim
%
%
% `checkfudim` checks if all local frames in a
% fusion frame share the same dimension.
%
% Example:
% F1 = [1 0; 0 1];
% F2 = [1 0 0; 0 1 0; 0 0 1];
% FF1 = frame('gen',F1);
% FF2 = frame('gen',F2);
% G = frame('fusion',1,FF1,FF2);
% G = checkfudim(G);
%
%
% Started: 23.12.2021
% Current: 04.11.2022
%
% Author: P. Balazs


complainif_notvalidframeobj(F,'MatrixRep');

%if nargin==1
%L = 160;
%end

if isfield(F, 'cdim')
return
elseif ~isfield(F, 'type') || ~strcmp(F.type, 'fusion')
error('Checkfudim only works for fusion frames');
end

for ii=1:F.Nframes
localframe = frameaccel(F.frames{ii}, framelength(F.frames{ii}, L));
FF=frsynmatrix(localframe,localframe.L);
M = size(FF, 1);
if ii > 2 && M ~= Mold
F.cdim = nan;
break
else
Mold = M;
end
end

F.cdim = Mold;
65 changes: 65 additions & 0 deletions comp/comp_fuana.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
function [proj,F] = comp_fuana(F,f,varargin)
%FUANA fusion frame analysis operator
%
% Input parameters:
% F fusion frame
% f input signal
%
% Output parameters:
% proj projection
% F loop back of fusion frames
%
%
% `fuana` does the fusion frame analysis, i.e
% $ p_j = (w_j \pi_{W_j} f )_j.$, where $(f)$
% is the signal/ function, $w_j$ teh weights,
% $W_j$ the subspaces (spanned by the local frames).
%
%
% Optional parameters:
% 'range',r vector or scalar, only calculate a specific range of projections, i.e. the projection on $W_j$
%
% Started: 23.12.2021
% Last: 8.11.2022
%
% Author: P. Balazs

complainif_notvalidframeobj(F,'Fuana');

if ~strcmp(F.type, 'fusion')
error('fuana only works for fusion frames');
end


definput.keyvals.range = [];
[~,kv]=ltfatarghelper({},definput,varargin);

if isfield(F, 'localdual')
FD = F.localdual;
else
FD = framedual(F);
end
L = length(f);
F = comp_checkfudim(F, L);

if isnan(F.cdim)
error('Local frames have to have the same dimension (for now).');
elseif F.cdim ~= length(f)
error('Local frames and signal do not fit.')
end

if ~isempty(kv.range)
proj = cell(1, 1);
else
kv.range = 1:F.Nframes;
proj = cell(F.Nframes, 1);
end

cnt = 1;
for ii=1:numel(kv.range)
jj = kv.range(ii);
c = frana(F.frames{jj},f);
c= flip(F.w(jj))*c;
proj{cnt} = frsyn(FD.frames{jj}, c);
cnt = ii+1;
end
48 changes: 48 additions & 0 deletions comp/comp_fudual.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function FfD = fudual(F, L)
%FUDUAL dual fusion frame
%
% Input parameters:
% F frame of which to calculate the dual
%
% Output parameters:
% FfD the dual frame
%
% `fudual` calculates the dual of the fusion frame operator.
% it differs from framedual, which calculates the dual of each single
% frame and inverts the weights to create a fusion frame (and stores
% them in a separate variable
%
% Started 15.01.2022
% Last 22.02.2022

complainif_notvalidframeobj(F,'Fudual');

F = checkfudim(F, L);

if ~strcmp(F.type, 'fusion')
error('fudual only works for fusion frames');
end

if isfield(F, 'frameoperator')
Sf = F.frameoperator;
else
Id = eye(F.cdim);
c = fuana(F,Id);
Sf = fusyn(F,c);
F.frameoperator = Sf;
end


for ii=1:F.Nframes
G = frsynmatrix(F.frames{ii}, F.cdim);
G = cell2mat(Sf)\G; %supposedly more efficient than G = inv(Sf)*G;
eval(sprintf("G_%i = frame('gen',G);",ii));
if ii == 1
fusionstring = "G_1";
else
fusionstring = sprintf("%s, G_%i",fusionstring, ii);
end
end
%weights could probably be passed directly
FfD = eval(sprintf('frame(''fusion'',1,%s)',fusionstring));
FfD.w = F.w; %weights are just the same
121 changes: 121 additions & 0 deletions comp/comp_fusyn.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
function [f,F] = comp_fusyn(F,coeff,varargin)
%FUSYN calculates the fusion frame synthesis operator
%
% Input parameters:
% F fusion frame
% coeff coeffcients, given as coeff{1} .. coeff{N}, for each
% element in C^L, where L = F.cdim and N= G.Nframes.
% (can also be a LxN array)
%
% Output parameters:
% f synthesized signal
% F loop back of usion frames
%
%
% `fusyn` Construct the fusion synthesis operator, i.e.
% $\sum \limits_i w_i \pi_{W_i} f_i $, where f_i = coeff{i}.
% We calculate
% $ f = \sum \limits_{l = 1}{N} w_l \pi_{W_l} f_l , $, where $(f_l)$
% are the coefficients, $w_l$ the weights, $W_l$ the subspaces
% (spanned by the local frames).
%
%
% Optional parameters:
% 'projections' Turn the projection off (Default: 0), i.e.
% $\sum \limits_i w_i f_i $
%
% 'operator' can be 'square' or 'frameoper': Square the weights.
% $\sum \limits_i w_i^2 \pi_{W_i} f_i $
% We are considering \ell^2(H) as coefficient space,
% so this is equivalent to the frame operator, if we
% use f_i = f.
%
%
% Started: 23.12.2021
% Current: 22.02.2022
%
% Author: P. Balazs
%
% Dependencies: LTFAT http://ltfat.org
%
% Copyright : (c) Acoustics Research Institute, Austrian Academy of
% Science
% http://www.kfs.oeaw.ac.at
%
% Permission is granted to modify and re-distribute this
% code for non-commercial usage in any manner as long as this
% notice is preserved. For research please cite the paper [1].
% All standard disclaimers apply.
%
% [1] P. Balazs, M. Shamsabadi, A. Arefijamaal, G. Chardon, "Representation
% of Operators Using Fusion Frames", submitted, 2022


complainif_notvalidframeobj(F,'Fusyn');

if iscell(coeff)
N_coeff = size(coeff);
dim_coeff = length(coeff{1});
elseif ismatrix(coeff)
[dim_coeff,N_coeff] = size(coeff);
coeff = mat2cell(coeff,dim_coeff,ones(1,N_coeff));
else
error("The input of fusyn has to be a cell or an array.")
end


definput.flags.projections = {'no_proj', 'proj'};
definput.flags.operator = {'frameoper', 'square'};
[flags,~]=ltfatarghelper({},definput,varargin);
%do_proj = 1;
% Apply the projection, i.e
% $ T_W f_i = sum \limits_i w_i \pi_{W_i} f_i


if ~strcmp(F.type, 'fusion')
error("Function \'fusyn\' only works for fusion frames");
end
L = size(coeff, 1);
F = comp_checkfudim(F, L);

if isnan(F.cdim)
error('Local frames have to have the same dimension for the synthesis.');
elseif F.cdim ~= dim_coeff
error('Dimension of fusion frame and coefficeints do not fit.')
end

if F.Nframes ~= N_coeff
error("Number of Frames in Fusion Frame and coefficient do not match.")
end


for ii = 1:length(coeff)
if flags.do_proj
fff = coeff{ii}; % Only for debugging: Seperation
ddd = comp_fuana(F,fff,'single',ii);
if flags.do_square
ddd = (F.w(ii)).^2*ddd;
end
% $= w_i \pi_{W_i} f_i$
else
% $= w_i f_i $
ddd = F.w(ii).*coeff{ii};
if flags.do_frameoper
ddd = {F.w(ii).*ddd};
end
end

if ii ~= 1
if length(coeff{ii}) == lll
f = f{1} + ddd{1};%this is not slower than the cellfun
if ~iscell(f)
f={f};
end
else
error('Dimensions do not match!')
end
else
lll = length(coeff{ii});
f = ddd;
end
end
4 changes: 4 additions & 0 deletions frames/frameaccel.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
end;
F=frame('fusion',F.w,accel_frames{:});
F.L=L;
F = comp_checkfudim(F, L);
F.fuana = comp_fuana(F, eye(L));
F.fusyn = comp_fusyn(F, eye(L));
F.localdual = comp_fudual(F, eye(L));
return;
end;

Expand Down

0 comments on commit 8d97f53

Please sign in to comment.