0% found this document useful (0 votes)
10 views

CMC All Exps

Uploaded by

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

CMC All Exps

Uploaded by

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

Exp 1 Friis free space path loss, log distance and data path loss

1.4.1 Friis Free Space Path loss Model:


clc;
clear all;
close all;
%-----------Input section------------------------
Pt=5; % Transmitted power in dB
Gt=2; % Gain of the Transmitted antenna in dBi
Gr=3; % Gain of the Receiver antenna in dBi
d =1:10:100; % Distance in meters
L=2; % Other System Losses
f=2.4e9; % Transmitted signal frequency in Hertz
lambda=(3*10^8)/f; % Wavelength in meters
Pr=Pt+Gt+Gr+(20)*log10(lambda)-(20)*log10(4*pi*d)-L;
PL=Pt-Pr;
plot(d,PL,'b-*'
,'LineWidth',2);
xlabel("Distance between Transmitter and Receiver (d) in meters");
ylabel("Path loss in dB");
grid on;
1.4.2 Log distance path loss model:
clc;
clear all;
close all;
Pt=5; % Input transmitted power in dB
Gt=3; % Gain of the Transmitted antenna in dBi
Gr=2; % Gain of the Receiver antenna in dBi
f=2.4e9; % Transmitted signal frequency in Hertz
d0=1; % Let’s assume reference distance = 1Km
d=1:0.1:50; % Array of distances to simulate
L=2; % Other System Losses, No Loss case L=1
sigma=2;% Standard deviation of log Normal distribution
n=2; % path loss exponent
lambda=3*10^8/f; % Wavelength in meters
Pr_d0=Pt+Gt+Gr+((20)*log10(lambda))-(20*log10(4*pi*d0))-(10*log10(L));
% Received power at reference distance
PL_d0=Pt-Pr_d0; % Path loss at reference distance
X = sigma*randn(1,numel(d)); % Normal random variable
PL_d1=PL_d0+10*n*log10(d/d0);% Mean Path loss
PL_d2=PL_d0+10*n*log10(d/d0)+X;% Log Distance path loss
plot(d,PL_d1,'r-o');
hold on;
xlabel("Distance between Transmitter and Receiver (d) in Km");
ylabel("Path loss in dB");
plot(d,PL_d2,'b-o');
grid on;
legend('Median Path loss','Path loss due to shadowing');
1.4.3 Hata Path loss Model:
clc;
clear all;
close all;
ht=30; % Height of the transmitter
hr=3; % Height of the receiver
d=1:5:100; % Distance in Km
%---------------------------For small and medium city-------------%
f1=100; % Frequency in MHz
cf_medium=((1.1)*log10(f1)-0.7)*hr-((1.566)*log10(f1)-0.8); %
Correction factor
PL_medium=69.55+((26.26)*log10(f1))-((13.82)*log10(ht))-
(cf_medium)+(44.9-6.55*log10(ht))*log(d); % Path loss
gure(1);
plot(d,PL_medium,'b-*'
,'LineWidth',1)
xlabel("Distance between Transmitter and Receiver (d) in Km");
ylabel("Path loss in dB");
title("Path loss with Hata model for small or Medium city");
grid on;
%----------- For Large city with Frequency<=300MHz——————————
f2=200; % Frequency in MHz
cf_large1=(8.29*(log10(1.54)*hr).^2-1.1); % Correction factor
PL_large1=69.55+(26.26)*log10(f2)-(13.82)*log10(ht)-cf_large1+((44.9-
(6.55)*log10(ht)))*log10(d); % Path loss
gure(2);
plot(d,PL_large1,'r-o','LineWidth',1)
xlabel("Distance between Transmitter and Receiver (d) in Km ");
ylabel("Path loss in dB");
title("Path loss with Hata model for Large city for frequency
<=300MHz");
grid on;
%--------------------For Large city with Frequency >=300MHz
f3=350; % Frequency in MHz
cf_large2=(3.2*(log10(11.75)*hr).^2-4.97); % Correction
factorPL_large2=69.55+(26.26)*log10(f3)-(13.82)*log10(ht)-cf_large2+((44.9-
(6.55)*log10(ht)))*log10(d); % Path loss
gure(3);
plot(d,PL_large2,'m-+','LineWidth',1)
xlabel("Distance between Transmitter and Receiver (d) in Km");
ylabel("Path loss in dB");
title("Path loss with Hata model for Large city for frequency
>=300MHz");
grid on;

Exp2 power delay pro le, fcf and doppler power spectrum

2.4.1 Power Delay Pro le (PDP) and Frequency Correlation Function (FCF):
% Power Delay Pro le (PDP) and Frequency Correlation Function (FCF)
Ps = [0 -2.9 -5.8 -8.7 -11.6]; % list of received powers in dB
Ts = [0 50e-9 100e-9 150e-9 200e-9]; %list of propagation delays
%Plot Power Delay Pro le (PDP)
gure(1);
fi
fi
fi
fi
fi
fi
fi
fi
PDP=stem(Ts,Ps,'linewidth',2);
set(PDP,'basevalue',
-14); %to show the stem plot bottom up
xlabel('Relative delays \tau (s)');
ylabel('Power P(\tau)');
title('Power Delay Pro le');
grid on;
2.4.2 Frequency Correlation Function (FCF):
%Frequency Correlation Function (FCF)
Ps = [0 -2.9 -5.8 -8.7 -11.6]; % list of received powers in dB
Ts = [0 50e-9 100e-9 150e-9 200e-9]; % list of propagation delays
Pi = 10.^(Ps/10); % Power levels in linear scale
nfft = 256; % FFT size
FCF = fft(Pi,nfft)/length(Pi); % Take FFT of PDP
FCF_N = abs(FCF)/max(abs(FCF)); % Normalize
dTau=50e-9; %Spacing of propagation delay in the PDP
f2 = 1/dTau/2*linspace(0,1,nfft/2+1); % X-axis frequency bins
gure (2);
plot(f2,FCF_N(1:nfft/2+1),'r-
'
,'linewidth',2);%FCF plot
title('Frequency Correlation Function');
xlabel('Frequency difference \Delta f (Hz)');
ylabel('Correlation \rho(\Delta f)');
grid on;
2.4.3 Doppler Power Spectrum:
% Doppler Power Spectrum
clc;
clear all;
close all;
fc=1800E6; % Carrier frequency (Hz)
fm=200; % Maximum Doppler shift (Hz)
trms=30e-6; % RMS Delay spread (s)
Plocal = 0.2; % local-mean power (W)
f_delta=fm/30; % Step size for frequency shifts
f=(fc-fm)+f_delta:f_delta:(fc+fm)-f_delta; % Normalized freq shifts
tau=3e-5; % Propagation delays
% Scattering function equation
Z =Plocal./(4*pi*fm*sqrt(1-((f-fc)/fm).^2)).*1/trms.*exp(-tau/trms);
gure;
plot(f,Z,'b-+','linewidth',2);
title('Doppler Power Spectrum');
xlabel('Doppler shift in Hertz');
ylabel(' S(\it f )');
grid on;

Exp 3 rayleigh fading , ricin fading

3.4.1 Rayleigh Fading:


%----Rayleigh_PDF-----------------------------------------
clc;
clear all;
close all;
N=1000000; % Number of samples to generate
variance = 0.2; % Variance of underlying Gaussian random variables
% Independent Gaussian random variables with zero mean and unit variance
fi
fi
fi
x = randn(1, N);
y = randn(1, N);
% Rayleigh fading envelope with the desired variance
r = sqrt(variance*(x.^2 + y.^2));
% De ne bin steps and range for histogram plotting
step = 0.1;
range = 0:step:3;
% Get histogram values and approximate it to get the pdf curve
h = hist(r, range);
SimulatedPDF = h/(step*sum(h)); % Simulated PDF from the x and y samples
% Theoritical PDF from the Rayleigh Fading equation
theoreticalPDF = (range/variance).*exp(-range.^2/(2*variance));
plot(range, SimulatedPDF,'b*', range, theoreticalPDF,'r');
title('PDF of received signal due to Rayleigh Fading')
xlabel('r');
ylabel('Probability Density Function (PDF) ');
grid on;
legend('Simulated PDF','Theoretical PDF’)
3.4.2 Rician Fading:
%Simulate PDF of Rician fading
clc;
clear all;
close all;
N = 10^5; % Number of received signal samples to generate
K_factors = [0 3 7 12]; % Ricean K factors
colors={'b','r','k','g'};
index=1;
for K=K_factors g1 = sqrt(K/(2*(K+1))); % Simulate for each K factors
% Generate variables for K-factors
g2 = sqrt(1/(2*(K+1)));
r1 = (g2*randn(1,N)+g1)+1i*(g2*randn(1,N)+g1); % Generate Rician fading samples
[val,bin] = hist(abs(r1),50); % PDF of envelope the samples
plot(bin,val/trapz(bin,val),[colors{index} 'O']);% Normalized PDF
% Compute theoretical PDF
r2 = 0:0.05:3; % Ricean random variables
Omega=1; % Total average power
z = 2*r2*sqrt(K*(K+1)/Omega); % generate modi ed Bessel function
I0_z= besseli(0,z); % Modi ed Bessel function of rst kind
pdf = (2*r2*(K+1)/Omega).*exp(-K-(r2.^2*(K+1)/Omega)).*I0_z;
hold on;
plot(r2,pdf,colors{index});
index=index+1;
end
title('PDF of received signal due to Rician Fading');
xlabel('r');
ylabel('Probability Density Function (PDF)');
legend('K=0 (Theory)','K=0 (Simulated)','K=3 (Theory)','K=3 (Simulated)','K=7
(Theory)','K=7 (Simulated)','K=12 (Theory)','K=12 (Simulated)');
grid on;

EXP 4 BPSK AND QAM


% Eb/N0 Vs BER for BPSK Modulation over Rayleigh Channel and AWGN
clc;
clear all;
close all;
N=10^6; %Number of BPSK symbols to transmit
d=rand(1,N)>0.5; %binary datax=2*d-1; %BPSK symbols 0->-1, 1->1
fi
fi
fi
fi
EbN0dB=1:1:20; %Range of Eb/N0 values
simBER_rayleigh=zeros(1,length(EbN0dB));
simBER_awgn=zeros(1,length(EbN0dB));
for i=1:length(EbN0dB)
noise=1/sqrt(2)*(randn(1,N)+1i*randn(1,N)); % AWGN noise
n = noise*10^(-EbN0dB(i)/20); %Scaling the noise for required Eb/N0
h=1/sqrt(2)*(randn(1,N)+1i*randn(1,N)); %Rayleigh Flat Fading factor- single tap
y_awgn=x+n; %received signal through AWGN channel
y_rayleigh=h.*x+n; %received signal through Rayleigh channel
%Coherent Receiver for Rayleigh Channel
y_rayleigh_cap=y_rayleigh./h; %Assuming that h is known at the signal accurately
%Receiver for Rayleigh fading channel
r_rayleigh=real(y_rayleigh_cap)>0; %received symbols = 1 is real part > 0 or else
it is 0
%Receiver for AWGN channel
r_awgn=real(y_awgn)>0;
simBER_rayleigh(i)=sum(xor(d,r_rayleigh)); %Finding out bits in error for Rayleigh
simBER_awgn(i)=sum(xor(d,r_awgn)); %Finding out bits in error for AWGN
end
simBER_rayleigh=simBER_rayleigh/N; % Averaging the error per bit in Rayleigh
simBER_awgn=simBER_awgn/N; % Averaging the error per bit in AWGN
% Plotting
semilogy(EbN0dB,simBER_rayleigh,'r*-','LineWidth',2);
hold on;
semilogy(EbN0dB,simBER_awgn,'b+-','LineWidth',2);
axis([1 20 10^-5 1.2]);
legend('Rayleigh','AWGN');
title('Eb/N0 Vs BER for BPSK over Rayleigh and AWGN Channels');
xlabel('Eb/N0(dB)');
ylabel('BER');
grid on;
4.4.2 Bit Error Rate (BER) Performance with QAM:
clc;
clear all;
close all;
N = 100000;
% Range of SNR over which to simulate
Eb_No = 0: 1: 20;% Convert Eb/No values to channel SNR
SNR = Eb_No + 10*log10(Eb_No);
% Start the main calculation loop
for i = 1: 1: length(SNR)
% Initiate variables
T_Errors = 0;
T_bits = 0;
% Keep going until you get 100 errors
while T_Errors < 100
% Generate some random bits
uncoded_bits = round(rand(1,N));
% Split the stream into 4 substreams
B = reshape(uncoded_bits,4,length(uncoded_bits)/4);
B1 = B(1,:);
B2 = B(2,:);
B3 = B(3,:);
B4 = B(4,:);
% 16-QAM modulator
% normalizing factor
a = sqrt(1/10);
% bit mapping
tx = a*(-2*(B3-0.5).*(3-2*B4)-j*2*(B1-0.5).*(3-2*B2));
% Generate Rayleigh Fading Channel
ray = sqrt((1/2)*((randn(1,length(tx))).^2+(randn(1,length(tx))).^2));
% Signal transmission through Rayleigh fading channel
rx = tx.*ray;
% Noise variance
N0 = 1/10^(SNR(i)/10);
% Add Noise
rx = rx + sqrt(N0/2)*(randn(1,length(tx))+1i*randn(1,length(tx)));
% 16-QAM demodulator at the Receiver
a = 1/sqrt(10);
B5 = imag(rx)<0;
B6 = (imag(rx)<2*a) & (imag(rx)>-2*a);
B7 = real(rx)<0;
B8 = (real(rx)<2*a) & (real(rx)>-2*a);
% Merge into single stream again
temp = [B5;B6;B7;B8];
B_hat = reshape(temp,1,4*length(temp));
% Calculate Bit Errors
diff = uncoded_bits - B_hat ;
T_Errors = T_Errors + sum(abs(diff));
T_bits = T_bits + length(uncoded_bits);
end% Calculate Bit Error Rate
BER(i) = T_Errors / T_bits;
end
gure(1);
semilogy(Eb_No,BER,'xr-','Linewidth',2);
xlabel('E_b / N_o (dB)');
ylabel('BER');
title('E_b / N_o Vs BER plot for 16-QAM Modualtion in Rayleigh Channel');
hold on;
theoryBerAWGN = 0.5.*erfc(sqrt((10.^(Eb_No/10))));
semilogy(Eb_No,theoryBerAWGN,'b-+','Linewidth',2);
grid on;
legend('Rayleigh', 'AWGN');
axis([Eb_No(1,1) Eb_No(end) 0.00001 1]);

Exp 5. BPSK modulation


clc;
clear all;
close all;
N = 10^5; % Number of bits
% Transmitter
ip = rand(1,N)>0.5; % Generating 0,1
s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 0
nRx = [1 2];
Eb_N0_dB = [0:15]; % Eb/N0 values
for jj = 1:length(nRx)
for ii = 1:length(Eb_N0_dB)
n = 1/sqrt(2)*[randn(nRx(jj),N) + j*randn(nRx(jj),N)]; % Noise
h = 1/sqrt(2)*[randn(nRx(jj),N) + j*randn(nRx(jj),N)]; % Rayleigh fading
channel
% Channel and Noise addition
sD = kron(ones(nRx(jj),1),s);
y = h.*sD + 10^(-Eb_N0_dB(ii)/20)*n;% Equal gain combining
yHat = y.*exp(-j*angle(h)); % removing the phase of the channel
yHat = sum(yHat,1); % adding values from all the receive chains
% Decoding at the receiver
ipHat = real(yHat)>0;
% counting the errors
fi
nErr(jj,ii) = size( nd([ip- ipHat]),2);
end
end
simBer = nErr/N; % Average BER
gure
semilogy(Eb_N0_dB,simBer(1,:),'ro-','LineWidth',2);
hold on;
semilogy(Eb_N0_dB,simBer(2,:),’bs-','LineWidth',2);
axis([0 15 10^-5 0.5])
grid on
legend(' No. of Receiver=1', 'No. of Receiver=2');
xlabel('Eb/No (dB)');
ylabel('Bit Error Rate (BER)');
title('BER for BPSK modulation with Equal Gain Combining in Rayleigh channel');
5.4.2 Bit Error Rate (BER) Performance with BPSK with Maximal Ratio
Combining (MRC):
clc;
clear all;
close all
N = 10^5; % Number of bits
% Transmitter
ip = rand(1,N)>0.5; % Generating 0,1
s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 0
nRx = [1 2];
Eb_N0_dB = [0:15]; % Eb/N0 values
for jj = 1:length(nRx)
for ii = 1:length(Eb_N0_dB)
n = 1/sqrt(2)*[randn(nRx(jj),N) + j*randn(nRx(jj),N)]; % Noise
h = 1/sqrt(2)*[randn(nRx(jj),N) + j*randn(nRx(jj),N)]; % Rayleigh fading
channel
% Channel and noise Noise addition
sD = kron(ones(nRx(jj),1),s);
y = h.*sD + 10^(-Eb_N0_dB(ii)/20)*n;
% Maximal ratio combining
yHat = sum(conj(h).*y,1)./sum(h.*conj(h),1);% Decoding at receiver
ipHat = real(yHat)>0;
% Counting the errors
nErr(jj,ii) = size( nd([ip- ipHat]),2);
end
end
simBer = nErr/N; % Average BER
gure
semilogy(Eb_N0_dB,simBer(1,:),'ro-','LineWidth',2);
hold on
semilogy(Eb_N0_dB,simBer(2,:),'bs-','LineWidth',2);
axis([0 15 10^-5 0.5])
grid on
legend( 'No. of Receiver=1', 'No. of Receiver=2 ');
xlabel('Eb/No (dB)');
ylabel('Bit Error Rate (BER)');
title('BER for BPSK modulation with Maximal Ratio Combining in Rayleigh channel’);

Exp 6 ISI eye diagram


clc;
clear all;
close all;
% Set the RRC lter, modulation scheme, and plotting parameters.
span = 10; % Filter span
fi
fi
fi
fi
fi
rolloff = 0.2; % Roll off factor
sps = 8; % Samples per symbol
M = 2; % Modulation Order
k = log2(M); % Bits/symbol
phOffset = pi/4; % Phase offset (radians)
n = 1; % Plot every nth value of the signal
offset = pi/4; % Offset value
% Create the lter coef cients using the rcosdesign function.
ltCoeff = rcosdesign(rolloff,span,sps);
% Generate random symbols for an alphabet size of M.
rng default
data = randi([0 M-1],5000,1);
% Apply modulation.
dataMod = pskmod(data,M,phOffset);
% Filter the modulated data.
txSig = up rdn(dataMod, ltCoeff,sps);
% Calculate the SNR for an oversampled QPSK signal.
EbNo = 20;
snr = EbNo + 10*log10(k) - 10*log10(sps);
% Add AWGN to the transmitted signal.
rxSig = awgn(txSig,snr,'measured');
% Apply the RRC receive lter.
rxSigFilt = up rdn(rxSig, ltCoeff,1,sps);
% Demodulate the ltered signal.
dataOut = pskdemod(rxSigFilt,M,phOffset,'gray');
%Eye Diagram: Display 1000 points of the transmitted signal eye diagram over two
symbol periods
eyediagram(txSig(sps*span+1:sps*span+1000),2*sps)
%Display 1000 points of the received signal eye diagram.
eyediagram(rxSig(sps*span+1:sps*span+1000),2*sps)

Exp 7 CDMA

clc;
clear all;
close all;
%------------------ Data Sequence ------------------------------------
data=[1 0 0 1 1 0 1 1];
gure();
subplot(3,1,1);
plot(rectpulse(data,100));
axis([0 length(rectpulse(data,100)) -0.2 1.2]);
title('Message Signal');
xlabel('n');
ylabel('x(n)');
grid on;
% ------------------NRZ form of Data Sequence---------------------------------------------
data(data(:)==0)=-1;
length_data=length(data);
msg=rectpulse(data,100);
subplot(3,1,2);
plot(msg);
title('Message Signal in NRZ form');
xlabel(’n');
ylabel('x(n)');
axis([0 100*length_data -1.2 1.2]);
grid on;
% ------------------BPSK Modulated Data----------------------------------------------------
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
N=length_data; % Length of Data Sequence
T=1;
fc1=10;
tb=1;
Tb = 0.0001; % Time period of one bit
nb=100;% Sampling factor
br = 1/Tb; % Bit rate
Fc = br*10; % Frequency of chip sequence
t2 = Tb/nb:Tb/nb:Tb;
t1=0.01:0.01:length_data;
bpskmod=sqrt(2/T)*cos(2*pi*fc1*t1);
bpsk_data=msg.*bpskmod;
subplot(3,1,3)
plot(bpsk_data)
title(' BPSK signal');
xlabel('Time Period(t)');
ylabel('x(t)');
axis([0 100*length_data -2 2]);
grid on;
% ---------------Generation of Psedo Noise (PN) Sequence---------------------------------------------------
sr=[1 -1 1 -1];
pn1=[];
for i=1:length_data
for j=1:10
pn1=[pn1 sr(4)];
if sr (4)==sr(3)
temp=-1;
else temp=1;
end
sr(4)=sr(3);
sr(3)=sr(2);
sr(2)=sr(1);
sr(1)=temp;
end
end gure();
subplot(3,1,1);
stem(pn1);
axis([0,length(pn1),-1.2,1.2])
title('PN sequence for data')
xlabel('n');
ylabel('x(n)');
grid on;
% ----------------Upsampling of PN sequence-------------------------------------------------------
pnupsampled1=[];
len_pn1=length(pn1);
for i=1:len_pn1
for j=0.1:0.1:tb
pnupsampled1=[pnupsampled1 pn1(i)];
end
end
length_pnupsampled1=length(pnupsampled1);
subplot(3,1,2)
stem(pnupsampled1);
axis([0,length(pnupsampled1),-1.2,1.2])
title('PN sequence for data upsampled');
xlabel('n');
ylabel('x(n)');
grid on;
% -----------------Generation of CDMA data sequence----------------------------------------------------
subplot(3,1,3);
fi
sigtx1=bpsk_data.*pnupsampled1;
plot(sigtx1);
title('CDMA Signal');
xlabel('Time Period(t)');
ylabel('x(t)');
grid on;
%---------------Propagating of CDMA Data sequence in AWGN channel-----
sigtonoise=20;
composite_signal=awgn(sigtx1,sigtonoise);
gure();
subplot(2,2,1);
plot(composite_signal);
title(' CDMA signal through AWGN Channel');xlabel('Time Period(t)');
ylabel('x(t)');
grid on;
%--------------------CDMA Receiver---------------------------------------------------
rx=composite_signal.*pnupsampled1;
subplot(2,2,2);
plot(rx);
title('CDMA Demodulated signal');
xlabel('Time Period(t)');
ylabel('x(t)');
grid on;
%--------------BPSK Demodulation---------------------------------------
y=[];
bpskdemod=rx.*bpskmod;
for i=1:100:size(bpskdemod,2)
y=[y trapz(t1(i:i+99),bpskdemod(i:i+99))];
end
y(y(:)<=0)=-1;
y(y(:)>=0)=1;
rxdata=y;
subplot(2,2,3);
plot(rectpulse(rxdata,100));
axis([0 length(rectpulse(rxdata,100)) -1.2 1.2]);
title('Recieved Message Signal in NRZ');
xlabel('n');
ylabel('x(n)');
grid on;
%---------------------NRZ to Data Sequence-------------------------------------------------
rxdata(rxdata(:)==-1)=0;
rxdata(rxdata(:)==1)=1;
rxmsg=rxdata;
subplot(2,2,4)
plot(rectpulse(rxmsg,100));
axis([0 length(rectpulse(rxmsg,100)) -0.2 1.2]);
title('Recieved Message Signal');
xlabel('n');
ylabel('x(n)');
grid on;

Exp 8 FDMA AND TDMA

%Frequency Division Multiplexing


% Signal Parameters
Fs=25e3;
T=0.02;
t=0:1/Fs:T;
fi
% First Signal
fc1=2500;
ct1=cos(2*pi*fc1*t);
st1=sin(2*pi*100*t);
S1=ct1.*st1;
subplot(3,2,1)
plot(t,S1);
title('Time domain representation of S1');
xlabel('Time duration');
ylabel('Amplitude');
S1fft=abs(fft(S1));
subplot(3,2,2)
plot(t,S1fft);
title('Frequency domain representation of S1');
xlabel('Frequency');
ylabel('Amplitude');
% Second Signal
fc2=1200;
ct2=cos(2*pi*fc2*t);st2=sin(2*pi*50*t);
S2=ct2.*st2;
subplot(3,2,3)
plot(t,S2);
title('Time domain representation of S2');
xlabel('Time duration');
ylabel('Amplitude');
S2fft=abs(fft(S2));
subplot(3,2,4)
plot(t,S2fft);
title('Frequency domain representation of S2');
xlabel('Frequency');
ylabel('Amplitude');
% Third Signal
fc3=3000;
ct3=cos(2*pi*fc3*t);
st3=sin(2*pi*120*t);
S3=ct3.*st3;
subplot(3,2,5)
plot(t,S3);
title('Time domain representation of S3');
xlabel('Time duration');
ylabel('Amplitude');
S3fft=abs(fft(S3));
subplot(3,2,6)
plot(t,S3fft);
title('Frequency domain representation of S3');
xlabel('Frequency');
ylabel('Amplitude');
% Original Message Signals
gure;
subplot(3,1,1);
plot(t,st1);
title('Message signal 1');
xlabel('Time duration');
ylabel('Amplitude');
subplot(3,1,2);
plot(t,st2);
title('Message signal 2');
xlabel('Time duration');
ylabel('Amplitude');
subplot(3,1,3);
fi
plot(t,st3);
title('Message signal 3');
xlabel('Time duration');
ylabel('Amplitude');
% Multilexing all signals
gure;
Xfdm = S1+S2+S3;
subplot(2,1,1)
plot(t,Xfdm);
title('Mulitplexed signal');
xlabel('Time duration');
ylabel('Amplitude');
Xfdm_fft=fftshift(abs(fft(Xfdm,length(Xfdm))));
subplot(2,1,2)
plot(Xfdm_fft);title('Frequency domain Mulitplexed signal');
xlabel('Frequency');
ylabel('Amplitude');
% Bandpass Filter for First signal S1 (2400Hz - 2600Hz)
BPF1=2400:1:2600;
gure
S1_Filtered=conv(BPF1,Xfdm);
subplot(3,2,1)
plot(S1_Filtered);
xlim([0 610]);
title('Filtered rst signal S1');
xlabel('Time duration');
ylabel('Amplitude');
subplot(3,2,2)
S1_Filtered_FFT=fftshift(abs(fft(S1_Filtered,length(S1_Filtered))));
plot(S1_Filtered_FFT);
title('Frequency domain representation of ltered rst signal S1');
xlim([0 610]);
title('Frequency domain ltered Second signal S1');
xlabel('Frequency');
ylabel('Amplitude');
% Bandpass Filter for First signal S2 (1150Hz - 1250Hz)
BPF2=1150:1:1250;
S2_Filtered=conv(BPF2,Xfdm);
subplot(3,2,3)
plot(S2_Filtered);
xlim([0 610]);
title('Filtered Second signal S2');
xlabel('Time duration');
ylabel('Amplitude');
subplot(3,2,4)
S2_Filtered_FFT=fftshift(abs(fft(S2_Filtered,length(S2_Filtered))));
plot(S2_Filtered_FFT);
title('Frequency domain ltered Second signal S2');
xlim([0 610]);
title('Frequency domain ltered Second signal S2');
xlabel('Frequency');
ylabel('Amplitude');
% BPF3 for DSBSC2 bandpass (2880hz - 3120hz)
BPF3=2880:1:3120;
S3_Filtered=conv(BPF3,Xfdm);
subplot(3,2,5)
plot(S3_Filtered);
xlim([0 610]);
title('Filtered Second signal S3');
xlabel('Time duration');
fi
fi
fi
fi
fi
fi
fi
fi
ylabel('Amplitude');
subplot(3,2,6)
S3_Filtered_FFT=fftshift(abs(fft(S3_Filtered,length(S3_Filtered))));
plot(S3_Filtered_FFT);
xlim([0 610]);
title('Frequency domain ltered Second signal S3');
xlabel('Frequency');
ylabel('Amplitude');
% Demodulaton Process After Filteration gure
% Signal 1
S1_Demod=demod(S1,fc1,25e3);
subplot(3,1,1)
plot(t,S1_Demod);
title('Original message signal S1 after Demodulation');
xlabel('Time duration');
ylabel('Amplitude');
% Signal 2
S2_Demod=demod(S2,fc2,25e3);
subplot(3,1,2)
plot(t,S2_Demod);
title('Original message signal S2 after Demodulation');
xlabel('Time duration');
ylabel('Amplitude');
% Signal 3
S3_Demod=demod(S3,fc3,25e3);
subplot(3,1,3)
plot(t,S3_Demod);
title('Original message signal S3 after Demodulation');
xlabel('Time duration');
ylabel('Amplitude');
11.4.2 Time Division Multiplexing (TDM)
% Time Division Multiplexing (TDM)
clc;
close all;
clear all;
% Signal generation
x=0:.5:4*pi;
sig1=8*sin(x); l=length(sig1);
sig2=8*triang(l); % Display of Both Signal
subplot(2,2,1);
plot(sig1);
title('Sinusoidal Signal');
ylabel('Amplitude');
xlabel('Time');
subplot(2,2,2);
plot(sig2);
title('Triangular Signal');
ylabel('Amplitude');
xlabel('Time');
% Display of Both Sampled Signal
subplot(2,2,3);
stem(sig1);
title('Sampled Sinusoidal Signal');
ylabel('Amplitude');
xlabel('Time');
subplot(2,2,4);
stem(sig2);
title('Sampled Triangular Signal');
% Generate 1st Sinusoidal signal
% Generate 2nd Traingular Signalylabel('Amplitude');
fi
fi
xlabel('Time');
l1=length(sig1);
l2=length(sig2);
for i=1:l1
sig(1,i)=sig1(i); sig(2,i)=sig2(i);
end
% TDM of both Quantized signals
tdmsig=reshape(sig,1,2*l1);
% Display of TDM Signal
gure
stem(tdmsig);
title('TDM Signal');
ylabel('Amplitude');
xlabel('Time');
% Demultiplexing of TDM Signal
demux=reshape(tdmsig,2,l1);
for i=1:l1
sig3(i)=demux(1,i); sig4(i)=demux(2,i);
end
% Display of demultiplexed signal
gure
subplot(2,1,1)
plot(sig3);
title('Recovered Sinusoidal Signal');
ylabel('Amplitude');
xlabel('Time');
subplot(2,1,2)
plot(sig4);
title('Recovered Triangular Signal');
ylabel('Amplitude');
xlabel(‘Time');

Exp 9 OFDM
lc;
clear all;
close all;
%% Initializing parameters
L=64; % FFT Length
Ncp=L*(1/4);% Cyclic Pre x
%% Transmitter
% data generation
rng default;
Tx_data=randi([0 15],L,Ncp);
% QAM modulation
mod_data=qammod(Tx_data,16);
%Serial to Parallel Conversion
s2p=mod_data.';
% IFFT Operation
OFDM_IFFT=ifft(s2p);
% Parallel to Series Conversion
p2s=OFDM_IFFT.';
% Cyclic Pre xing
CP_part=p2s(:,end-Ncp+1:end); %Cyclic Pre x part to be appended.
cp=[CP_part p2s];
% Reciever
%Adding Noise using AWGN
c=0;
fi
fi
fi
fi
fi
r=zeros(size(0:1:25));
for snr=0:1:25
c=c+1;
noisy=awgn(cp,snr,'measured');
% Remove cyclic pre x
cpr=noisy(:,Ncp+1:Ncp+Ncp); %remove the Cyclic pre x
% Series to parallel
parallel=cpr.';
% FFT
OFDMdemod=fft(parallel);
% Parallel to serial
rserial=OFDMdemod.';
% QAM demodulation
Umap=qamdemod(rserial,16);
% Calculating the Bit Error Rate
[n, r(c)]=biterr(Tx_data,Umap);
end
%% Plotting BER vs SNR
snr=0:1:25;
semilogy(snr,r,'-ok');
grid;
title('Bit Error Rate (BER) VS Signal To Noise Ratio (SNR)');
ylabel('BER');
xlabel('SNR [dB]');
fi
fi

You might also like