AkanshaKhandelwalMCA (SE) 2ndsem
AkanshaKhandelwalMCA (SE) 2ndsem
AkanshaKhandelwalMCA (SE) 2ndsem
MENTOR: MENTEE:
t=0:Ts:(T*M);
carh=sin(2*pi*t*fh); %High frequency carrier for data bit 1
carl=sin(2*pi*t*fl); %Low frequency carrier for data bit 0
modSig=[];
for i=1:length(data)
if(data(i)==1)
modSig=[modSig carh];
else
modSig=[modSig carl];
end
end
subplot(3,1,3);
plot(modSig,'b');
xlabel('Samples(FSK Modulated signal)');
ylabel('Amplitude');
totalBits=length(rx)/length(tp);
sdiff=0;
noofzeros=0;
zeroSample=[];
k=1;
for i=1:totalBits
for j=1:length(tp)
if(sdiff>sampleValue)
if(rx(1,k)>0)
positive=1;
end
if(rx(1,k)<0)
negative=1;
end
end
k=k+1;
sdiff=sdiff+1;
if(positive==1 && negative==1)
noofzeros=noofzeros+1;
positive=0;
sdiff=0;
negative=0;
end
end
zeroSample=[zeroSample noofzeros];
noofzeros=0;
end
firstZeroSample=zeroSample(1,1);
zeroSample=zeroSample/firstZeroSample;
clc;
close all;
clear all;
b=input('Enter The input Bits : ');
ln=length(b);
% Converting bit 0 to -1
for i=1:ln
if b(i)==0
b(i)=-1;
end
end
% Generating the bit sequence with each bit 8 samples long
k=1;
for i=1:ln
for j=1:8
bb(k)=b(i);
j=j+1;
k=k+1;
end
i=i+1;
end
len=length(bb);
subplot(2,1,1);
stairs(bb,'linewidth',2); axis([0 len -2 3]);
title('ORIGINAL BIT SEQUENCE b(t)');
% Generating the pseudo random bit pattern for spreading
pr_sig=round(rand(1,len));
for i=1:len
if pr_sig(i)==0
pr_sig(i)=-1;
end
end
subplot(2,1,2);
stairs(pr_sig,'linewidth',2); axis([0 len -2 3]);
title('PSEUDORANDOM BIT SEQUENCE pr_sig(t)');
% Multiplying bit sequence with Pseudorandom Sequence
for i=1:len
bbs(i)=bb(i).*pr_sig(i);
end
% Modulating the hopped signal
dsss=[];
t=0:1/10:2*pi;
c1=cos(t);
c2=cos(t+pi);
for k=1:len
if bbs(1,k)==-1
dsss=[dsss c1];
else
dsss=[dsss c2];
end
end
figure,
subplot(2,1,1);
stairs(bbs,'linewidth',2); axis([0 len -2 3]);
title('MULTIPLIER OUTPUT SEQUENCE b(t)*pr_sig(t)');
subplot(2,1,2);
plot(dsss);
title(' DS-SS SIGNAL...');
%Frequency Hopping Spread Spectrum
clc
clear
% Generation of bit pattern
s=round(rand(1,25)); % Generating 20 bits
signal=[];
carrier=[];
t=[0:2*pi/119:2*pi]; % Creating 60 samples for one cosine
for k=1:25
if s(1,k)==0
sig=-ones(1,120); % 120 minus ones for bit 0
else
sig=ones(1,120); % 120 ones for bit 1
end
c=cos(t);
carrier=[carrier c];
signal=[signal sig];
end
subplot(4,1,1);
plot(signal);
axis([-100 3100 -1.5 1.5]);
title('\bf\it Original Bit Sequence');
% BPSK Modulation of the signal
bpsk_sig=signal.*carrier; % Modulating the signal
subplot(4,1,2);
plot(bpsk_sig)
axis([-100 3100 -1.5 1.5]);
title('\bf\it BPSK Modulated Signal');
% Preparation of 6 new carrier frequencies
t1=[0:2*pi/9:2*pi];
t2=[0:2*pi/19:2*pi];
t3=[0:2*pi/29:2*pi];
t4=[0:2*pi/39:2*pi];
t5=[0:2*pi/59:2*pi];
t6=[0:2*pi/119:2*pi];
c1=cos(t1);
c1=[c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1 c1];
c2=cos(t2);
c2=[c2 c2 c2 c2 c2 c2];
c3=cos(t3);
c3=[c3 c3 c3 c3];
c4=cos(t4);
c4=[c4 c4 c4];
c5=cos(t5);
c5=[c5 c5];
c6=cos(t6);
% Random frequency hopps to form a spread signal
spread_signal=[];
for n=1:25
c=randint(1,1,[1 6]);
switch(c)
case(1)
spread_signal=[spread_signal c1];
case(2)
spread_signal=[spread_signal c2];
case(3)
spread_signal=[spread_signal c3];
case(4)
spread_signal=[spread_signal c4];
case(5)
spread_signal=[spread_signal c5];
case(6)
spread_signal=[spread_signal c6];
end
end
subplot(4,1,3)
plot([1:3000],spread_signal);
axis([-100 3100 -1.5 1.5]);
title('\bf\it Spread Signal with 6 frequencies');
% Spreading BPSK Signal into wider band with total of 12 frequencies
freq_hopped_sig=bpsk_sig.*spread_signal;
subplot(4,1,4)
plot([1:3000],freq_hopped_sig);
axis([-100 3100 -1.5 1.5]);
title('\bf\it Frequency Hopped Spread Spectrum Signal');
% Expressing the FFTs
figure,subplot(2,1,1)
plot([1:3000],freq_hopped_sig);
axis([-100 3100 -1.5 1.5]);
title('\bf\it Frequency Hopped Spread Spectrum signal and its FFT');
subplot(2,1,2);
plot([1:3000],abs(fft(freq_hopped_sig)));
iqScope([QBranchUpsampled,IBranchUpsampled]);
repeatFactor = 4;
% Repeat the generated BPSK signal to see the adjacent bands spectrum
updata = repmat(gpsBBWaveform(:).',repeatFactor,1);
updata = updata(:);
bbscope = dsp.SpectrumAnalyzer('SampleRate',10*1.023e6*repeatFactor, ...
'PlotAsTwoSidedSpectrum',true, ...
'SpectrumType','Power density', ...
'AveragingMethod','Exponential', ...
'SpectrumUnits','dBW', ...
'YLimits',[-120,-50], ...
'Title','Power Spectral Density of Complex Baseband GPS Signal');
bbscope(updata);
end
Question 7: Softhandover and hardhandover
%SoftHandover Probablity
x=1:.1:10;
z=10.^(x/33.6);
w=(z+1).^2
y=1-(4./w);
plot (x,y)
xlabel('SHO Threshold (dB)')
ylabel('SHO Probability')
title('SHO Probability as a function of the Threshold Value')
grid
EsNo=EsNoRange(EsNoIndex);
disp(['Simulating: EsNo=' num2str(EsNo) 'dB']);
SNR=EsNo+10*log10(1/SpreadingRate)+10*log10(1/SamplesPerChip);
% Initialize system and simulation measurements state
% Bits
TotalBits= false; % Bit count for BER calculation
ErrorBits=false; % Error count for BER calculation
LastTxSymbol=1; % Set DBPKS Modulator state
LastRxSymbol=1; % Set DBPKS Demodulator state
% Filters
Rx_chips_delayed_store=zeros(ChipDelayAdd,1);
Tx_bits_delayed_store=true;
Tx_Filter_State=h(1:end-1); % Fill filter with a +1 symbol
Rx_Filter_State=h(1:end-1); % Fill filter with a +1 symbol
% Main simulation loop
% Each packet is transmitted, and the recieved bits compared with the
% transmitted bits to calculate the BER.
for Packet=1:NumPackets
% Construct frame of bits
Tx_bits=rand(PacketSizeBits,1)>.5; % Random bits
% Modulate
Tx_bits_bp=(1-2*Tx_bits); % Convert to bipolar 0,1 --> 1,
-1
Tx_symbols=LastTxSymbol*cumprod(Tx_bits_bp); % New DBPSK symbol = previous *
1 or -1
LastTxSymbol=Tx_symbols(end); % Store modulator state (last
symbol)
% Spread symbols with Barker code, upsampling by spreading rate
Tx_chips=reshape(Barker*Tx_symbols',[],1); % Multiply by barker and reshape
to a columm
Tx_chips=complex(Tx_chips); % Make complex to ensure correct baseband
transmission
% Upsample chips by SamplesPerChip factor
Tx_samples=zeros(length(Tx_chips)*SamplesPerChip,1); % Create empty
Tx_samples
Tx_samples(1:SamplesPerChip:end,1)=sqrt(SamplesPerChip)*Tx_chips; % Normalize
power due to upsampling
% Tx Filter
[Tx_samples_filtered,Tx_Filter_State]=filter(h,1,Tx_samples,Tx_Filter_State);
% Filter
Tx_samples_filtered=Tx_samples_filtered*2.495; % Set output power to 1W
var(Tx_samples_filtered); % Calculate Tx signal power, view by removing ';'
% Transmit though AWGN Channel assuming 0dBW input power (check
% with line above)
Rx_samples_unfiltered = awgn(Tx_samples_filtered,SNR,0);
% Rx Filter
[Rx_samples_filtered,Rx_Filter_State]=filter(h,1,Rx_samples_unfiltered,Rx_Filter_Stat
e);
% Downsample - sample chips
Rx_chips=Rx_samples_filtered(1:SamplesPerChip:end);
% Add 1 chip delay to move signal to 11 chip boundary
Rx_chips_delayed=[Rx_chips_delayed_store; Rx_chips(1:end-ChipDelayAdd)];
Rx_chips_delayed_store=Rx_chips((end-ChipDelayAdd+1):end); % Store delayed
chips
% Despread - sample symbol
Rx_symbols=Barker'*reshape(Rx_chips_delayed,SpreadingRate,PacketSizeBits); %
Multiply by Barker
Rx_symbols=Rx_symbols(:)/SpreadingRate; % Make a column and normalize
% Demodulate
Rx_symbols_plus_last=[LastRxSymbol; Rx_symbols];
Rx_symbols_plus_last_mult=Rx_symbols_plus_last(1:end-
1).*conj(Rx_symbols_plus_last(2:end));
Rx_bits=Rx_symbols_plus_last_mult < 0;
LastRxSymbol=Rx_symbols(end); % Demodulator state
% Calculate BER
% Add BitDelay to Tx signal to align with Rx signal
Tx_bits_delayed=[Tx_bits_delayed_store; Tx_bits(1:end-BitDelay)];
Tx_bits_delayed_store=Tx_bits(end-BitDelay+1:end); % Store delayed symbol
if Packet==1 % Ignore delayed bits on first packet
TotalBits=TotalBits+length(Rx_bits)-BitDelay;
ErrorBits=ErrorBits+sum(Tx_bits_delayed(BitDelay+1:end)~=Rx_bits(BitDelay+1:end));
else
TotalBits=TotalBits+length(Rx_bits); % Calculate total bits
ErrorBits=ErrorBits+sum(Tx_bits_delayed~=Rx_bits); % Compare Tx and Rx
bits
end
end
BERResults(EsNoIndex)=ErrorBits/TotalBits; % Calculate BER
end
%% Plot BER Results
% Plot the BER results Vs EsNo.
semilogy(EsNoRange,BERResults,'*-');
grid;
title('802.11b 1Mbps');
ylabel('BER')
xlabel('EsNo');