function run_pie()
%
% Function computes Ideal Equalizer penalty 
% written by Sudeep Bhoja, BigBear Networks, June 28, 2004
%
% Default Parameters:
% 47.1ps Gaussian Rise Time Tx
% Channel is [A1 A2] with A2/A1 = 1.5 and T spacing
% Reference Rx is 4th order Bessel Thompson, 7.5GHz 3dB BW
%
L = 16;

tx_pulse = gen_tx_pulse(47.1, L);

bitTime = 1/10.3125e9;
channel = complaint_channel(1.5, bitTime, L);

tp3 = conv(tx_pulse, channel);

% Reference Rx is 4th order Bessel Thompson, 7.5GHz 3dB BW
[Ba Aa] = besself(4, 2*pi*7.5*1.5255);
[B A] = bilinear(Ba, Aa, 10.3125*L);

pulse_response = filter(B,A, tp3);

pie_l = pie_metric(pulse_response, L, 1);
pie_d = pie_metric(pulse_response, L, 2);

disp(sprintf('PIE_L = %f (dBo). PIE_D = %f (dBo)', pie_l, pie_d));

return

function tx = gen_tx_pulse(riseTime, L)
%
% riseTime	 = 20-80% rise time for Gaussian pulse
% L              = Oversampling ratio 
% 				

	Ts = riseTime * 1E-12;
	BW = 0.1323 * 2.564 / (1.52 * Ts);

	bitTime = 1/10.3125e9;
	aa = 1/(2*pi*bitTime*BW) * sqrt(log(2));
	tt = [-5*bitTime:bitTime/L:5*bitTime];
	hh = exp(-tt.^2/(2*aa^2*bitTime^2));
	gg = hh ./ sum(hh);	

	rect_pulse = [zeros(1,2*L) ones(1,L) zeros(1,L)];

	tx = conv(rect_pulse, gg);

return


function chan_out = complaint_channel(A_ratio, time_spacing, L)
%
% A_ratio	= A1/A2
% L             = Oversampling ratio 
% 				

	A2 = 1 / (1+A_ratio);
	A1 = A_ratio / (1+A_ratio);
	bitTime = 1/10.3125e9;

	tt = floor(time_spacing / bitTime * L);
	disp(sprintf('Ratio = %f A2 = %1.2f A1 = %1.2f Spacing = %1.2f(ps)', A_ratio, A2, A1, tt / L * bitTime*1e12))

	chan_out = [A2 zeros(1,tt-1) A1];

return

