function g = rcfiltgaincompat(block)
%RCFILTGAINCOMPAT Backwards compatible raised cosine filter gain
%
%   This function is intended to be used by the raised cosine filter
%   upgrade code only. This function returns a gain value that ensures the
%   upgraded blocks provide the same filter coefficients. Do not use this
%   function for regular use of the blocks. 

%   Copyright 2013 The MathWorks, Inc.

filtType = get_param(block, 'filtType');
filtSpanStr = get_param(block, 'filtSpan');
try
  val = evalin('base', filtSpanStr);
catch
  try
    val = evalin('caller', filtSpanStr);
  catch e
    rethrow(e)
  end
end
filtSpan = val;

NStr = get_param(block, 'N');
try
  val = evalin('base', NStr);
catch
  try
    val = evalin('caller', NStr);
  catch e
    rethrow(e)
  end
end
N = val;

RStr = get_param(block, 'R');
try
  val = evalin('base', RStr);
catch
  try
    val = evalin('caller', RStr);
  catch e
    rethrow(e)
  end
end
R = val;

switch filtType
  case 'Normal'
    b = rcosdesign(R, filtSpan, N, 'normal');
    g = 1 / max(b);
  case 'Square root'
    b = rcosdesign(R, filtSpan, N, 'sqrt');
    g = 1 / max(b) * ((-1/(pi*N)*(pi*(R-1)-4*R))) * sqrt(N);
end
end
