None
None
None
[1]. Generate the binary data stream, modulate it using a 16-QAM baseband
modulator, transmit it through AWGN channel and then demodulate. Compute
the system’s bit error rate (BER). Also, display the transmitted and received
signals in a scatter plot.
The result is a complex column vector whose values are in the 16-point QAM
signal constellation.
4. Add White Gaussian Noise. Applying the awgn function to the modulated
signal adds white Gaussian noise to it. The ratio of bit energy to noise power
spectral density, Eb/N0, is arbitrarily set at 10 dB.
% Send signal over an AWGN channel.
ynoisy = awgn(ytx,10,'measured');
%% Received Signal
yrx = ynoisy;
5. Create a Scatter Plot. Applying the scatterplot function to the transmitted and
received signals shows what the signal constellation looks like and how the noise
distorts the signal. In the plot, the horizontal axis is the in-phase component of
the signal and the vertical axis is the quadrature
component.
%% Scatter Plot
% Create scatter plot of noisy signal and transmitted
% signal on the same axes.
h = scatterplot(yrx(1:3e3),1,0,'g.');
hold on;
scatterplot(ytx(1:3e3),1,0,'r+',h);
title('Received Signal');
legend('Received Signal','Signal Constellation');
axis([-5 5 -5 5]); % Set axis ranges.
hold off;
6. Demodulate Using 16-QAM. Applying the ‘qamdemod’ to the received signal
demodulates it. The result is a column vector containing integers between 0 and
15.
%% Demodulation
% Demodulate signal using 16-QAM.
zsym = demodulate(modem.qamdemod(M),yrx);
8. Compute the System’s BER. Applying the biterr function to the original
binary vector and to the binary vector from the demodulation step above yields
the number of bit errors and the bit error rate.
%% BER Computation
% Compare x and z to obtain the number of errors and
% the bit error rate.
[number_of_errors,bit_error_rate] = biterr(x,z)
For BPSK:
M=2
y = modulate(modem.pskmmod(M),xsym);
zsym = demodulate(modem.pskdemod(M),yrx);
For MSK:
M=2
y = modulate(modem.mskmod,xsym);
zsym = demodulate(modem.mskdemod,yrx);
Compare the BER of Problem (1) & (3) and comment on the results.
[4]. Modify the modulation in Problem (3) so that it computes the BER for integer
values of EbNo between 0 and 7. Plot the BER as a function of EbNo using a
logarithmic scale for the vertical axis. (Using ‘bertool’ )
edit bertooltemplate
4. Update numBits and totErr. After the pasted code from the last step and
before the end statement from the template, insert the following code.
%% Update totErr and numBits.
totErr = totErr + number_of_errors;
numBits = numBits + n;
9. Use BERTool to Simulate and Plot. Click the Run button on BERTool.
[5] Scalar Quantization ( Use of codebook, partition)
qunatiz function uses partition and codebook to provide quantization as shown
below.
% sample programme
partition = [0,1,3];
codebook = [-1, 0.5, 2, 3];
samp = [-2.4, -1, -.2, 0, .2, 1, 1.2, 1.9, 2, 2.9, 3, 3.5, 5];
[index,quantized] = quantiz(samp,partition,codebook);
quantized
quantized =
Columns 1 through 6
-1.0000 -1.0000 -1.0000 -1.0000 0.5000 0.5000
Columns 7 through 13
2.0000 2.0000 2.0000 2.0000 2.0000 3.0000 3.0000
(1) Change the signal from sine to sawtooth and observe the effects.
(2) Change the partition and codebook and observe the effect on the quantized signal.
Change the waveform from sin to sawtooth and compare the distortion before
optimization and after optimization.
Lab Session 2
[7] Hamming code
%Encoding and decoding of [7,4] Hamming code.
close all;
clear all;
clc;
m = 3; n = 2^m-1; k = n-m;
parmat = hammgen(m); % Produce parity-check matrix.
trt = syndtable(parmat); % Produce decoding table.
recd = [1 0 0 1 1 1 1] % Suppose this is the received vector.
syndrome = rem(recd * parmat',2);
syndrome_de = bi2de(syndrome,'left-msb'); % Convert to decimal.
disp(['Syndrome = ',num2str(syndrome_de),...
' (decimal), ',num2str(syndrome),' (binary)'])
corrvect = trt(1+syndrome_de,:) % Correction vector
% Now compute the corrected codeword.
correctedcode = rem(corrvect+recd,2)
Modify the received code word ‘recd’ and run the programme again.
Modify above programme for m=4 i.e. [15,11] Hamming code. Make
necessary corrections in the programme.
m=4
recd = [ any 15 bit code word]
The encoder's constraint length is a vector of length 2 because the encoder has two inputs.
The elements of this vector indicate the number of bits stored in each shift register,
including the current input bits. Counting memory spaces in each shift register in the
diagram and adding one for the current inputs leads to a constraint length of [5 4].
To determine the code generator parameter as a 2-by-3 matrix of octal numbers, use the
element in the ith row and jth column to indicate how the ith input contributes to the jth
output. For example, to compute the element in the second row and third column, the
leftmost and two rightmost elements in the second shift register of the diagram feed into
the sum that forms the third output. Capture this information as the binary number 1011,
which is equivalent to the octal number 13. The full value of the code generator matrix is
[23 35 0; 0 5 13].
To use the constraint length and code generator parameters in the convenc and vitdec
functions, use the poly2trellis function to convert those parameters into a trellis
structure. The command to do this is below.
close all;
clear all;
clc;
len = 1000;
msg = randint(2*len,1); % Random binary message of 2-bit symbols
trel = poly2trellis([5 4],[23 35 0;0 5 13]); % Trellis
code = convenc(msg,trel); % Encode the message.
ncode = rem(code + randerr(3*len,1,[0 1;.96 .04]),2); % Add noise.
decoded = vitdec(ncode,trel,34,'cont','hard'); % Decode.
[number,ratio] = biterr(decoded(68+1:end),msg(1:end-68))
% Modulation
xq(1)=0; d(1)=0;
for n=2:length(x),
d(n)=sign(x(n)-xq(n-1));
xq(n)=xq(n-1)+d(n)*step;
end
subplot(222);
plot(d(1:100)), axis([0 100 -10.2 10.2]);
title('First 100 output of delta modultaion')
% Demodulation
y=0;
for n=2:length(d)
y(n)=y(n-1)+d(n);
end;
subplot(223);plot(y); title('demodulation by summing');
%slope overload
A=2.5; x=A*x; %max. slope=2.5*62.8=157, slope overloading
% Modulation
xq(1)=0; d(1)=0;
for n=2:length(x),
d(n)=sign(x(n)-xq(n-1)); xq(n)=xq(n-1)+d(n)*step;
end
% Demodulation
y=0;
for n=2:length(d)
y(n)=y(n-1)+d(n);
end;
subplot(224), plot(y); title('demodulation by summing, slope overload')
Change the value of A >1 for slope overload effect and <1 for observing the
effects of granual noise.
[10] Simulation of Hamming code with and without interleaver. Observe the
ability of interleaver to correct burst errors
errors = zeros(size(op_code));
errors(n-2:n+3) = [1 1 1 1 1 1]; % Burst error affecting adjacent blocks
Result:
Number of errors and error rate, without interleaving:
num_no_interleav =
4
rate_no_interleav =
0.0020
Number of errors and error rate, with interleaving:
num_interleav =
0
rate_interleav =
0
* Change the error pattern, seed1, seed2 and type of code in the above
programme and observe.
[11] Generation of PN sequence and spreading of data using it. Plot the
frequency spectrum of the spreaded signal.
by
BPSK Modulator
AWGN Channel
Error Rate Calculation
Output on Scope
[6] Auto correlation & Cross Correlation of spread spectrum code generator
ans =
89.177 0.0397