CMC All Exps
CMC All Exps
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 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 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