Use the Matlab code discussed in class to build a simulator for the digital modulation scheme...

90.2K

Verified Solution

Question

Advance Math

Use the Matlab code discussed in class to build a simulator forthe digital modulation scheme PPM Coherent. Once finished, run thesimulations required to plot BER curves with a minimum probabilityof bit-error of 10.

1. Plots:

a. ??? vs ??? (??) plot – in the same graph, plot at least 4 BERcurves corresponding to different values of symbol periods andpulse widths.

b. Transmitted signal plot – plot the transmitted signalcorresponding to 3 bits.

c. Received signal plots – for the transmitted signal (3 bits),plot the received noisy signal for at least 4 values of ??? (e.g. 0??, 10 ??, 20 ??, 30 ??) .

Code in Matlab:

% Description: Simple simulator for digital (binary)communications

%% Main Function
function runComm_code()
clear;clc;
  
SNRdB = 0:0.5:26;
nBits = 1e6;
SNRdBLength = length(SNRdB);
Pe = ones(1,SNRdBLength);
clc; disp('Simulation running: 0.0% completed.');
for i = 1:SNRdBLength
Pe(i) = transmitReceive(nBits,SNRdB(i));
clc;fprintf('%s: %.1f%% completed','Simulationrunning',i/SNRdBLength*100);
end
hold on; semilogy(SNRdB,Pe); grid on;
clc; disp('Simulation finished.');
return

%% Bit Transmission Function
function [Perror,nErrors,TxBits,RxBits] =transmitReceive(nBits,SNRdB)
% TxBits = [0 1 1 0 1 0 0 1 1 1];
nBitsMax = 100000;
nBitsOrig = nBits;
TxBits = [];
RxBits =[];
if(nBits > nBitsMax)
n = ceil(nBits/nBitsMax);
nErrorsArr = zeros(1,n);
for i = 1:n
if(nBits < nBitsMax)
[~,nErrorsArr(i),TxBitsTmp,RxBitsTmp] =transmitReceive(nBits,SNRdB);
TxBits = [TxBits,TxBitsTmp];
RxBits = [RxBits,RxBitsTmp];
break;
else
[~,nErrorsArr(i),TxBitsTmp,RxBitsTmp] =transmitReceive(nBitsMax,SNRdB);
TxBits = [TxBits,TxBitsTmp];
RxBits = [RxBits,RxBitsTmp];
nBits = nBits - nBitsMax;
end
end
nErrors = sum(nErrorsArr);
Perror = nErrors/nBitsOrig;
return;
end
  
TxBits = round(rand(1,nBits));
TxSignals = modulation(TxBits);
[RxSignals] = addAWGNoise(TxSignals,SNRdB);
RxBits = demodulation(RxSignals);
errorBits = TxBits ~= RxBits;
nErrors = sum(errorBits);
Perror = nErrors/nBits;
  

return

%% Modulation and Demodulation Functions
function [outSignals,time] = modulation(inBits)

% This code is for On-Off Keying (OOK) modulation
% You need to substitute this with your own Matlab codeaccording
% to your assigned modulation scheme.

pulseWidth = 1e-9;
timeWindow = 10.5e-9;
carrierFreq = 4e9;
  
signalBW = 1.5/pulseWidth;
osFactor = 1 + carrierFreq/signalBW;
  
[signal1,time] = pulseSignal(pulseWidth,timeWindow,osFactor);
signal1 = signal1.*squareSignal(time,carrierFreq);
signalLength = length(signal1);
signal0 = zeros(signalLength,1);
  
inBits = inBits(:)';
nBits = length(inBits);
outSignals = zeros(signalLength,nBits);
col0 = inBits == 0;
col1 = inBits == 1;
outSignals(:,col0) = repmat(signal0,1,sum(col0));
outSignals(:,col1) = repmat(signal1,1,sum(col1));

return
function [outBits] = demodulation(inSignals)
  
% This code is for On-Off Keying (OOK) modulation
% You need to substitute this with your own Matlab codeaccording
% to your assigned modulation scheme.

SNRmin = 10^(12/10);
Ps = sum(modulation(1).^2);
Po = Ps./SNRmin;
  
Psignals = sum(inSignals.^2);
outBits = Psignals > Po;
return

%% Noise Adding Function
function [outSignals,noiseSignals] =addAWGNoise(signals,SNRdB)
signalsSize = size(signals);
SNR = 10^(SNRdB/10);
Ps = max(sum(signals.^2));
Po = Ps./SNR;
noiseSignals =sqrt(Po/2).*randn(signalsSize(1),signalsSize(2));
outSignals = signals+noiseSignals;
return

%% Signal Creation Functions
function [outSignal,time] = pulseSignal(Tp,Tw,osFactor)
if(nargin == 2), osFactor = 1; end
if(osFactor < 1), osFactor = 1; end
B = 1.5/Tp;
fs = osFactor*2*B;
Nw = ceil(fs*Tw);
Np = ceil(fs*Tp);
outSignal = [0; ones(Np,1); zeros(Nw-Np-1,1)];
outSignal(end)=0;
time = (0:length(outSignal)-1)'/fs;
return
function [outSignal] = squareSignal(time,freq)
tsample = time(2)-time(1);
tperiod = 1/freq;
n = ceil(tperiod/tsample);
npos = ceil(n/2);
nneg = n - npos;
Nperiods = ceil(time(end)*freq);
signalTmp = [ones(npos,1); -1*ones(nneg,1)];
outSignal = repmat(signalTmp,Nperiods+1,1);
outSignal = [ 0; outSignal(1:length(time)-1) ];
return

Answer & Explanation Solved by verified expert
3.9 Ratings (511 Votes)
IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU ALL THE BEST Answer Explanation CODE Answer for 1a clc it clears the data clear all clears all the pervious data close all closes    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students