www.gusucode.com > OFDM_16QAM系统仿真源码程序 > OFDM_16QAM系统仿真源码程序/code/main.m
clear all; clc; % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % IEEE 802.11a based OFDM PHY program by You Li 2006.10.12 % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %%% Program parameters are as following %%%% % Working frequency: fc = 5.2GHz % Bit rate: 24Mbps % Number of data subcarriers: Nsd = 48 % Number of pilot subcarriers: Nsp = 4 % Number of total subcarriers: Nst = 52 % Subcarrier frequency spacing: fs = 0.3125MHz ( = 20MHz/64) % Total bandwidth: ft = fs * Nst = 52 * 0.3125MHz = 16.25MHz % IFFT/FFT period: T_FFT = 1/fs =1/0.3125M = 3.2us % Guard interval: T_GI = T_FFT/4 = 3.2us/4 = 0.8us % OFDM symbol period: T_sym = T_FFT + T_GI = 3.2+0.8 = 4us % Coding: Convolutional code with coding rate R = 1/2 % Modulation: 16-QAM % Coded bits per subcarrier: N_BPSC = 4; % Coded bits per OFDM symbol: N_CBPS = 4 * 48 = 192 % Data bits per OFDM symbol: N_DBPS = N_CBPS * R = 192 * 1/2 = 96 % IFFT/FFT sampling point: 64, over sampling % Sampling rate: f_s = 1/(T_FFT/64) = 1/(0.05us) = 20Msps diary IEEE802.11a_OFDM_PHY.txt rand('state',sum(100*clock));%? N_DBPS = 96; N_SPF = input('Please enter the OFDM symbol number of each frame:\n'); % Number of OFDM symbols per fram frame_num = input('Please enter the number of frames: \n'); N_DBPF = N_DBPS * N_SPF - 6; % Data bits per frame,minus the 6 tail bits to return the convolutional encoder to the "zero state" fprintf('\nFrame size is %d OFDM symbols, and %d bits\n ',N_SPF, N_DBPF); T_sym = 4 * 1e6; % OFDM symbol period is 4us fc = 5.2e9; % Carrier frequency 5.2GHz v = 2.7e3/3600; % Vehicle speeed, 2.7km/h f_max = v/3e8*fc; % Maximum Dopper frequency, 13Hz T_start = rand(1) * 10^(-6); % A random starting time for simulation channel_option = 1; channel_response = channel_model(channel_option,f_max,frame_num,T_sym,T_start); % Channel response of multipath Rayleigh fading channel during the simulation % Assuming the channel response is invariant during one frame pilot_sym = pilot_generator(128); % Generate the pilot symbols, all in BPSK modulation pilot_syms=pilot_sym'; pilot_syms=pilot_syms(:)'; for snr = 20:20 nframe = 0; nerror = 0; while nframe < frame_num nframe %====================== % Transmitter %====================== info_bits = round(rand(1, N_DBPF)); % Generate the information bites randomly tail = zeros(1,6); % Tail bits for convolutional encoder info_bits = [info_bits tail]; % Append the tail bits to the infomation bits trl = poly2trellis(7,[133 171]); % Trellis structure of convolutional encoder, % Constraint length K = 7,generator polynomial in octal g0 = 133, g1 = 171 code_bits = convenc(info_bits, trl); % Convolutional encoder,rate R = 1/2 TX = tx_16qam_mod(code_bits); % 16-QAM modulation figure(1) a=real(TX); b=imag(TX); plot(a,b,'bx') pilot_num = 1; % The start number of the cyclic pilot symbols tx = tx_fre_to_time(TX,N_SPF,pilot_syms,pilot_num); % Serial to parallel,Add pilot symbols, IFFT ( Oversampling),Add cyclic prefix %====================== % Channel %====================== temp_channel = channel_response(:,nframe+1).'; % Channel response at the current frame ry = channel_multipath(tx,temp_channel); % Multi-path channel ry = awgn(ry,snr); % Add addictive white gaussian noise %====================== % Receiver %====================== [RY,R_pilot] = ry_time_to_fre(ry,N_SPF,temp_channel); % Recover the time signal to frequency symbols of each subcarrier and Channel Equalization figure(2) a=real(RY); b=imag(RY); plot(a,b,'bx') axis([-2 2 -2 2]); hold on Rcode_bits = ry_16qam_demod(RY); % Demodulate the received symbols dec_bits = ry_sovadec(Rcode_bits, trl, N_DBPF,N_DBPF); % Soft output viterbi decoding, out = ln( p(info_bits(i)=1)/p(info_bits(i)=0)); %====================== % Error detection %====================== for i = 1:N_DBPF if dec_bits(i) >= 0 hard_det(i) = 1; % hard_det refers to the hard decision else hard_det(i) = 0; end if hard_det(i) ~= info_bits(i) nerror = nerror+1; end end nframe = nframe + 1; end BER = nerror/(frame_num * N_DBPF); fprintf('\nSNR is %1.2f dB, BER is %e\n ',snr,BER); end