无线通信——基于MATLAB实现OFDM系统(信道估计与均衡),可以分享一下这篇文章的代码吗

无线通信——基于MATLAB实现OFDM系统(信道估计与均衡),可以分享一下这篇文章的代码吗

我能够提供一个基于LS信道估计的OFDM通信系统的MATLAB代码示例:

%% OFDM-LMS Channel Estimation example with simulated 'mobile' channel fading % (c) 2006-2015 Ron Shalom ron.shalom@matlab.co.il % % This is an example of the OFDM-based wireless transmitter/receiver % system using channel estimation with the LS algorithm. The system model % includes channel fading effects introduced by a moving transmitter. % The programs may be used in wireless system engineering courses for % educational purposes. % % The program (OFDMSystemChannelEstimate.m) performs the following % operations: % 1. Generation of random symbol sequence % 2. Modulation using 16-QAM constellation % 3. Conversion to parallel transmission through IFFT % 4. Addition of cyclic prefix % 5. Multiplication by an appropriate channel transfer function % 6. Addition of white Gaussian noise % 7. Removal of cyclic prefix % 8. Conversion to serial transmission through FFT % 9. Demodulation % % The channel estimation block estimates the channel coefficients using % the LS algorithm from the known data at the beginning of each frame and % calculates the channel impulse response (CIR) for frequency-domain equalization % both for the current frame and a number of previous ones. % % The estimated channel information from each frame is collected and used % to calculate time-domain equalizer coefficients which are used to % correct the timing effects resulting from unknown delay spread in the channel. % % Note that the operations assumed here are the minimum necessary for the % generation of realistic example data - in practical set-ups more options % and alternative solutions should be considered. % % Various settings of the programs are configurable by choosing options in % the provided 'configuration' section. % % The programs require the following MATLAB toolboxes: % - Signal Processing Toolbox % - Communications Toolbox % % To run the simulation enter the command 'OFDMSystemChannelEstimate' in the % command window. The graphs show the frequency-domain estimates of the % channel transfer function and the resulting BER (bit error rate) for the % equalized transmissions. % % (The program was tested with MATLAB R2014a (32 bit) and 2014b (64 bit)) %

%% --- CONFIGURATION ---

% Basic transmit parameters numCarriers = 64; % Number of evenly spaced sub-carriers in the OFDM signal numData = 48; % Number of sub-carriers that carry data symbols numPilot = 4; % Number of sub-carriers reserved for pilot symbols pilotSpacing = 8; % Number of sub-carriers between successive pilot symbols lag = 25; % For the equalizer, length of the estimated channel impulse response fftSize = 64; % Points in FFT (equals number of sub-carriers for each OFDM frame in this example)

% Channel characteristics numFrames = 5; % Number of OFDM frames sent before switching off transmitter m = 0; % Index for 'delay line' representing path delays in simulated mobile channel v = 10; % Velocity of simulated transmitter (m/s) delaySpread = 100e-9; % RMS delay spread of the channel (in seconds) SNR = 14; % Signal to noise ratio for AWGN (in dB)

% --- END OF CONFIGURATION ---

%% --- PROGRAM STARTS HERE ---

% The simulates a mobile radio environment where the transmitter is in motion relative to the receiver. % The transmitter position at each instant is given by the formula: % x = vt where v is the velocity and t is the time % The channel response is generated by a tap-delay line model where % each tap corresponds to a unique path followed by a reflected component of the signal. % Each tap has an amplitude and a time delay corresponding to the actual effect of the path on a transmitted signal.

% Set up IFFT object ifftObj = dsp.IFFT('FFTLength',fftSize);

% Set up FFT object fftObj = dsp.FFT('FFTLength',fftSize);

% Create a QAM Modulator qamModulator = comm.RectangularQAMModulator('ModulationOrder',16,'BitInput',true,'NormalizationMethod','Average power');

% Create a QAM Demodulator qamDemodulator = comm.RectangularQAMDemodulator('ModulationOrder',16,'BitOutput',true,'NormalizationMethod','Average power');

% Set up the channel object. % The channel is generated using a number of paths - each tap of the channel has the properties: % Tau: A unique delay time for the path (in seconds) % KFactor: The KFactor is a value giving the ratio of energy added by path k to the total energy at the receiver % AoD: Angle of departure represents the angle the signal arrives at the receiver position % AoA: Angle of arrival represents the angle the signal arrives at the transmitter. % distance: The distance from the transmitter to the receiver % Additional parameters may be set up as well

Ts = 1/1e6; % Sample time interval for channel coefficients maxDelay = 64*Ts; % Maximum delay for multipath components

% Set up channel taps % this example will use only direct and first reflected paths for channel % simulation. The signal is transmitted from 50 meters distance.

taps = [ struct('Tau', 0, 'KFactor', 0.9, 'AoD', 0, 'AoA', 0, 'distance', 50); struct('Tau', 3e-7, 'KFactor', 0.1, 'AoD', 10, 'AoA', -10, 'distance', 50*1.4) ];

% Set up channel object fadingChannel = comm.RayleighChannel('SampleRate',1/Ts, 'MaximumDopplerShift', 10, 'DopplerSpectrum', taps, ... 'PathGainsOutputPort', true, 'NormalizePathGains', true);

% Number of samples for channel estimate numEstimate = numCarriers + lag - 1;

% Set up training sequence - uses 4 pilot subcarriers indexed at positions % spaced by pilotSpacing trainingSeq = ones(numCarriers, 1); idx = (numPilot:pilotSpacing:numCarriers); idx(idx > numCarriers) = []; trainingSeq(idx) = 1i;

% Number of output bits (this is for the final demodulation comparison) numBits = numData16numFrames;

% Initialize BER object errorRate = comm.ErrorRate;

%% Simulate the OFDM system, with channel estimation block

% Preallocate arrays for holding channel estimates channelFreqEst = zeros(numEstimate,numFrames,'single');

% Predefine array for holding the received data rxSig = zeros(numFrames * (fftSize + ceil(lag/2)), 1);

% Create a time delay interferer object that adds multiple independent delay interferers % into the received signal path. This simulates signal propagation through % a channel with multipaths. Set up the object so that each path has random % amplitude, delay, and phase offset. tdiObj = comm.TimeDelayInterferer('SampleRate',1/Ts, 'DelayType', 'Variable', ... 'PathGainsOutputPort', true, ... 'MaximumDelay', maxDelay, ... 'PathGains', [0.9 0.09], ... 'Distances', [50 50*1.4], ... 'Outputs',[1 2],... 'SeedSource','Property','Seed',1234);

% Use maximum-likelihood estimation to adjust the timing samples % for the channel taps during each iteration in each frame. % It will use the estimated FFT / IFFT sample rate differential to insure that timing % estimates are consistent with calculated channel coefficients.

% Set the pilot signals for the 4 pilot sub-carriers. pilotSignals = ones(numCarriers, numPilot, numFrames); pilotIdx = 1:pilotSpacing:numCarriers;

for idx =1:numFrames

% Generate random data
data = randi([0 1],numData,1);

% QAM modulation
dataMod = qamModulator(data);

% Allocate the IFFT inputs, and insert the data and pilots with the correct spacing.
ifftIn = zeros(numCarriers,1);
ifftIn([1:pilotSpacing:numCarriers]) = pilotSignals(:,1,idx);
ifftIn(pilotIdx) = pilotSignals(:,2,idx);
ifftIn(kron([1; 1i],[-(numData/2-1/2):(numData/2-1/2)]+numCarriers/2+1)) = reshape(dataMod,numData,[]);

% IFFT
ifftOut = ifftObj(ifftIn);

% Add cyclic prefix
ifftOut = [ifftOut(numCarriers-fftSize+1:numCarriers,:); ifftOut];
ifftOut = ifftOut(:);

% Pass signal through Rayleigh channel
[fadingChan,pathGains] = fadingChannel(ifftOut);
expectedPower = mean(abs(ifftOut).^2);
pathGains = pathGains/sqrt(expectedPower);
if isempty(pathGains); pathGains = 1; end

% Time-delay interferer
rxSig(:,idx) = tdiObj(fadingChan);

% Calculate noise power for required SNR and transmit power
txPower = mean(abs(ifftOut).^2);
noisePower = txPower/(10^(SNR/10));

% Add white Gaussian noise
noisySig = rxSig(:,idx) + sqrt(noisePower)*randn(size(rxSig(:,idx)));

% Receiver end processing, taking into account complex channel gain
ifftIn = reshape(noisySig,fftSize+lag-1,[]);

% Remove cyclic prefix
ifftIn = ifftIn((fftSize-numCarriers+1):end,:);

% FFT
fftOut = fftObj(ifftIn);

% Frequency Domain Equalization using LS Estimation

% Extract pilot subcarriers and estimated channel at pilots
pilotFreqs = fftOut(numCarriers/2+1 + ([1:numPilot] - floor(numPilot/2))',:);
estChannelAtPilots = pilotFreq