RF Ofdm
RF Ofdm
close all
clc
%% simulation parameters
%modulation method: BPSK, QPSK, SPSK, 16QAM, 32QAM, 64QAM
mod_method = 'QPSK';
% IFFT/FFT size
n_fft = 64;
%% symbol modulation
%BPSK
if mod_order == 1
mod_ind = 2^(mod_order-1);
n = 0:pi/mod_ind:2*pi-pi/mod_ind;
in_phase = cos(n);
quadrature = sin(n);
symbol_book = (in_phase + quadrature*1i)';
end
%32QAM modulation
%generates 6x6 constellation and removes corners
if mod_order == 5
mod_ind = 6;
in_phase = repmat(linspace(-1, 1, mod_ind), mod_ind, 1);
quadrature = repmat(linspace(-1, 1, mod_ind)', 1, mod_ind);
symbol_book = in_phase(:) + quadrature(:)*1i;
symbol_book = symbol_book([2:5 7:30 32:35]);
end
%add AWGN
%calculate data power
data_pwr = mean(abs(x_s.^2));
%measure SNR
snr_meas = 10*log10(mean(abs(x_s.^2))/mean(abs(noise.^2)));
%% estimate channel
if n_taps > 1
switch(ch_est_method)
case 'none'
case 'LS'
G = X_hat_blocks(:,1)./X_blocks(:,1);
X_hat_blocks = X_hat_blocks./repmat(G,1,size(X_hat_blocks,2));
end
end
%% symbol demodulation
%remove fft padding
X_hat = X_hat_blocks(:);
X_hat = X_hat(1:end-fft_rem);
%% recover image
rec_im = reshape(rec_im_bin,8, numel(rec_im_bin)/8);
rec_im = uint8(bin2dec(rec_im'));
rec_im = reshape(rec_im,size(im));
%% generate plots
%transmit constellation
subplot(2,2,1);
plot(X, 'x', 'linewidth', 2, 'markersize', 10);
xlim([-2 2]);
ylim([-2 2]);
xlabel('In Phase');
ylabel('Quadrature');
if n_taps > 1
title(sprintf('Transmit Constellation Diagram\n\\rm%s Modulation\nMultipath
Channel Taps: %d', mod_method, n_taps));
else
title(sprintf('Transmit Constellation Diagram\n\\rm%s Modulation',
mod_method));
end
grid on;
%recovered constellation
subplot(2,2,2);
plot(X_hat(1:500:end),'x','markersize',3);
xlim([-2 2]);
ylim([-2 2]);
xlabel('In Phase');
ylabel('Quadrature');
if n_taps > 1
title(sprintf('Receiving Constellation diagram\n\\rmMeasured SNR: %.2f
db\nChannel Estimation: %s', snr_meas, ch_est_method));
else
title(sprintf('Receiving Constellation diagram\n\\rmMeasured SNR: %.2f dB',
snr_meas));
end
grid on;
%original image
subplot(2,2,3);
imshow(im);
title('\bfTransmit Image');
%recovered image
subplot(2,2,4);
imshow(rec_im);
title(sprintf('\\bfReceived Image\n\\rmBER: %.2g', ber));
%position figure
%set(gcf,'Position',[680 287 698 691]);
%save figure
if save_file
print(sprintf('Plots/%s_%.0ffft_%.0fcpe_%0fdB_%.0ftaps_%s',mod_method, n_fft,
n_cpe, snr, n_taps, ch_est_method), '-dmeta');
end