Hi here is the code for OFDM Function. By the way the finddelay is matlab function.
function y = func_ofdm_generate(qam_mode, ofdm_mode, GI, N_symbol)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch qam_mode
case 'qpsk'; M = 4; case '16qam'; M = 16; case '64qam'; M = 64;
end
switch ofdm_mode
case '2k'; N_fft = 2048*2; n = 1705;
case '4k'; N_fft = 2048*4; n = 3409;
case '8k'; N_fft = 2048*8; n = 6817;
end
scale = modnorm(qammod(0:M-1,M),'peakpow',1) ;
data = randi([0,M-1],1,N_symbol*n);
data_qam = scale * qammod(data,M);
x = reshape(data_qam,n,N_symbol);
y = [x((n-1)/2+1:end,
;zeros(N_fft-n,N_symbol);x(1
n-1)/2,
];
Y = ifft(y, N_fft);
Y1 = [Y(end-GI*N_fft+1:end,
;Y];
y = reshape(Y1,1,N_symbol*N_fft*(1+GI));
Thanks