function [chanMod] = channel(wifi_params,nTX,nRX)
% channel function for creating awgn or fading channel matrix
n_fft = wifi_params.mapping.n_fft;
% n_sf = wifi_params.mapping.n_sf;
% n_sf = wifi_params.coexistence.N_available_symbols;
df = wifi_params.mapping.df;
Fs = n_fft*df;
H = zeros(n_fft,1,nTX,nRX);

Nsym = wifi_params.mapping.n_data_symbols_per_frame;

if strcmp(wifi_params.channel.type,'awgn')
    H = ones((n_fft+length(wifi_params.cprefix.indices)),1,nTX,nRX); % no fading - J146
    h = ones(1,1,nTX,nRX);
    Lch = [];
    Ntap = [];
else % fading
    % PowerdB = [0 -8 -17 -21 -25];
    powerdB = wifi_params.channel.powerdB;
    % Delay = [0 3 5 6 12]; % channel delay sample
    delayTime = wifi_params.channel.delayTime; % channel delay sample
    delay = unique(round(delayTime*Fs));
    powerlin = 10.^(powerdB/10);
    Ntap = length(powerdB); % channel tap number
    Lch = delay(end)+1;
    
    h = zeros(1,Lch,nTX,nRX);
    
    for i_tx = 1:nTX
        for i_rx = 1:nRX
            chanRand = (randn(1,Ntap)+1j*randn(1,Ntap)).*sqrt(powerlin/2);
            h_tmp = zeros(1,Lch);
            h_tmp(delay+1) = chanRand; % cir: channel impulse response
            
            H_tmp = fft([h_tmp, zeros(1,n_fft-Lch)]); % channel frequency response
            H_tmp = H_tmp.';
% %             if strcmp(wifi_params.channel.fading,'block')
%                 H_tmp = repmat(H_tmp,1,n_sf);
% %             end
            h(:,:,i_tx,i_rx) = h_tmp;
            H(:,:,i_tx,i_rx) = H_tmp;
            
        end
    end
end

 
% chanMod.H = repmat(H,1,Nsym); % only block fading 
chanMod.H = H; % only block fading 
chanMod.h = h;
chanMod.nTX = nTX;
chanMod.nRX = nRX;
chanMod.Lch = Lch;
chanMod.Ntap = Ntap;
end