0% found this document useful (0 votes)
6 views4 pages

Wireless Communication

The document outlines a series of MATLAB simulations for different communication experiments, including TDMA, QAM, Zero-Forcing Equalization, and QPSK with Rayleigh fading. Each experiment involves defining parameters, generating user traffic or symbols, simulating transmission through a channel, and calculating the Bit Error Rate (BER). Results are visualized and displayed, demonstrating the performance of various modulation and equalization techniques.

Uploaded by

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

Wireless Communication

The document outlines a series of MATLAB simulations for different communication experiments, including TDMA, QAM, Zero-Forcing Equalization, and QPSK with Rayleigh fading. Each experiment involves defining parameters, generating user traffic or symbols, simulating transmission through a channel, and calculating the Bit Error Rate (BER). Results are visualized and displayed, demonstrating the performance of various modulation and equalization techniques.

Uploaded by

peterjohn00475
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

% TDMA Simulation

% Step 1: Define System Parameters


numUsers = 4;
timeSlotDuration = 1; % seconds
totalTimeSlots = 10;
channelGain = 0.8;

% Step 2: Generate User Traffic


userData = round(rand(numUsers, totalTimeSlots)); % Compatible version of
randi([0,1],...)

% Step 3: Create Time Slots


timeSlots = linspace(0, timeSlotDuration * totalTimeSlots, totalTimeSlots);

% Step 4: Allocate Time Slots to Users


userSlots = mod(0:totalTimeSlots - 1, numUsers) + 1;

% Step 5: Simulate Transmission


receivedData = zeros(numUsers, totalTimeSlots);
for slot = 1:totalTimeSlots
for user = 1:numUsers
if userSlots(slot) == user
% Simulate transmission for the current user in the time slot
transmittedData = userData(user, slot);
% Simulate channel effects
receivedData(user, slot) = transmittedData * channelGain;
end
end
end

% Step 6: Evaluate Performance Metrics (e.g., BER)


% Threshold received data to binary values before calculating BER
thresholdedData = receivedData > 0.5; % since channelGain is 0.8
bitErrorRate = sum(sum(xor(thresholdedData, userData))) / (numUsers *
totalTimeSlots);

% Step 7: Visualize Results


figure;
subplot(2, 1, 1);
stem(timeSlots, userData');
title('User Traffic');
xlabel('Time (s)');
ylabel('Data');
legend('User 1', 'User 2', 'User 3', 'User 4');

subplot(2, 1, 2);
stem(timeSlots, thresholdedData');
title('Received Data');
xlabel('Time (s)');
ylabel('Data');
legend('User 1', 'User 2', 'User 3', 'User 4');

disp(['Bit Error Rate: ', num2str(bitErrorRate)]);

( 6 experiment)
% Parameters
M = 4; % QAM order
N = 1000; % Number of symbols
SNRdB = 10; % SNR in dB
pilotSymbols = [1 -1 1 -1]; % Pilot sequence

% Generate random QAM symbols


transmittedSymbols = floor(M * rand(1, N));

% QAM modulation
modulatedSymbols = qammod(transmittedSymbols, M);

% Channel (FIR filter)


channel = [0.8 -0.4 0.2 -0.1];
channelOutput = filter(channel, 1, modulatedSymbols);

% Add Gaussian noise


SNR = 10^(SNRdB/10);
noiseVar = 1 / (2 * SNR); % QAM: both I and Q noise
noise = sqrt(noiseVar) * (randn(1, length(channelOutput)) + 1i * randn(1,
length(channelOutput))) / sqrt(2);
receivedSignal = channelOutput + noise;

% --- Channel Estimation using Pilots ---


% Select random indices for pilots (backward-compatible randperm)
temp = randperm(N);
pilotIndices = temp(1:length(pilotSymbols));
receivedPilots = receivedSignal(pilotIndices);

% Estimate channel (basic LS approach)


estimatedChannel = conv(receivedPilots, conj(pilotSymbols(end:-1:1)));
estimatedChannel = estimatedChannel(end - length(channel) + 1 : end);

% MMSE Equalization
equalizerCoefficients = conj(estimatedChannel) ./ (abs(estimatedChannel).^2 +
noiseVar);
equalizedSymbols = filter(equalizerCoefficients, 1, receivedSignal);

% Demodulate
demodulatedSymbols = qamdemod(equalizedSymbols, M);

% Compute Bit Error Rate


bitErrors = sum(transmittedSymbols ~= demodulatedSymbols);
bitErrorRate = bitErrors / N;

% Display result
disp(['Bit Error Rate: ' num2str(bitErrorRate)]);
(5 ( 2) experiment )

% Zero-Forcing Equalizer (ZFE) MATLAB code

% Define the channel impulse response


h = [0.1 0.3 0.4 0.2];

% Generate random transmitted symbols (binary)


N = 100; % Number of symbols
symbols = round(rand(1, N)); % Compatible with older MATLAB versions
% Convolve transmitted symbols with the channel
received_signal = conv(symbols, h);

% Add AWGN noise


snr_dB = 20;
received_signal = awgn(received_signal, snr_dB, 'measured');

% Equalizer parameters
L = length(h);
equalizer_taps = 0.01 * ones(1, L); % Initialize with small non-zero values

% Prepare output
equalized_symbols = zeros(1, N);

% Equalization loop
for n = 1:(length(received_signal) - L + 1)
received_symbols = received_signal(n:n+L-1);

% Equalize
equalized_symbols(n) = equalizer_taps * received_symbols';

% Update equalizer taps using Least Squares-like rule


error = symbols(n) - equalized_symbols(n);
equalizer_taps = equalizer_taps + error * received_symbols / (received_symbols
* received_symbols');
end

% Display original vs equalized (rounded) symbols


disp('Original Symbols:');
disp(symbols);

disp('Equalized Symbols (rounded):');


disp(round(real(equalized_symbols))); % rounding to compare against binary
( 5 (1) experiment )
% Define simulation parameters
numBits = 1e6; % Number of bits to transmit
EbNo_dB = 10; % Eb/No in dB

% QPSK: 2 bits per symbol


numSymbols = numBits / 2;

% Generate QPSK symbols (random integers from 0 to 3)


txSymbols = floor(4 * rand(1, numSymbols));

% Modulate using QPSK with pi/4 phase offset


modulatedSymbols = pskmod(txSymbols, 4, pi/4);

% Add AWGN noise


EbNo = 10^(EbNo_dB/10);
noiseVar = 1 / (2 * EbNo);
noise = sqrt(noiseVar) * (randn(size(modulatedSymbols)) + 1i *
randn(size(modulatedSymbols))) / sqrt(2);
rxSymbols = modulatedSymbols + noise;

% Apply Rayleigh fading channel


fadeChannel = rayleighchan(1/1000, 30);
fadedSymbols = filter(fadeChannel, rxSymbols);

% Demodulate received symbols


demodulatedSymbols = pskdemod(fadedSymbols, 4, pi/4);

% Convert symbols back to bits to compute BER


txBits = de2bi(txSymbols, 2, 'left-msb');
rxBits = de2bi(demodulatedSymbols, 2, 'left-msb');

% Compare bits
numErrors = sum(sum(txBits ~= rxBits));
ber = numErrors / numBits;

% Display results
fprintf('Bit Error Rate (BER): %.6f\n', ber);
( 3 experiment )

You might also like