function y=model(beta,x)
%------------------- LineShapeKin MODEL -----------------------------
%-- version 3.0 
%
% 3/17/08
% Written by Evgenii Kovrigin, Medical College of Wisconsin
%
%  This function calculates spectral intensities for composite X data set at every frequency point.
%  This function is called for least squares fitting.
%
%  NOTES:
%    - optimization for speed: you may arrange to run rate_matrix only once
%    per spectrum

global B_vector X_columns

[N,M]=size(x);   

spectra=[];


for i=1:N
  
  % build a rate matrix for the particular X-vector row
  [p, K, R2_vector, v_vector]=rate_matrix(beta,x(i,:));

  current_frequency = x(i,X_columns.Xtotal); 

  spectra=[ spectra; spectrum(current_frequency, K, R2_vector, v_vector, p) ];

end


%-- scale entire array of spectral intensities by adjustable scaling factor
y=spectra*beta(B_vector.scale_factor);
