Professional Documents
Culture Documents
Transmitter/Receiver Code Description Introduction To Digital Communication Receiver Design
Transmitter/Receiver Code Description Introduction To Digital Communication Receiver Design
we{23, 21, 1, 3}
Analog
upconversion
Carrier
specification
P(f)
Coding
Pulse
shaping
Transmitted
signal
Channel
Other FDM
Noise
users
1
Antenna
Analog
received
signal
Analog
conversion
to IF
Digital downconversion
to baseband
Pulse
matched
filter
Ts
Carrier
Input to the
synchronization
software
receiver
m
T
Downsampling
Timing
synchronization
Equalizer
Q(m)e{23, 21, 1, 3}
Decision
^
b
Decoding
Matlab Files
A brief description of each of the functions used in the complete system is provided here.
You can find all of the files in the /system code directory. For a more detailed description
of the inputs and outputs for each of these functions, you can using the help command at
the Matlab prompt (e.g. by typing help Tx).
Main Files
Listings at the end of this code description document.
main.m This script is merely an example which shows how to set up the system
parameters, run the transmitter, run the receiver, and calculate the bit-error-rate.
Tx.m This function contains the transmitter, and introduces the impairments (e.g.
the channel, imperfect receiver frontend, etc.)
Rx.m This function decodes the received signal, and outputs the message.
globalParams.m This function contains the parameters for the system (e.g. sampling period, IF frequency, marker sequence, etc.)
Subroutine Files
These files are from Telecommunication Breakdown.
letters2pam.m This function converts an ASCII text sequence into 4-PAM symbols. Used by Tx.m.
pam2letters.m This function converts a sequence of 4-PAM symbols into an
ASCII text string. Used by Rx.m.
quantalph.m This function is effectively a minimum Euclidean distance detector,
or decision device. It accepts soft PAM symbols, and quantizes the input to the
nearest PAM symbol. Used by Rx.m.
srrc.m This function generates the impulse response for the square-root raisedcosing pulse shape. Used by both Tx.m and Rx.m.
interpsinc.m The function performs sinc interpolation, and is used for the baudtiming and downsampling in the receiver. Used by Rx.m.
Calculate Intermediate Variables (lines 19-29) This part calculates intermediate variables which are used in the transmitter, including the upsampling/downsampling
ratios and the phase noise random process.
Generation of 4-PAM sequence (lines 30-32) This part encodes the ASCII test
message into 4-PAM signals (using letters2pam), and inserts the header and marker
sequences. The result is a serial stream of 4-PAM symbols stored in the variable
called s.
Pulse Shaping (lines 33-35) This part performs upsampling of the 4-PAM signal
and then filters the signal with the pulse shape obtained from srrc. The result is
stored in the variable x.
Analog Upconversion (lines 36-39) This part modulates the signal up to the
carrier frequency, and includes the effect of phase noise. The result is stored in x rf.
Channel (lines 40-42) This part convolves the upconverted signal with the channel, storing the result in the variable x2.
Noise (lines 43-47) This part adds the additive white Gaussian noise of specified
SNR.
Analog Conversion from RF to IF (lines 48-52) This part acts as the frontend
of the receiver, and performs analog conversion of the RF signal down to IF. While
the RF signal in reality would be analog, our computer simulation uses a digital
representation throughout; thus, the sampled-IF receiver is obtained from the RF
signal by simple downsampling. The result is the digital signal which gets passed
into Rx.m.
kT
kT
[k + 1] = [k] + x[k] x
+ [k] + x
+ [k]
M
M
!#
which is seen in lines 91-94. The Matlab variable tau stores the timing offset, tnow
stores the current position, and x sampled stores the downsampled signal after timing
recovery.
Correlation (lines 97-102) Always running, this part calculates the correlation of
the downsampled signal with the known header sequence.
Header Search (lines 39-41, 104-110) This part searches for the header, by
comparing the correlation value with a threshold.
Equalization with Adaptation via LMS (lines 111-124) This part performs
equalization of the signal, which includes adaptation of the equalizer coefficient during
training periods (see paragraph below about different operating modes of receiver).
Equalization consists of two sub-steps
Adapt equalizer using LMS (lines 111-121)
Generate equalizer output (lines 121-124)
Recall the equation for the LMS algorithm which has the form
fi [k + 1] = fi [k] + (s[k ] y[k]) r[k i]
and is seen in lines 114-115. The Matlab variable f stores the equalizer coefficients,
and eqOut stores the output of the equalizer.
Decision Device, Frame Sync, and Message Decoding (lines 125-129) This
part quantizes the equalizer output using quantalph, resulting in a stream of 4-PAM
symbol estimates stored in the variable dec. With knowledge of the start of the
header sequence from the previous stage, frame synchronization is performed, after
which the decisions pass into the decoder (i.e. pam2letters), the output of which is
stored in the variable decoded msg.
There are some other details of the receiver which are worth noting. The receiver consists
of two main loops and their corresponding counters
1. IFsampleIdx Each time this loop counter is incremented, the receiver has received
a new IF sample at the receiver frontend.
2. BBsampleIdx This loop counter is incremented every time a new baseband sample
is output from the baud-timing device.
Also, the receiver operates in 3 distinct modes:
1. HEADER SEARCH MODE In this mode, the receiver is running its correlator to search
for the header sequence.
2. TRAINING MODE In this mode, the receiver thinks that it is receiving training data,
and so it is training the equalizer using the LMS algorithm.
3. DATA MODE In this mode, the receiver has completed training, and believes that it
is receiving data.
The receiver starts in HEADER SEARCH MODE. Once the header is found, it switches to
TRAINING MODE, and when the training is complete it switches to DATA MODE. Once the
data transmission is complete (based on the length of the data sequence specified in the
system parameters), the receiver then returns to HEADER SEARCH MODE and repeats.
Listings
main.m
1
2
3
35
36
37
38
39
40
41
42
43
44
45
46
Tx.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
char_str_length=frame_length*lines_of_text;
% insert training & header, and generate 4-PAM source vector
s=reshape([repmat([marker; training],lines_of_text,1) reshape(lett
ers2pam(reshape(m,lines_of_text*dataLength/4,1)),dataLength,lines_
of_text)],lines_of_text*(dataLength+(length([marker; training])))
,1);
% generate pulse-shaped signal
x=conv(srrc(srrcLength,rolloff,M,0),upsample(s,M));
% mix signal to RF (analog upconversion)
p_noise=cumsum(randn(size(x))*sqrt(phase_noise_variance/N)); % gene
rate phase noise process
x_rf=x.*cos(2*pi*f_if*[1:length(x)]*T_t/M+p_noise);
% pass through BP channel
x2=conv(x_rf,upsample(c,M));
% add channel noise of appropriate SNR
x2_size=size(x2);
x2_nrm=sqrt(x2(srrcLength*M+1:x2_size(1)-srrcLength*M)*x2(srrcLeng
th*M+1:x2_size(1)-srrcLength*M)/x2_size(1));
x_r=x2+randn(size(x2))*10^(-SNR/20)*x2_nrm;
% perform analog conversion to IF, and do AGC
r=x_r(N:N:end);
r_nrm=r*r/length(r);
r=r/sqrt(r_nrm);
% add some zeros to front and back
r=[zeros(floor(rand*10*M),1); r; zeros(10*M,1)];
Rx.m
1
2
3
4
5
6
7
8
9
10
10
100
101
102
103
104
105
106
107
108
109
111
BBsampleIdx=BBsampleIdx+1;
% ok, were at next baseband sample, so increment
% perform timing recovery (OP)
x_sampled(BBsampleIdx)=interpsinc(x_bb,tnow+tau(BBsampleIdx
),srrcLength);
% interpolated value at tnow+tau
x_deltap=interpsinc(x_bb,tnow+tau(BBsampleIdx)+delta,srrcLe
ngth);
% get value to the right
x_deltam=interpsinc(x_bb,tnow+tau(BBsampleIdx)-delta,srrcLe
ngth);
% get value to the left
dx=x_deltap-x_deltam;
% calculate numerical derivative
tau(BBsampleIdx+1)=tau(BBsampleIdx)+mu_timing*dx*x_sampled(
BBsampleIdx);
% alg update: OP
tnow=tnow+T_t*f_s;
% update current position
% run correlator, matched to marker sequence
if (BBsampleIdx>eqDelay+markerLength-1)
% need to skip t
he first few sample until we have enough to fill correlator
corInputSignal=x_sampled(BBsampleIdx-markerLength+1-eqD
elay:BBsampleIdx-eqDelay);
% extract portion of signal used f
or correlation
Corr(BBsampleIdx)=(marker*corInputSignal)^2;
% calculate correlation
end
switch operationMode
case HEADER_SEARCH_MODE
% if we havent already fou
nd marker, look for it...
if Corr(BBsampleIdx)>correlThresh
% has cor
relation exceeded threshold?
operationMode=TRAINING_MODE;
% yep, so switch to training mode
trainingIndex=1;
% reset to trainingIndex to first sample of training data
packetIndex=packetIndex+1;
% increment packet counter
end 110
case TRAINING_MODE % if were in equalizer training mod
e, train the LMS equalizer
112
rr=x_sampled(BBsampleIdx:-1:BBsampleIdx-eqLength+1)
;
% extract "regressor" vector of receive
d signal
11
eqOut(BBsampleIdx)=f*rr;
% equalizer output
114
e_lms(BBsampleIdx)=training(trainingIndex)-eqOut(BB
sampleIdx);
% calculate LMS error term
115
f=f+mu_eq_lms*e_lms(BBsampleIdx)*rr;
% update equalizer coefficients
116
trainingIndex=trainingIndex+1;
% increment training index location
117
if trainingIndex>trainingLength
% are we done training?
118
operationMode=DATA_MODE;
% yep, switch to data mode
119
symbolIndex=1;
% and re-init symbol counter to 1
120
end
121
122
case DATA_MODE
% were into data portion of the pack
et -- equalizer, and save data
123
rr=x_sampled(BBsampleIdx:-1:BBsampleIdx-eqLength+1)
;
% extract "regressor" vector of receive
d signal
124
eqOut(BBsampleIdx)=f*rr;
% equalizer output
125
dec(symbolIndex)=quantalph(eqOut(BBsampleIdx),[-3 1 1 3]);
% make decisions
126
127
if mod(symbolIndex,4)==0
% if weve completed a w
hole letter (i.e. 4 PAM symbols), convert PAM symbols to letters
128
decoded_msg(packetIndex,symbolIndex/4)=pam2lett
ers(dec(symbolIndex-3:symbolIndex)); % re-assemble text message
129
end
130
symbolIndex=symbolIndex+1;
% increment training index location
131
if symbolIndex>dataLength % are we done with data
yet?
132
operationMode=HEADER_SEARCH_MODE; % yep, switc
h back to header search mode
133
end
134
end
135
end
12
end
% plot results ---------------------------------------------------figure(1);
plot(theta)
title(carrier phase estimate)
ylabel(theta)
xlabel(time)
figure(2)
plot(tau)
title(timing offset estimates)
ylabel(tau)
xlabel(time)
figure(3)
plot(Corr)
hold on
plot([1 length(Corr)],[correlThresh correlThresh],:) % plot thre
shold
title(correlator output (for finding start of training))
xlabel(time)
ylabel(correlation value)
figure(4)
plot(eqOut,b.)
% plot constellation diagram
title(constellation diagram (equalizer output));
ylabel(estimated symbol values)
xlabel(time)
figure(5)
plot(e_lms)
title(error at equalizer output (during training))
ylabel(e_lms)
xlabel(time)
globalParams.m
1
2
3
4
5
6
13
T_t=6.4e-6;
f_if=2e6;
rolloff=0.3;
dataLength=400;
%
%
%
%
14