0% found this document useful (0 votes)
12 views14 pages

DC Lab Manual

The document provides MATLAB code snippets for various signal processing tasks including Gram-Schmidt orthogonalization, binary baseband signal simulation with BER estimation, QPSK modulation and demodulation, and 16-QAM modulation with constellation visualization. Each section includes explanations of parameters, data generation, modulation processes, and steps to run the code. The document emphasizes the importance of visualizing signals and their constellations in understanding communication systems.

Uploaded by

vishalinivi07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views14 pages

DC Lab Manual

The document provides MATLAB code snippets for various signal processing tasks including Gram-Schmidt orthogonalization, binary baseband signal simulation with BER estimation, QPSK modulation and demodulation, and 16-QAM modulation with constellation visualization. Each section includes explanations of parameters, data generation, modulation processes, and steps to run the code. The document emphasizes the importance of visualizing signals and their constellations in understanding communication systems.

Uploaded by

vishalinivi07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

1.

Gram-Schmidt Orthogonalization: To find orthogonal basis vectors for the


given set of vectors and plot the orthonormal vectors.

The Gram-Schmidt process is used to convert a set of vectors into an orthogonal (or orthonormal) set of
vectors. Here's a MATLAB code snippet that implements the Gram-Schmidt process and plots the
orthonormal vectors.

% Given set of vectors


A = [1, 1, 1;
1, 0, 1;
1, -1, 0];

% Number of vectors
n = size(A, 2);

% Initialize Q (orthogonal) and R (upper triangular) matrices


Q = zeros(size(A));
R = zeros(n);

% Gram-Schmidt process
for j = 1:n
v = A(:, j);
for i = 1:j-1
R(i, j) = Q(:, i)' * A(:, j);
v = v - R(i, j) * Q(:, i);
end
R(j, j) = norm(v);
Q(:, j) = v / R(j, j);
end

% Display orthonormal basis


disp('Orthonormal basis (Q):');
disp(Q);

% Plotting the original and orthonormal vectors


figure;
hold on;
colors = {'r', 'g', 'b'};

% Plot original vectors


for i = 1:n
quiver3(0, 0, 0, A(1, i), A(2, i), A(3, i), 0, 'k', 'LineWidth', 2);
end

% Plot orthonormal vectors


for i = 1:n
quiver3(0, 0, 0, Q(1, i), Q(2, i), Q(3, i), 0, colors{i}, 'LineWidth', 2);
end

% Formatting the plot


xlabel('X');
ylabel('Y');
zlabel('Z');
title('Original and Orthonormal Vectors');
legend('Original Vectors', 'Orthonormal Vectors');
grid on;
axis equal;
hold off;

Output:
Orthonormal basis (Q):
0.5774 0.7071 -0.4082
0.5774 0 0.8165
0.5774 -0.7071 -0.4082

Explanation:

1. Input Matrix A: The matrix A contains the set of vectors as its columns.
2. Gram-Schmidt Process: The loop iterates over the vectors to orthogonalize them using
the Gram-Schmidt process. The result is stored in the matrix Q.
3. Plotting: The original vectors are plotted in black, while the orthonormal vectors
obtained from the Gram-Schmidt process are plotted in different colors.

Steps to Run:

1. Copy the code into a MATLAB script or the MATLAB command window.
2. Run the code. It will display the orthonormal vectors and plot them alongside the original
vectors.

You can replace the matrix A with any other set of vectors to test the code with different inputs.
Simulation of binary baseband signals using a rectangular pulse and estimate
the BER for AWGN channel using matched filter receiver.

To simulate binary baseband signals using a rectangular pulse and estimate the Bit Error Rate (BER) for
an Additive White Gaussian Noise (AWGN) channel using a matched filter receiver in MATLAB, you can
follow these steps. The code below performs this simulation:

% Parameters

N = 1e5; % Number of bits

T = 1; % Bit duration

Fs = 10; % Sampling frequency (samples per bit)

SNR_dB = 0:2:12; % SNR values in dB


M = 2; % Binary signaling

% Generate random binary data

data = randi([0 M-1], N, 1);

% Rectangular pulse shaping

rect_pulse = ones(Fs, 1);

% Baseband signal (rectangular pulse)

tx_signal = rect_pulse * 2 * (data' - 0.5);

% Reshape tx_signal to simulate over the time

tx_signal = reshape(tx_signal, 1, N*Fs);

% Initialize BER array

BER = zeros(length(SNR_dB), 1);

% Loop over different SNR values

for i = 1:length(SNR_dB)

% AWGN channel

rx_signal = awgn(tx_signal, SNR_dB(i), 'measured');

% Matched filter (correlator) receiver

matched_filter = conv(rx_signal, rect_pulse(end:-1:1));

% Downsample and make decisions based on threshold

sampled_signal = matched_filter(Fs:Fs:end);

received_bits = sampled_signal > 0;


% Calculate BER

BER(i) = sum(data ~= received_bits') / N;

end

% Plot BER vs. SNR

figure;

semilogy(SNR_dB, BER, 'b-o');

xlabel('SNR (dB)');

ylabel('Bit Error Rate (BER)');

title('BER vs. SNR for Binary Baseband Signal in AWGN Channel');

grid on;

Explanation:

1. Parameters:
o N: Number of bits to transmit.
o T: Bit duration.
o Fs: Sampling frequency (number of samples per bit).
o SNR_dB: Range of Signal-to-Noise Ratio (SNR) values in dB to evaluate.
o M: Binary signaling (2 for BPSK).
2. Binary Data Generation:
o Random binary data is generated using randi.
3. Rectangular Pulse Shaping:
o The transmitted signal (tx_signal) is created by applying a rectangular pulse to
the binary data.
4. AWGN Channel:
o The awgn function simulates the effect of an AWGN channel on the transmitted
signal.
5. Matched Filter Receiver:
o A matched filter is applied by convolving the received signal with the time-
reversed rectangular pulse.
6. BER Calculation:
o The received signal is downsampled and thresholded to recover the binary data.
o The Bit Error Rate (BER) is calculated by comparing the received bits with the
original transmitted bits.
7. Plotting:
o The BER is plotted against the SNR in dB.

Steps to Run:

1. Copy the code into a MATLAB script or the MATLAB command window.
2. Run the code. It will simulate the transmission and reception of the binary baseband
signals, and plot the BER versus SNR curve.

This simulation provides a basic understanding of how binary baseband signals are transmitted
over an AWGN channel and received using a matched filter, with the BER being a key
performance metric.
Perform the QPSK Modulation and demodulation. Display the signal and
its constellation.

% Parameters
N = 1000; % Number of symbols
M = 4; % QPSK (4-ary modulation)
k = log2(M); % Bits per symbol
SNR_dB = 15; % Signal-to-noise ratio in dB

% Generate random binary data


data = randi([0 1], N*k, 1);

% Reshape data into symbols (2 bits per symbol for QPSK)


data_symbols = reshape(data, k, N).';

% Convert binary to decimal (0, 1, 2, 3)


data_symbols = bi2de(data_symbols);

% QPSK Modulation
tx_signal = pskmod(data_symbols, M, pi/4);

% AWGN Channel
rx_signal = awgn(tx_signal, SNR_dB, 'measured');

% QPSK Demodulation
rx_symbols = pskdemod(rx_signal, M, pi/4);

% Convert received symbols back to binary


rx_data = de2bi(rx_symbols, k);
rx_data = rx_data.';
rx_data = rx_data(:);

% Display the signal


figure;
subplot(2,1,1);
plot(real(tx_signal), 'b');
hold on;
plot(imag(tx_signal), 'r');
title('QPSK Modulated Signal');
xlabel('Sample Index');
ylabel('Amplitude');
legend('In-phase', 'Quadrature');
grid on;

% Display the constellation diagram


subplot(2,1,2);
scatterplot(rx_signal);
title('QPSK Constellation');
grid on;

% Compute Bit Error Rate (BER)


BER = sum(data ~= rx_data) / length(data);
disp(['Bit Error Rate (BER): ', num2str(BER)]);

Explanation:

1. Parameters:
o N: Number of symbols to transmit.
o M: The modulation order (4 for QPSK, since there are 4 possible symbol states).
o k: Bits per symbol (log2(M) gives 2 for QPSK).
o SNR_dB: The Signal-to-Noise Ratio in dB for the AWGN channel.
2. Data Generation:
o Random binary data is generated and reshaped into groups of 2 bits (since QPSK
modulates 2 bits per symbol).
3. QPSK Modulation:
o pskmod is used to perform QPSK modulation on the data symbols. A phase offset
of pi/4 is used to achieve the standard QPSK constellation.
4. AWGN Channel:
o The modulated signal is passed through an AWGN channel using awgn.
5. QPSK Demodulation:
o pskdemod is used to demodulate the received signal back to the original symbols.
6. BER Calculation:
o The demodulated data is compared with the original transmitted data to compute
the Bit Error Rate (BER).
7. Plotting:
o The modulated signal is plotted, showing the in-phase (I) and quadrature (Q)
components.
o The constellation diagram is displayed using scatterplot, showing the QPSK
constellation points.

Steps to Run:

1. Copy the code into a MATLAB script or the MATLAB command window.
2. Run the code. It will perform QPSK modulation, transmit the signal through an AWGN
channel, demodulate the signal, and display the modulated signal and its constellation
diagram.

This code provides a complete implementation of QPSK modulation and demodulation, along
with visualizations of the signal and its constellation, which are essential in understanding QPSK
communication systems.

Output:
Bit Error Rate (BER): 0
Generate 16-QAM Modulation and obtain the QAM
constellation.

% Parameters
N = 1000; % Number of symbols
M = 16; % 16-QAM (16-ary modulation)
k = log2(M); % Bits per symbol
SNR_dB = 20; % Signal-to-noise ratio in dB

% Generate random binary data


data = randi([0 1], N*k, 1);

% Reshape data into symbols (4 bits per symbol for 16-QAM)


data_symbols = reshape(data, k, N).';
% Convert binary to decimal (0 to 15 for 16-QAM)
data_symbols = bi2de(data_symbols);

% 16-QAM Modulation
tx_signal = qammod(data_symbols, M, 'UnitAveragePower', true);

% AWGN Channel (optional, can be removed if you only want the constellation)
rx_signal = awgn(tx_signal, SNR_dB, 'measured');

% Plot QAM constellation


scatterplot(rx_signal);
title('16-QAM Constellation');
xlabel('In-phase Component');
ylabel('Quadrature Component');
grid on;

% Display the constellation points


hold on;
scatter(real(tx_signal), imag(tx_signal), 'ro');
legend('Received Signal', 'Transmitted Signal');
Explanation:

1. Parameters:
o N: Number of symbols to transmit.
o M: Modulation order (16 for 16-QAM, since there are 16 possible symbol states).
o k: Bits per symbol (log2(M) gives 4 for 16-QAM).
o SNR_dB: Signal-to-Noise Ratio in dB (optional for constellation visualization with
noise).
2. Data Generation:
o Random binary data is generated and reshaped into groups of 4 bits (since 16-
QAM modulates 4 bits per symbol).
3. Binary to Decimal Conversion:
o The binary groups are converted to decimal numbers ranging from 0 to 15, which
correspond to the 16-QAM symbol indices.
4. 16-QAM Modulation:
o qammod is used to perform 16-QAM modulation on the data symbols. The option
'UnitAveragePower', true normalizes the average power of the constellation
to 1.
5. AWGN Channel (Optional):
o The modulated signal is passed through an AWGN channel using awgn. This step
can be omitted if you only want to visualize the constellation without noise.
6. Constellation Plotting:
o The constellation diagram of the received signal is plotted using scatterplot.
o The transmitted signal points are also overlaid on the constellation diagram in red
for comparison.

Steps to Run:

1. Copy the code into a MATLAB script or the MATLAB command window.
2. Run the code. It will perform 16-QAM modulation and display the QAM constellation
diagram, optionally including the effects of an AWGN channel.

This code provides a clear visualization of the 16-QAM constellation, which is essential for
understanding the modulation scheme's signal space representation.

You might also like