以下是802.11a OFDM MATLAB仿真代码:
```matlab
% 802.11a OFDM Simulation
% Author: Jiahao Hu
% Date: 2018/11/19
clear;clc;
%% Parameters
% Basic parameters
Fs = 20e6; % Sampling frequency (Hz)
Fc = 5.18e9; % Carrier frequency (Hz)
Ts = 1/Fs; % Sampling period (s)
T = 4e-6; % OFDM symbol period (s)
N = 64; % Number of subcarriers
M = 4; % Modulation order
L = 16; % Cyclic prefix length
SNR = 20; % Signal-to-noise ratio (dB)
% Derived parameters
Ncp = L/N*T; % Cyclic prefix duration (s)
df = Fs/N; % Subcarrier spacing (Hz)
f = (-N/2:N/2-1)*df; % Subcarrier frequencies (Hz)
Tsymb = T + Ncp; % OFDM symbol duration (s)
Ndata = 48; % Number of data subcarriers
Ng = N - Ndata; % Number of guard subcarriers
NFFT = N; % FFT size
Npilot = 4; % Number of pilot subcarriers
Nsym = 100; % Number of OFDM symbols
%% Transmitter
% Generate data
data = randi([0 M-1], Ndata, Nsym);
% Generate pilots
pilot = ones(Npilot, Nsym);
pilot(2,:) = -1;
pilot(3,:) = 1;
pilot(4,:) = -1;
% Generate zeros for guard subcarriers
guard = zeros(Ng, Nsym);
% Combine data, pilots and guard subcarriers
X = [guard; pilot; data; pilot; guard];
% Perform IFFT
x = ifft(X, NFFT);
% Add cyclic prefix
xc = [x(end-L+1:end,:); x];
% Serial-to-parallel conversion
xsp = reshape(xc, NFFT+L, []);
% Generate preamble
preamble = [1; 1; 1; 1; 1; 1; 1; -1; 1; -1; 1; -1; -1; 1; -1; -1];
preamble = repmat(preamble, Nsym, 1);
% Combine preamble and data
xsp = [preamble, xsp];
% Parallel-to-serial conversion
xser = reshape(xsp, [], 1);
% Upsample
xups = upsample(xser, Fs*T);
% Modulate
xmod = qammod(xups, M);
% Pass through AWGN channel
n = 1/sqrt(2)*(randn(size(xmod)) + 1i*randn(size(xmod))); % Complex Gaussian noise
snr = 10^(SNR/10);
power_xmod = sum(abs(xmod).^2)/length(xmod);
power_n = sum(abs(n).^2)/length(n);
scale_factor = sqrt(power_xmod/(power_n*snr));
xmod_noise = xmod + scale_factor*n;
% Demodulate
xdemod = qamdemod(xmod_noise, M);
% Downsample
xdn = downsample(xdemod, Fs*T);
% Receiver
% Serial-to-parallel conversion
xsp_rx = reshape(xdn, NFFT+L, []);
% Remove cyclic prefix
xcp_rx = xsp_rx(L+1:end,:);
% Perform FFT
X_rx = fft(xcp_rx, NFFT);
% Remove guard and pilot subcarriers
data_rx = X_rx(Ng+1:Ng+Ndata,:);
% Calculate BER
ber = sum(sum(data_rx ~= data)) / (Ndata*Nsym)
% Plot constellation diagram
figure;
plot(xmod_noise, 'o');
axis([-6 6 -6 6]);
title('Constellation diagram');
xlabel('I');
ylabel('Q');
grid on;
```
注意,需要使用MATLAB的Communications Toolbox。