Program:
% Wireless Communication System Modeling
% Parameters
f = 900e6; % Frequency in Hz (e.g., 900 MHz)
d = 10:1000; % Distance in meters (from 10 to 1000 meters)
ht = 30; % Transmitter antenna height in meters
hr = 2; % Receiver antenna height in meters
Pt = 30; % Transmitter power in dBm
Gt = 2; % Transmitter antenna gain in dB
Gr = 5; % Receiver antenna gain in dB
L = 1; % System loss in dB
% Two-Ray Channel Model
Pr_two_ray = (Gt * Gr * (ht^2 * hr^2)) ./ (d.^4);
Pr_two_ray = 10 * log10(Pr_two_ray) + Pt - L;
% Okumura-Hata Model (Urban Area)
A = (1.1 * log10(f) - 0.7) * hr - (1.56 * log10(f) - 0.8);
L_urban = 69.55 + 26.16 * log10(f) - 13.82 * log10(ht) - A + (44.9 - 6.55 *
log10(ht)) * log10(d);
Pr_urban = Pt - L_urban;
%
Plotting
figure;
subplot(2,1,1);
plot(d, Pr_two_ray, 'b', 'LineWidth',
2); xlabel('Distance (m)');
ylabel('Received Power (dBm)');
title('Two-Ray Channel Model');
grid on;
subplot(2,1,2);
plot(d, Pr_urban, 'r', 'LineWidth', 2);
xlabel('Distance (m)');
ylabel('Received Power (dBm)');
title('Okumura-Hata Model
(Urban)'); grid on;
legend('Two-Ray Channel', 'Okumura-Hata (Urban)');
Output:
Program:
% Modeling and Simulation of Multipath Fading Channel using MATLAB
% Parameters
fs = 1000; % Sampling frequency
(Hz) t = 0:1/fs:1; % Time vector (1 second)
fc = 100; % Carrier frequency (Hz)
num_paths = 4; % Number of multipath paths
delay_spread = 0.1; % Delay spread (seconds)
fade_variance = 0.5; % Variance of fading (adjust as needed)
% Generate random fading coefficients (Rayleigh fading)
fade_coeff = sqrt(fade_variance/2) * (randn(num_paths, length(t)) + 1i *
randn(num_paths, length(t)));
% Generate multipath channel response
channel_response = zeros(1, length(t));
for i = 1:num_paths
delay = i * delay_spread / num_paths;
channel_response = channel_response + fade_coeff(i, :) .* exp(1i * 2 * pi
* fc * (t - delay));
end
% Normalize the channel response
channel_response = channel_response
/
sqrt(sum(abs(channel_response).^2));
% Plot the results
subplot(2, 1, 1);
plot(t, abs(channel_response));
title('Multipath Fading Channel Magnitude Response');
xlabel('Time (s)');
ylabel('Magnitude');
subplot(2, 1, 2);
plot(t, angle(channel_response));
title('Multipath Fading Channel Phase Response');
xlabel('Time (s)');
ylabel('Phase (radians)');
Output:
Program:
% Simulation Parameters
% Parameters
numBits = 1e6; % Number of bits to
simulate SNRdB = 20; % Signal-to-Noise
Ratio in dB
% Generate random bits
txBits = randi([0, 1], 1, numBits);
% Modulation
modulatedSymbols = qammod(txBits, 16); % 16-QAM modulation
% AWGN Channel
noisySymbols = awgn(modulatedSymbols, SNRdB);
% Demodulation
rxBits = qamdemod(noisySymbols, 16);
% BER Calculation
ber = sum(txBits ~= rxBits) / numBits;
% Display results
disp(['Bit Error Rate (BER): ' num2str(ber)]);
% Other measurements and calculations can be added similarly
% Throughput Calculation
throughput = numBits / length(noisySymbols); % Assuming 1 symbol = 1
bit
disp(['Throughput: ' num2str(throughput) ' bits/symbol']);
% Capacity Calculation (Theoretical)
capacity = log2(1 + 10^(SNRdB/10)); % Shannon-Hartley theorem
disp(['Capacity: ' num2str(capacity) ' bits/symbol']);
% Other measurements can be added in a similar manner
% ... (Previous code)
% Display results
disp(['Bit Error Rate (BER): ' num2str(ber)]);
disp(['Throughput: ' num2str(throughput) ' bits/symbol']);
disp(['Capacity: ' num2str(capacity) ' bits/symbol']);
% Plot BER vs. SNR
snrValues = 0:2:30;
berValues = zeros(size(snrValues));
for i = 1:length(snrValues)
noisySymbols = awgn(modulatedSymbols, snrValues(i));
rxBits = qamdemod(noisySymbols, 16);
berValues(i) = sum(txBits ~= rxBits) / numBits;
end
figure;
semilogy(snrValues, berValues, 'bo-');
xlabel('SNR (dB)');
ylabel('Bit Error Rate (BER)');
title('BER vs. SNR');
grid on;
Output:
Program:
% DSSS Modulation and Demodulation
% Parameters
Chip_rate = 1000; % Chip rate in chips per
second Bit_rate = 100; % Bit rate in bits per
second Num_bits = 100; % Number of bits
to transmit
% Generate random bits to transmit
Data_bits = randi([0, 1], 1, num_bits);
% DSSS modulation
Chips_per_bit = chip_rate /
bit_rate; Chips = 2 * data_bits – 1;
Dsss_signal = reshape(repmat(chips, chips_per_bit, 1), 1, []);
% Add noise to simulate the channel
Snr_dB = 10; % Signal-to-noise ratio in dB
Noisy_signal = awgn(dsss_signal, snr_dB, ‘measured’);
% DSSS demodulation
Demodulated_chips = reshape(reshape(noisy_signal, chips_per_bit, []).’, 1,
[]);
Received_bits = demodulated_chips > 0;
% BER calculation
Bit_errors = sum(data_bits ~= received_bits);
BER = bit_errors / num_bits;
Disp([‘Bit Error Rate (BER): ‘, num2str(BER)]);
Output:
Program for ZFE:
% Generate channel and transmitted signal
channel = [0.3, 0.5, 0.2];
tx_signal = randi([0, 1], 1, 100); % Random binary input signal
% Apply channel distortion
rx_signal = conv(tx_signal, channel);
% Zero-Forcing Equalization
zfe_equalized = conv(rx_signal, 1./channel);
% Display results
subplot(3,1,1); stem(tx_signal); title('Transmitted Signal');
subplot(3,1,2); stem(rx_signal); title('Received Signal');
subplot(3,1,3); stem(zfe_equalized); title('Zero-Forcing Equalized Signal');
Program for MMSEE:
% Generate channel and transmitted signal
channel = [0.3, 0.5, 0.2];
tx_signal = randi([0, 1], 1, 100); % Random binary input signal
% Apply channel distortion
rx_signal = conv(tx_signal, channel);
% MMSE Equalization
snr = 10; % Signal-to-noise ratio in dB
mmse_equalized = conv(rx_signal, conj(channel) / (sum(abs(channel).^2) + 10^(-
snr/10)));
% Display results
subplot(3,1,1); stem(tx_signal); title('Transmitted Signal');
subplot(3,1,2); stem(rx_signal); title('Received Signal');
subplot(3,1,3); stem(mmse_equalized); title('MMSE Equalized Signal');
Program for ADE:
% Adaptive Equalizer using LMS Algorithm
clear all;
close all;
% Parameters
numSymbols = 1000; % Number of transmitted
symbols snr_dB = 15; % Signal-to-noise ratio in dB
channelOrder = 15; % Channel order (length)
stepSize = 0.01; % LMS step size
% Generate random QPSK symbols
data = randi([0, 3], 1, numSymbols);
QPSK = exp(1j * (pi/4) * data);
% Create a channel impulse response (example: multipath channel)
channel = [0.407, 0.815, 0.407];
% Transmit through the channel
receivedSignal = conv(channel, QPSK);
% Add complex Gaussian noise to the received signal
noisePower = 10^(-snr_dB/10);
noise = sqrt(noisePower/2) * (randn(1, length(receivedSignal)) + 1j * randn(1,
length(receivedSignal)));
receivedSignal = receivedSignal + noise;
% Initialize equalizer coefficients
equalizerCoeff = zeros(1, channelOrder);
% Adaptive Equalization using LMS algorithm
for n = channelOrder+1 : length(receivedSignal)
inputSignal = receivedSignal(n:-1:n-channelOrder+1);
estimatedSymbol = equalizerCoeff * inputSignal';
error = QPSK(floor(n/channelOrder)) - estimatedSymbol;
equalizerCoeff = equalizerCoeff + stepSize * conj(error) * inputSignal;
end
% Equalize the received signal
equalizedSignal = conv(equalizerCoeff, receivedSignal);
% Plotting
figure;
subplot(3,1,1);
stem(real(QPSK), imag(QPSK), 'Marker',
'o'); title('Transmitted QPSK Symbols');
xlabel('In-Phase (I)');
ylabel('Quadrature (Q)');
axis([-2 2 -2 2]);
grid on;
subplot(3,1,2);
plot(real(receivedSignal), 'b');
hold on;
plot(imag(receivedSignal), 'r');
title('Received Signal');
xlabel('Sample Index');
ylabel('Amplitude');
legend('Real', 'Imaginary');
grid on;
subplot(3,1,3);
plot(real(equalizedSignal), 'b');
hold on;
plot(imag(equalizedSignal), 'r');
title('Equalized Signal');
xlabel('Sample Index');
ylabel('Amplitude');
legend('Real', 'Imaginary');
grid on;
sgtitle('Adaptive Equalization using LMS Algorithm');
% Display equalizer coefficients
disp('Equalizer Coefficients:');
disp(equalizerCoeff);
Program for DFE:
% Decision Feedback Equalizer (DFE) Simulation
clear all;
close all;
% Parameters
numSymbols = 1000; % Number of transmitted symbols
snr_dB = 15; % Signal-to-noise ratio in dB
channelOrder = 15; % Channel order (length)
ffFilterOrder = 7; % Feedforward filter order
fbFilterOrder = 5; % Feedback filter order
stepSize = 0.01; % LMS step size
% Generate random QPSK symbols
data = randi([0, 3], 1, numSymbols);
QPSK = exp(1j * (pi/4) * data);
% Create a channel impulse response (example: multipath channel)
channel = [0.407, 0.815, 0.407];
% Transmit through the channel
receivedSignal = conv(channel, QPSK);
% Add complex Gaussian noise to the received signal
noisePower = 10^(-snr_dB/10);
noise = sqrt(noisePower/2) * (randn(1, length(receivedSignal)) + 1j * randn(1,
length(receivedSignal)));
receivedSignal = receivedSignal + noise;
% Initialize feedforward and feedback filter coefficients
ffFilterCoeff = zeros(1, ffFilterOrder);
fbFilterCoeff = zeros(1, fbFilterOrder);
% Initialize symbol estimates and error history
symbolEstimates = zeros(1, numSymbols);
errorHistory = zeros(1, numSymbols);
% Decision Feedback Equalization
for n = max(channelOrder, ffFilterOrder) + 1 : numSymbols
% Feedforward filter
ffInput = receivedSignal(n:-1:n-ffFilterOrder+1);
ffOutput = ffFilterCoeff * ffInput';
% Feedback filter
fbInput = symbolEstimates(n-1:-1:n-fbFilterOrder);
fbOutput = fbFilterCoeff * fbInput';
% Combine feedforward and feedback outputs
combinedOutput = ffOutput + fbOutput;
% Make a decision based on the combined output
symbolEstimates(n) = sign(real(combinedOutput)) + 1j *
sign(imag(combinedOutput));
% Calculate the error and update filters
error = QPSK(n) - symbolEstimates(n);
errorHistory(n) = abs(error);
% Update feedforward and feedback filter coefficients
ffFilterCoeff = ffFilterCoeff + stepSize * conj(error) * ffInput;
fbFilterCoeff = fbFilterCoeff + stepSize * conj(error) * fbInput;
end
% Plotting
figure;
subplot(3,1,1);
stem(real(QPSK), imag(QPSK), 'Marker',
'o'); title('Transmitted QPSK Symbols');
xlabel('In-Phase (I)');
ylabel('Quadrature (Q)');
axis([-2 2 -2 2]);
grid on;
subplot(3,1,2);
plot(real(receivedSignal), 'b');
hold on;
plot(imag(receivedSignal), 'r');
title('Received Signal');
xlabel('Sample Index');
ylabel('Amplitude');
legend('Real', 'Imaginary');
grid on;
subplot(3,1,3);
plot(real(symbolEstimates), 'b');
hold on;
plot(imag(symbolEstimates), 'r');
title('Equalized Symbols (Decision Feedback Equalizer)');
xlabel('Sample Index');
ylabel('Amplitude');
legend('Real', 'Imaginary');
grid on;
sgtitle('Decision Feedback Equalization');
% Display filter coefficients
disp('Feedforward Filter Coefficients:');
disp(ffFilterCoeff);
disp('Feedback Filter Coefficients:');
disp(fbFilterCoeff);
Output for ZFE:
Output for MMSEE:
Output for ADE:
OUTPUT FOR DFE:
Program:
% Wireless Communication Simulation: TDMA, FDMA, CDMA
clear; clc;
% Parameters
numUsers = 4; % Number of users
numSlots = 10; % Number of time slots
numSubchannels = 8; % Number of
subchannels
SNR_dB = 10; % Signal-to-Noise Ratio (in dB)
spreadFactor = 8; % CDMA Spread factor
% Generate random data for users
data = randi([0 1], numUsers, numSlots*numSubchannels);
% TDMA: Transmit data in each time slot
tdmaSignal = zeros(numUsers, numSlots*numSubchannels);
for user = 1:numUsers
for slot = 1:numSlots
tdmaSignal(user, (slot-1)*numSubchannels + 1 : slot*numSubchannels) =
data(user, (slot-1)*numSubchannels + 1 : slot*numSubchannels);
end
end
% FDMA: Divide data into subchannels
fdmaSignal = zeros(numUsers, numSlots*numSubchannels);
for user = 1:numUsers
for slot = 1:numSlots
fdmaSignal(user, (slot-1)*numSubchannels + 1 : slot*numSubchannels) =
data(user, (slot-1)*numSubchannels + 1 : slot*numSubchannels);
end
end
% CDMA: Spread data using pseudo-random codes
cdmaCodes = sign(randn(numUsers, numSlots*numSubchannels));
cdmaSignal = zeros(1, numSlots*numSubchannels);
for user = 1:numUsers
cdmaSignal = cdmaSignal + spreadFactor * cdmaCodes(user, :) .* data(user, :);
end
% Add noise to signals
noisePower = 10^(-SNR_dB/10);
tdmaSignalNoisy = awgn(tdmaSignal, SNR_dB, 'measured');
fdmaSignalNoisy = awgn(fdmaSignal, SNR_dB, 'measured');
cdmaSignalNoisy = awgn(cdmaSignal, SNR_dB, 'measured');
% Display results
figure;
subplot(3, 1, 1); stem(data(1, :)); title('User 1 Data');
subplot(3, 1, 2); stem(data(2, :)); title('User 2 Data');
subplot(3, 1, 3); stem(data(3, :)); title('User 3 Data');
figure;
subplot(3, 1, 1); plot(tdmaSignalNoisy(1, :)); title('TDMA Signal (User 1)');
subplot(3, 1, 2); plot(fdmaSignalNoisy(1, :)); title('FDMA Signal (User 1)');
subplot(3, 1, 3); plot(cdmaSignalNoisy); title('CDMA
Signal'); disp('Simulation completed.');
Output: