%bfdriver.m : Driver for nonperiodic sampling 
% on the group G = Z_L = {0, ..., L-1} with addition modulo L.
% Explanation of variables: 
% L = number elements in G
% h: h(k) is the divisor of L which  generates the subgroup H_k, 
%    i.e., H_k = {0,h(k),2h(k),...,L-h(k)}
% x: vector with shifts. M_k = x(k) + H_k
% eta: eta(k) corresponds to eta_{k+1} in the theorem.
% filt: characteristic function of spectrum

%Input parameters:
L=2520; % Length of group G.
filt = zeros(1,L); %initialization. DO NOT CHANGE!
filt(1:72) = 1; filt(1225:1275)=1; %Define spectrum 

h=[280,60,35]; %Specify generators of subgroups
x=[3,1,0]; % Specify shifts 
eta = [42,1224]/L; 
%End of input section 


N = max(size(h)); %number of subgroups
% Compute signal to be sampled and reconstructed
fhat = complex(rand(1,L),rand(1,L)); %generating random spectrum
fhat = fhat.*filt; %setting frequencies outside spectrum to zero
fexact = ifft(fhat); 
fexact = fexact/norm(fexact); %generating normalized signal

% Compute sampled values
f = zeros(1,L);
for k=1:N
 Hx = x(k)+[0:h(k):L-h(k)];
 f(1+Hx) = fexact(1+Hx); 
end

F = bfmethod(f,L,h,eta,x); %reconstruct signal

% Compute the l2 relative reconstruction error
relerr = norm(fexact-F)
%----------------------------------------

