% Blind Calibration
% code written by Laura Balzano at UCLA for use by Varsha Bhambhani at Utah
% (c) University of California
% no part of this can be used for proprietary purposes!!!


%create lowpass frequency subspace
r=1;
n=4;
I=eye(n);
U=dct(I);
U(r+1:n,:)=0;
P=idct(U);

%the signals x lie in that subspace
x = P*rand(4,256);


% y are the observed measurements, which have
% a gain and offset factor difference from x
y = [];
alpha = [.2 .28 .458 .53]';
beta = [9 6 13 16]';
for j=1:4
    %Note the form of the calibration equation here
    y = [y; (x(j,:)-beta(j))./alpha(j)];
end
my = mean(y,2);

%build the C matrix
C = [];
for k=1:256
    C = [C ; (I-P)*diag(y(:,k)-my)];
end

[u,s,v]=svd(C,0);

%estimate for alpha (normalized)
v(:,n)/v(1,n)
%truth (normalized)
alpha/alpha(1)