Commit cbef5b80 authored by Kevin Kershaw's avatar Kevin Kershaw

Initial commit for the project

parents
% Copyright (c) 2017, Cable Television Laboratories Inc.
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice, this
%    list of conditions and the following disclaimer.
% 2. Redistributions in binary form must reproduce the above copyright notice,
%    this list of conditions and the following disclaimer in the documentation
%    and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
% ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
% WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
% ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
% (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%
% The views and conclusions contained in the software and documentation are those
% of the authors and should not be interpreted as representing official policies,
% either expressed or implied, of the FreeBSD Project.
%
% Implementation of CP-less OFDM transmission and Freq. Domain EQ.
% based on T.Williams proposal
%
% Author: Greg White 2/2/2017
% Simulation of idealized tx-rx chain for OFDM with no cyclic prefix
%% Configuration Values
% system configuration
Tsymbol=20e-6; %20us symbol time
fftsize=4096;
T_sub=Tsymbol/fftsize; % sub-symbol time
numsymbols=102; % how many sequential OFDM symbols to simulate, note: the first and last will be discarded
QAM=1024; % Modulation Order
% channel configuration: the model here is an AWGN channel with a single echo
snr_db=50; % AWGN SNR
echo_db=-6; % echo amplitude relative to the direct signal amplitude
echo_t=1e-6; % echo time delay (in seconds)
% calcuated values
N=sqrt(QAM); % number of unique symbol values in each dimension
E_symbol=2*mean((2*((1:(N/2)))-1).^2); % average subcarrier-symbol energy
E_noise=E_symbol*10^(-snr_db/10); % average noise energy per subcarrier-symbol
%% Generate transmitted signal
Xr=2*round(rand(fftsize,numsymbols)*N+0.5)-N-1; % generate random symbols (real component)
Xi=2*round(rand(fftsize,numsymbols)*N+0.5)-N-1; % generate random symbols (imag component)
X=Xr+j*Xi; % combine real+imag
x=sqrt(fftsize)*ifft(X); % Perform IFFT of each symbol to convert to time domain
x=x(:); % reorganize x into a 1-dimensional time sequence
%% Generate channel
echo_m=10^(echo_db/20); % convert echo_db into linear quantity
T_echo=round(echo_t/T_sub); % convert echo delay into a sub-symbol index
%channel impulse response
channel=zeros(T_echo+1,1); % start with all zeros
channel(1)=1; % add a 1 at the zero-lag tap
channel(end)=echo_m; % add the echo at the appropriate tap
% AWGN noise sequence
noise=sqrt(E_noise/2)*(randn(length(x),1)+j*randn(length(x),1));
%% calculate received signal
y=conv(x,channel); % convolve transmitted signal (x) with the channel impulse response
y=y(1:length(x))+noise; % trim the resulting convolution back down to the original length and add the noise
%% Show what the result would be if no equalization was done
Y=fft(reshape(y,fftsize,numsymbols))/sqrt(fftsize); % do the FFT to convert to freq. domain
figure(1);
plot(real(Y),imag(Y),'.'); % plot the constellation
axis square; % plot formatting
axis(max(abs(axis))*[-1 1 -1 1]); % plot formatting
E_error=mean(mean(abs(Y-X).^2)); % calculate the average subcarrier-symbol error energy
MER_noEQ = 10*log10(E_symbol / E_error); % calculate the MER with no EQ
%% Frequency Domain Equalization
%
% This is an omniscient FDE, i.e. it knows precisely what the channel response was
% pad the channel impulse response out to equal 2x the OFDM FFT size
% note: this code will break if echo_t is more than 2x the OFDM FFT size
channel_resample=zeros(fftsize*2,1);
channel_resample(1:length(channel))=channel;
CHANNEL_RES=fft(channel_resample); % and convert the channel response into the freq domain
%generate overlapping fft blocks that are 2x the OFDM FFT size
z_temp=reshape(y,fftsize,numsymbols);
z=[z_temp(fftsize/2+(1:fftsize/2),1:end-2);
z_temp(:,2:end-1);
z_temp((1:fftsize/2),3:end)];
Z=fft(z)/sqrt(2*fftsize); % convert to freq domain
Z= Z ./ repmat(CHANNEL_RES,1,numsymbols-2); % equalize
zz=ifft(Z)*sqrt(2*fftsize); % convert back to time domain
zz=zz(fftsize/2+(1:fftsize),:); % discard overlaps
%% OFDM receiver
ZZ=fft(zz)/sqrt(fftsize); %convert equalized time sequence to freq domain
%% Plot the resulting constellation
figure(2)
plot(real(ZZ),imag(ZZ),'.');
axis square
%% Display some statistics
% calculate the MER for each OFDM symbol and then give summary stats
E_error=mean(abs(ZZ-X(:,2:end-1)).^2);
MER = 10*log10(E_symbol ./ E_error);
disp('MER per OFDM symbol (in dB)');
disp({'Min','Mean','Max','Std'});
disp([min(MER) mean(MER) max(MER) std(MER)]);
This diff is collapsed.
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment