|
| pilot_f (pilot_f==0) |
|
| pilot_f (setdiff(1:N_SC, SC_IND_DATA))=0 |
|
| fwrite (fileID, pilot_f, 'float') |
|
| fclose (fileID) |
|
| fwrite (fileID, pilot_t, 'float') |
|
| fwrite (fileID_data, tx_data_for_saving(:), 'uint8') |
|
| fclose (fileID_data) |
|
mod_fcn_16qam, tx_data | arrayfun () |
|
otherwise | fprintf ('Invalid MOD_ORDER(%d)! Must be in[2, 4, 16]\n', MOD_ORDER) |
|
end IFFT Reshape the symbol vector into two different spatial streams | length (tx_syms)/NUM_UE |
|
| tx_syms_mat (SC_IND_DATA,:,:) |
|
| ifft_in_mat_A (SC_IND_PILOTS, :) |
|
Add CP Insert the cyclic prefix | if (CP_LEN > 0) tx_cp |
|
2 | sqrt () |
|
| H_vec_float (1:2:end) |
|
| H_vec_float (2:2:end) |
|
| fwrite (fileID, H_vec_float, 'float') |
|
N_SC, NUM_UE, NUM_UE | zeros () |
|
| CSI_est (:, i,:) |
|
end | fprintf ("CSI_estimation error: %d/%d\n", sum(sum(sum(abs(CSI_est(SC_IND_DATA,:,:) -H_noisy(SC_IND_DATA,:,:))>0.5 *1e-1))), length(H_noisy(:))) |
|
| rx_vec_float (1:2:end) |
|
| rx_vec_float (2:2:end) |
|
| fwrite (fileID, rx_vec_float, 'float') |
|
| rx_syms_mat (i,:,:) |
|
| switch (MOD_ORDER) case 2 % BPSK rx_data |
|
| fprintf ("Uplink: correct data demodulation: %d/%d\n", sum(sum(sum(rx_data==tx_data_mat))), length(tx_data_mat(:))) |
|
show data of symbol and all users from subcarrier to | disp (squeeze(rx_data(1:6, 1,:))) |
|
Reshape to a vector | numel (tx_payload_mat)) |
|
pilot_t.', 1, NUM_UE | tx_payload_vec () |
|
Downlink data analysis | fprintf ("Downlink.....\n") |
|
end | fprintf ("CSI_estimation error: %d/%d\n", sum(sum(sum(abs(CSI_est(SC_IND_DATA,:,:) -H_from_file_float(SC_IND_DATA,:,:))>0.5 *1e-1))), length(H_from_file_float(:))) |
|
| precoder_from_file (i,:,:) |
|
| dl_rx_data_f (OFDM_START_OFFSET+i,:,:) |
|
| dl_rx_data_f (424+i,:,:) |
|
| dl_rx_data_saving_float (1:2:end) |
|
| dl_rx_data_saving_float (2:2:end) |
|
| fwrite (fileID, dl_rx_data_saving_float, 'float') |
|
| fprintf ("Downlink: correct data demodulation: %d/%d\n", sum(sum(sum(ue_rx_data==tx_data_dl_raw))), length(SC_IND_DATA) *NUM_UE *(N_SYMS-NUM_UE)) |
|
|
Parameters | MOD_ORDER = 16 |
|
| N_SC = 2048 |
|
| SC_IND_DATA = 425:1624 |
|
| OFDM_START_OFFSET = 424 |
|
| NUM_BS_ANT = 8 |
|
| NUM_UE = 8 |
|
| N_SYMS = 70 |
|
| N_OFDM_SYMS = (N_SYMS-NUM_UE)*NUM_UE |
|
| N_DATA_SYMS = N_OFDM_SYMS * length(SC_IND_DATA) |
|
used to generate new pilot files in time domain and frequency domain pilot in time | domain |
|
used to generate new data files original data(tx_data) for all users before modulation | CP_LEN = 0 |
|
| frmLen = 100 |
|
frame length Generate pilot if GENERATE_PILOT | pilot_f = randi(3,N_SC,1)-2 |
|
| pilot_t = ifft(pilot_f, N_SC) |
|
| fileID = fopen('../files/experiment/pilot_f_2048.bin','w') |
|
end Generate data if GENERATE_DATA | tx_data = randi(MOD_ORDER, 1, N_DATA_SYMS) - 1 |
|
| tx_data_for_saving = reshape(tx_data, length(SC_IND_DATA), N_OFDM_SYMS/NUM_UE, NUM_UE) |
|
| fileID_data = fopen(sprintf('../files/experiment/orig_data_2048_ant%d.bin',NUM_BS_ANT),'w') |
|
end Modulate data | modvec_bpsk = (1/sqrt(2)) .* [-1 1] |
|
| modvec_16qam = (1/sqrt(10)) .* [-3 -1 +3 +1] |
|
| getbit13 = @(x) (bitget(x,3) * 2 + bitget(x,1)) |
|
| getbit24 = @(x) (bitget(x,4) * 2 + bitget(x,2)) |
|
| mod_fcn_bpsk = @(x) complex(modvec_bpsk(1+x),0) |
|
| mod_fcn_qpsk = @(x) complex(modvec_bpsk(1+bitshift(x, -1)), modvec_bpsk(1+mod(x, 2))) |
|
| mod_fcn_16qam = @(x) complex(modvec_16qam(1+bitshift(x, -2)), modvec_16qam(1+mod(x,4))) |
|
switch MOD_ORDER case BPSK | tx_syms = arrayfun(mod_fcn_bpsk, tx_data) |
|
| return |
|
end IFFT Reshape the symbol vector into two different spatial streams | size |
|
Construct the IFFT input matrix | ifft_in_mat = zeros(NUM_BS_ANT, N_SC, N_OFDM_SYMS/NUM_BS_ANT) |
|
Insert the data and pilot | values |
|
Perform the IFFT | tx_payload_mat = ifft(ifft_in_mat, N_SC, 1) |
|
| H = repmat(H,1,1,N_SC) |
|
| noise = (randn(N_SC,NUM_UE, NUM_BS_ANT) + 1i*randn(N_SC, NUM_UE, NUM_BS_ANT))/sqrt(2)/100 |
|
| H_noisy = H + noise |
|
| H_vec = reshape(H_noisy, 1, numel(H_noisy)) |
|
| H_vec_float = zeros(1,size(H_vec,2)*2) |
|
| H_from_file = fread(fileID,[1,N_SC*NUM_UE*NUM_BS_ANT*2],'float') |
|
for | i |
|
end | pilot_all_ue = reshape(pilot_all_ue, N_SC,1,NUM_UE) |
|
| tx_mat_all = cat(2,pilot_all_ue,tx_payload_mat) |
|
| tx_mat = reshape(tx_mat_all,N_SC*N_SYMS,NUM_UE) |
|
Rx data | rx_mat_all = zeros(N_SC,N_SYMS,NUM_BS_ANT) |
|
| tx_mat_all_f = fft(tx_mat_all,N_SC,1) |
|
| rx_mat_all_f = zeros(N_SC,N_SYMS,NUM_BS_ANT) |
|
| rx_mat = tx_mat*H |
|
CSI estimation | CSI_est = zeros(N_SC,NUM_UE,NUM_BS_ANT) |
|
| pilot_est = zeros(N_SC,NUM_UE,NUM_BS_ANT) |
|
| rx_vec = reshape(rx_mat_all, 1, numel(rx_mat_all)) |
|
| rx_vec_float = zeros(1,size(rx_vec,2)*2) |
|
end | H_est = squeeze(CSI_est(1,:,:)) |
|
| rx_data_fft = fft(rx_mat_data,N_SC,1) |
|
| precoder_all = zeros(length(SC_IND_DATA),NUM_BS_ANT,NUM_UE) |
|
| rx_syms_mat = zeros(length(SC_IND_DATA),N_SYMS-NUM_UE,NUM_UE) |
|
| rx_mat_data = rx_mat_all(:,:,NUM_UE+1:end) |
|
size | __pad1__ |
|
| rx_syms = precoder * rx_data_fft |
|
| demod_fcn_bpsk = @(x) double(real(x)>0) |
|
| demod_fcn_qpsk = @(x) double(2*(real(x)>0) + 1*(imag(x)>0)) |
|
| demod_fcn_16qam = @(x) (8*(real(x)>0)) + (4*(abs(real(x))<0.6325)) + (2*(imag(x)>0)) + (1*(abs(imag(x))<0.6325)) |
|
case QPSK | rx_data = arrayfun(demod_fcn_qpsk, rx_syms_mat(:)) |
|
| tx_data_mat = reshape(tx_data,length(SC_IND_DATA),N_SYMS-NUM_UE,NUM_UE) |
|
| rx_data_from_file = fread(fileID,[1,N_SC*N_SYMS*NUM_BS_ANT*2],'float') |
|
| rx_data_from_file_float = rx_data_from_file(1:2:end)+1j*rx_data_from_file(2:2:end) |
|
| rx_pilot_from_file = rx_data_from_file_float(:,1:8,:) |
|
| H_from_file_float = H_from_file(1:2:end)+1j*H_from_file(2:2:end) |
|
Precoder calculation and precoding | precoder_from_file = zeros(N_SC,NUM_BS_ANT,NUM_UE) |
|
end original data before modulation | tx_data_dl_raw = reshape(tx_data,length(SC_IND_DATA),N_SYMS-NUM_UE, NUM_UE) |
|
original data after modulation | tx_data_dl = reshape(tx_syms,length(SC_IND_DATA),N_SYMS-NUM_UE, NUM_UE) |
|
| precoded_data = zeros(N_SC,NUM_BS_ANT,N_SYMS-NUM_UE) |
|
| dl_rx_data_f = zeros(N_SC,NUM_BS_ANT,N_SYMS-NUM_UE) |
|
end | ifft_data = ifft(precoded_data,N_SC,1) |
|
| dl_rx_data = ifft(dl_rx_data_f,N_SC,1) |
|
if GENERATE_DATA | dl_rx_data_saving = dl_rx_data(:).* N_SC |
|
| dl_rx_data_saving_float = zeros(1,length(dl_rx_data_saving)*2) |
|
end | dl_rx_data_fft_orig = fft(dl_rx_data,N_SC,1) |
|
| dl_rx_data_fft = zeros(length(SC_IND_DATA),NUM_UE,N_SYMS-NUM_UE) |
|
case QPSK | ue_rx_data = arrayfun(demod_fcn_qpsk, dl_rx_data_fft(:)) |
|