%**********************************************************
%  This Matlab mfile computes the MMSE linear relation 
%  between two vectors X & Y
% 
%  AUTHOR: Santhanam, Balu
%  DATE  : 11/02/99
%  SYNOPSIS: [m_opt,c_opt,rho_XY,MMSE] = lin_reg(X,Y)
%  m_opt  : Optimal estimate of the slope
%  c_opt  : Optimal estimate of the intercept
%  rho_XY : Correlation Coefficient
%  MMSE   : Minimum Mean Square Error (dB)
%**********************************************************
function [m_opt,c_opt,rho_XY,MMSE] = lin_reg(X,Y)
% Compute correlation coefficient 
rho_XY = cor_coeff(X,Y); 
sig_X = std(X); sig_Y = std(Y); 
%  Optimal estimate of the slope 
m_opt = rho_XY*sig_Y/sig_X;
mu_Y = mean(Y); mu_X = mean(X);
%  Optimal estimate of the intercept  
c_opt = mu_Y - m_opt*mu_X; 
%  Minimum Mean Square Error
MMSE = 10*log10(sig_Y^2*(1 - rho_XY^2));
%*********************************************************
