%------------------- LineshapeKin Simulation -----------------------------
%-- version 4.0 
%
% 5/8/09
% Written by Evgenii Kovrigin
% Medical College of Wisconsin
%
% 
function y=Spectra(Model, w_range, Rtotal, LRratio)
%  This function calculates spectra for the titration series


%% Preallocate memory for the spectrum
spectral_points=length(w_range);   
y=zeros(spectral_points,1);


%% compute model-dependent vectors and matrices
%[p, K, R2_vector, v_vector, p_other, rcCPMG]=model_matrices(Model, Rtotal, LRratio);
[p, K, R2_vector, v_vector, p_other]=model_matrices(Model, Rtotal, LRratio);

%% Build diagonal matrices of R2 and w0
R2=eye(Model.species);
v0=eye(Model.species);
for i=1:Model.species
  R2(i,i)=R2_vector(i);
  v0(i,i)=v_vector(i);
end
% construct composite
M1=R2-K-(sqrt(-1)*v0);



%% Compute spectrum
for counter=1:spectral_points
      
      current_frequency = w_range(counter);
            
      % Calculate second matrix  
      M2=current_frequency *sqrt(-1)*eye(Model.species);
      
      % Solve for intensity
      y(counter)=real(sum(inv(M1+M2)*p'));
      
      
end


