function [Hn,fn,Ncp]=channel_model(Tsamp,N,fp,cp_coeff)
%  [Hn,fn,Ncp]=channel_model(Tsamp,N,fp,cp_coeff)
%%% Channel model - single pole %%%
% inputs
%   Tsamp - sample time
%   N - number of tones
%   fp - pole frequency
%   cp_coeff - percentage of energy covered with choped pulse response
% outputs
%   Hn - frequency response at each tone
%   fn - frequency of each tone
%   Ncp - cyclic-prefix length for pulse response for sample duration Tsamp

% Define single-pole channel frequency response
fsamp=1/Tsamp;
df=fsamp/N;
fn=-fsamp/2+df:df:fsamp/2;
Hn=fp./(fp+j*fn);
plot(fn,20*log10(abs(Hn)));

% impulse response
t=0:Tsamp:100*1/fp;
h=exp(-t*2*pi*fp);
p=[1-h(1) -h(2:end)+h(1:end-1)];

% determine necessary cp length
Ep=norm(p)^2;
Ep_vec=cumsum(p.^2);
Ncp=min(find(Ep_vec>=cp_coeff*Ep))-1

% stem(p);