DCT Lab AAT
DCT Lab AAT
COLLEGE OF ENGINEERING
(Autonomous College Affiliated to Visvesvaraya Technological University, Belgaum)
Bull Temple Road, Basavanagudi, Bangalore-560019
NAME USN
SEM: 5
SECTION: C
Course Instructor
Assistant Professor
ECE , BMSCE
SL.NO. TITLE
1) PCM
ALGORITHM:
The three-step algorithm used for PCM is sampling quantization and Encoding.
We are choosing a sampling rate of 500Hz for a time interval of 1 second and
then create 2 sine waves of frequencies 1 and 3Hz. To study the efficiency, we
are doing 4 level and 16 level quantization basically, we are setting the number
of discrete levels and then the output is taken and demodulated and quantization
signal to noise ratio is found for both levels and are compared with the input
sine signal.
CODE:
clc;
clear all;
close all;
td=0.002; %original sampling rate
500 Hz t=0:td:1; %time interval of
1 second
xsig=sin(2*pi*t)-sin(6*pi*t); % 1Hz +3Hz
sinusoids Lsig=length(xsig);
Lfft=2^ceil(log2(Lsig)+1);
Xsig=fftshift(fft(xsig,Lfft));
Fmax=1/(2*td);
Faxis=linspace(-
Fmax,Fmax,Lfft); ts=0.02;
%new sampling rate = 50Hz
Nfact=ts/td;
% send the signal through a 16-level uniform quantizer
[s_out,sq_out,sqh_outl,Delta,SQNR]=sampandquant(xsig,16,td,ts )
; figure(1);
subplot (2,1,1) ;
sfigl=plot(t,xsig,'k',t,sqh_outl(1:Lsig ),'b');
set(sfigl,'Linewidth',2);
title('Signal and its 16 level PCM signal')
xlabel('time(sec.)');
% send the signal through a 4-level uniform quantizer
[s_out,sq
out,sqh_out2,Delta,SQNR]=sampandquant(xsig,4,td,ts);
subplot(212);
sfig2=plot(t,xsig,'k',t,sqh_out2(1:Lsig),'b
'); set (sfig2,'Linewidth',2);
title('Signal and its 4 level PCM signal')
xlabel('time (sec.)');
%Reconstruction of pcm signal
Lfft=2^ceil( log2(Lsig)+1);
Fmax=1/(2*td);
Faxis=linspace(-Fmax,Fmax,Lfft);
SQHl=fftshift(fft(sqh_outl,Lfft));
SQH2=fftshift(fft(sqh_out2,Lfft));
% Now use LPF to filter the two PCM
signals BW=10 ; %Bandwidth is no larger
than lO Hz . H_lpf=zeros(1,Lfft);
H_lpf(Lfft/2-BW:Lfft/2+BW- 1)=1; %ideal LPF
Sl_recv=SQHl.*H_lpf ; % ideal fil ter ing
s_recvl=real(ifft(fftshift(Sl_recv))); % recons tructed f-
domain recvl = s_recvl(1:Lsig) ; % recons truc ted t-domain
S2_recv= SQH2.*H_lpf; % ideal fil tering
s_recv2 =real(ifft(fftshift(S2_recv))); % recons tructed f-
domain s_recv2 = s_recv2 (1:Lsig) ; % reconstructed t-domain
figure (2)
subplot(211);
sfig3=plot(t,xsig,'b-',t,s_recvl(1:Lsig),'b-.');
legend ( ' original ', ' recovered ')
set ( sfig3,'Linewidth',2) ;
title ('Signal and filtered 16-level PCM signal
') xlabel ( ' time( sec . ) ' );
subplot (212);
sfig4=plot(t,xsig,' b-',t,s_recv2(1:Lsig),' b-. ' )
; legend ( ' original ', ' recovered ')
set ( sfig4,'Linewidth',2) ;
title ( ' Signal and filtered 4-level PCM
signal ') xlabel ( ' time(sec.) ' ) ;
function
[s_out,sq_out,sqh_out1,Delta,SQNR]=sampandquant(sig_in,L,t
d,ts)
% L number of uniform quasantization l evels
% sig_in - input signal vector
% td original signal sampling period of sig_in
% s_out = sampled output
% sq_out = sampled and quantized output
% sqh_out = sapmled, quantized and hold output
% delta = quantization interval
% SQNR = actual signal to quantization noise
ratio if(rem((ts/td),1)==0)
nfac=round(ts/td) ;
p_zoh=ones(1,nfac) ;
s_out=downsample(sig_in,nfac)
;
sig_pmax=max(s_out);
sig_nmax=min(s_out);
Delta=(sig_pmax-
sig_nmax)/L;
q_level=sig_nmax+Delta/2 : Delta : sig_pmax-Delta/2 ; %
define Q- levels
L_sig=length(s_out); % find signal length
sigp=(s_out-sig_nmax)/Delta+1/2; % convert into 1/2 to L+ l/2
range qindex=round(sigp); % round to 1,2,..... L levels
qindex=min(qindex,L); % eleminate L+l as a rare possibility
sq_out=q_level(qindex); % use index vector to generate output
SQNR=20*log10(norm(s_out)/norm(s_out-sq_out)); %actual SQNR
value s_out=upsample(s_out,nfac);
sqh_out1=kron(sq_out,p_zoh);
sq_out=upsample(sq_out,nfac);
else
warning ( ' Error ! ts / td is not an integer ! ');
s_out=[ ]; sq_out=[ ]; sqh_out=[ ]; Delta=[ ];
SQNR=[ ]; end
end
WAVEFORMS:
OBSERVATION:
The 16-level quantization has recovered the signal better than the 4 level
quantization with low QSNR. The output demodulated is matching with the
input signal hence PCM is studied for 2 different levels of quantization.
2) DPCM
CODE:
clc
clear all
close all
t=0:0.01:1
; a = 2;
fc = 2;
xsig =
a*sin(2*pi*fc*t);
subplot(6,1,1);
plot(xsig)
title('x(t) = a.*sin(2*pi*fc*t)');
subplot(6,1,2);
q = stem(xsig);
l =zeros(1,100,'int32');
m
=zeros(1,100,'int32');
for N=1:length(t)
m(N)=xsig(N);
end
for N=2:99
if m(N-
1)<m(N)
l(N)=1;
elseif m(N-1)==m(N)
l(N)=0; else
l(N)=-1;
en
d
en
d
title('Sampled Signal');
[index,quants] = quantiz(xsig, [0:0.5:4],[0:0.5:4.5]);
subplot(6,1,3);
stairs(quants
);
subplot(6,1,4
); stairs(l)
title('DPCM Quantized
Signal'); z1 =
dec2bin(abs(l));
z2 = bin2dec(z1);
subplot(6,1,5)
stem(z2);
title('Dequantized
Signal') [b,a] =
butter(2,0.03,'low'); k =
filter(b,a,l);
subplot(6,1,6);
plot(k)
title('Reconstructed Signal');
WAVEFORM:
OBSERVATION:
The input signal is sampled and quantized and at the receiver end it is recovered
which is almost same as the input signal showing good recovering efficiency.
AIM: Obtain Characteristic curve for A Law and Mu Law
CODE:
clc;
clear all;
close all;
% Signal generation
sig = exp(-
4:0.1:4);
V = max(sig);
% Quantization parameters
partition = linspace(0, V, 2^6 - 1); % Partition defines
boundaries codebook = linspace(0, V, 2^6); % Codebook defines
quantization levels
OBSERVATION:
The original quantized and expanded signals of the A law and Mu law are studied
and observed the a law showed good efficiency in the recovering of the signal.
WAVEFORMS:
2. SIMULATION OF TECHNIQUES LEARNT IN MODULE-2:
DIFFERENT MODULATIONS
1) BASK
CODE:
clc;
clear all;
close all;
x=[ 1 0 0 1 1 0 1]; % Binary
Information bp=.000001; % bit period
disp(' Binary information at Trans mitter :');
disp(x);
%XX representation of transmitting binary information as
digital signal XXX
bit=[];
for
n=1:1:length(x)
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit
se]; end
t1=bp/100:bp/100:100*length(x)*(bp/
100); subplot(3,1,1);
plot(t1,bit,'lineWidth',2.5);grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('transmitting information as digital signal');
% Binary-ASK modulation %
A1=10; % Amplitude of carrier signal for information
1 A2=5; % Amplitude of carrier signal for
information 0 br=1/bp; % bit rate
f=br*10; % carrier
frequency
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for
(i=1:1:length(x))
if (x(i)==1)
y=A1*cos(2*pi*f*t2
); else
y=A2*cos(2*pi*f*t2
); end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m);
xlabel('time(sec)');
ylabel('amplitude(volt)')
;
title('waveform for binary ASK modulation coresponding binary
information');
% Binary ASK demodulation
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y=cos(2*pi*f*t); % carrier
siignal mm=y.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z=trapz(t4,mm) % intregation
zz=round((2*z/bp))
if(zz>7.5) % logic level =
(A1+A2)/2=7.5 a=1;
els
e
a=0
;
end
mn=[mn a];
end
disp(' Binary information at Reciver
:'); disp(mn);
% Representation of binary information as digital signal
which achived
%after ASK demodulation
bit=[];
for
n=1:length(mn);
if mn(n)==1;
se=ones(1,100);
else mn(n)==0;
se=zeros(1,100);
end
bit=[bit
se]; end
t4=bp/100:bp/100:100*length(mn)*(bp/
100); subplot(3,1,3)
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('recived information as digital signal after binary ASK
demodulation');
WAVEFORM:
CODE:
clc;
clear all;
close all;
x=[ 1 0 0 1 1 0 1]; % Binary
Information bp=.000001; % bit period
disp(' Binary information at Transmitter :');
disp(x);
%XX representation of transmitting binary information as
digital signal XXX
bit=[];
for
n=1:1:length(x)
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit
se]; end
t1=bp/100:bp/100:100*length(x)*(bp/
100); subplot(3,1,1);
plot(t1,bit,'lineWidth',2.5);grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('transmitting information as digital signal');
% Binary-PSK modulation
A=5; % Amplitude of carrier signal
br=1/bp; % bit rate
f=br*2; % carrier
frequency
t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for
(i=1:1:length(x))
if (x(i)==1)
y=A*cos(2*pi*f*t2)
; else
y=A*cos(2*pi*f*t2+pi); %A*cos(2*pi*f*t+pi) means -
A*cos(2*pi*f*t) end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m);
xlabel('time(sec)');
ylabel('amplitude(volt)')
;
title('waveform for binary PSK modulation coresponding binary
information');
% Binary PSK demodulation
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y=cos(2*pi*f*t); % carrier
siignal mm=y.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z=trapz(t4,mm) % intregation
zz=round((2*z/bp))
if(zz>0) % logic level = (A+A)/2=0
%becouse A*cos(2*pi*f*t+pi) means -
A*cos(2*pi*f*t) a=1;
els
e
a=0
;
end
mn=[mn a];
end
disp(' Binary information at Reciver
:'); disp(mn);
% Representation of binary information as digital signal
which achived
%after PSK demodulation
bit=[];
for
n=1:length(mn);
if mn(n)==1;
se=ones(1,100);
else mn(n)==0;
se=zeros(1,100);
end
bit=[bit
se]; end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(3,1,3)
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('recived information as digital signal after binary PSK
demodulation');
WAVEFORM:
OBSERVATION: We can see that for every change in the bit state there is a
phase shift in there PSK modulated wave the PSK wave is again demodulated
and the obtained output is matching with the input information signal.
QPSK:
ALGORITHM: The Quadrature Phase Shift Keying is similar to BPSK but
instead of 1 phase shift here we are having 4 possible phase shifts that are 0 90
180 270 or it can also be in the form of 45 125 225 and 315. The Quadrature
shit occurs for every di-bits (2 bits).
CODE:
clc;
clear all;
close all;
data=[0 0 1 1 0 1 1 0 1 1 1 0]; % information
figure(1)
stem(data, 'linewidth',3), grid on;
title(' Information before Transmiting
'); axis([ 0 12 0 1.5]);
data_NZR=2*data-1; % Data Represented at NZR form for
QPSK modulation
s_p_data=reshape(data_NZR,2,length(data)/2); % S/P convertion
of data
br=10.^6; %Let us transmission bit rate
1000000 f=br; % minimum carrier frequency
T=1/br; % bit duration
t=T/99:T/99:T; % Time vector for one bit
information y=[];
y_in=[];
y_qd=[];
d=zeros(1,length(data)/2)
; for i=1:length(data)/2
p=data(2*i);
imp=data(2*i - 1);
y1=s_p_data(1,i)*cos(2*pi*f*t); % inphase component
y2=s_p_data(2,i)*sin(2*pi*f*t) ;% Quadrature component
y_in=[y_in y1]; % inphase signal vector
y_qd=[y_qd y2]; %quadrature signal
vector y=[y y1+y2]; % modulated signal
vector
if (imp == 0) && (p == 0)
d(i)=exp(j*pi/4);%45
degrees end
if (imp == 1)&&(p == 0)
d(i)=exp(j*3*pi/4);%135
degrees end
if (imp == 1)&&(p == 1)
d(i)=exp(j*5*pi/4);%225
degrees end
if (imp == 0)&&(p == 1)
d(i)=exp(j*7*pi/4);%315
degrees end
end
Tx_sig=y; % transmitting signal after
modulation qpsk=d;
tt=T/99:T/99:
(T*length(data))/2; figure(2)
subplot(3,1,1);
plot(tt,y_in,'linewidth',3), grid on;
title(' wave form for inphase component in QPSK modulation ');
xlabel('time(sec)');
ylabel(' amplitude(volt0');
subplot(3,1,2);
plot(tt,y_qd,'linewidth',3), grid on;
title(' wave form for Quadrature component in QPSK modulation
'); xlabel('time(sec)');
ylabel(' amplitude(volt0');
subplot(3,1,3);
plot(tt,Tx_sig,'r','linewidth',3), grid on;
title('QPSK modulated signal (sum of inphase and Quadrature
phase signal)');
xlabel('time(sec)');
ylabel('
amplitude(volt0');
figure(3);
plot(d,'o');%plot constellation without
noise axis([-2 2 -2 2]);
grid on;
xlabel('real'); ylabel('imag');
title('QPSK constellation');
OBSERVATION: From the input waveform the in phase and quadrature phase
waveform is generated from which the QPSK modulated signal is generated the
obtained constellation diagram is matching with the theoretical diagram.
WAVEFORM:
2) BFSK
ALGORITHM: In BFSK the frequency of the carrier wave is changed with the
binary data such that say f2 for logic 1 and f1 for logic 0 keeping the amplitude
and the phase constant.
CODE:
clc;
clear all;
x=[ 1 0 0 1 1 0 1]; % Binary
Information bp=.000001; % bit period
disp(' Binary information at Trans mitter :');
disp(x);
% representation of transmitting binary information as
digital signal
bit=[];
for
n=1:1:length(x)
if x(n)==1;
se=ones(1,100);
else x(n)==0;
se=zeros(1,100);
end
bit=[bit
se]; end
t1=bp/100:bp/100:100*length(x)*(bp/
100); subplot(3,1,1);
plot(t1,bit,'lineWidth',2.5);grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('transmitting information as digital signal');
% Binary-FSK modulation
A=5; % Amplitude of carrier signal
br=1/bp; % bit rate
f1=br*8; % carrier frequency for information
as 1 f2=br*2; % carrier frequency for
information as 0 t2=bp/99:bp/99:bp;
ss=length(t2);
m=[];
for
(i=1:1:length(x))
if (x(i)==1)
y=A*cos(2*pi*f1*t2
);
else
y=A*cos(2*pi*f2*t2
); end
m=[m y];
end
t3=bp/99:bp/99:bp*length(x);
subplot(3,1,2);
plot(t3,m);
xlabel('time(sec)');
ylabel('amplitude(volt)')
;
title('waveform for binary FSK modulation corresponding binary
information');
% Binary FSK demodulation
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y1=cos(2*pi*f1*t); % carrier signal for
information 1 y2=cos(2*pi*f2*t); % carrier
signal for information 0 mm=y1.*m((n-(ss-1)):n);
mmm=y2.*m((n-(ss-1)):n);
t4=bp/99:bp/99:bp;
z1=trapz(t4,mm) %
integration z2=trapz(t4,mmm)
% intregation
zz1=round(2*z1/bp)
zz2= round(2*z2/bp)
if(zz1>A/2) % logic lavel= (0+A)/2 or (A+0)/2 or 2.5 (
in this case)
a=1;
else(zz2>A/
2) a=0;
end
mn=[mn a];
end
disp(' Binary information at Reciver
:'); disp(mn);
% Representation of binary information as digital signal
which achived
%after demodulation
bit=[];
for
n=1:length(mn);
if mn(n)==1;
se=ones(1,100);
else mn(n)==0;
se=zeros(1,100);
end
bit=[bit
se]; end
t4=bp/100:bp/100:100*length(mn)*(bp/
100); subplot(3,1,3)
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('recived information as digital signal after binary FSK
demodulation');
WAVEFORMS:
1) BASK
CODE:
clc;
clear all;
close all;
num_bit=1000;%number of bit data=randi(1,num_bit);
%random bit generation (1 or 0) SNRdB=0:10; % SNR
in dB
SNR=10.^(SNRdB/10);
for(k=1:length(SNRdB))%BER (error/bit) calculation for different
SNR
%
y=awgn(complex(data),SNRdB(k)
); error=0;
R=0;
M=[]
;
for(c=1:1:num_bit)
if (y(c)>.5&&data(c)==0)||(y(c)<.5&&data(c)==1)%logic
acording to BASK
error=error+1
; M=[M
~data(c)];
else
M=[M
data(c)]; end
end
error=error/num_bit; %Calculate
error/bit m(k)=error;
end
figure;
semilogy(SNRdB,m,'o','linewidth',2.5),grid on,hold on;
BER_th=(1/2)*erfc(.5*sqrt(SNR));
semilogy(SNRdB,BER_th,'r','linewidth',2.5),grid on,hold
on; title(' curve for Bit Error Rate verses SNR for
Binary ASK modulation');
xlabel(' SNR(dB)');
ylabel('BER');
legend('simulation','theorytical
') axis([0 10 10^-5 1]);
WAVEFORM:
OBSERVATION: The theoretical bit error rate of ASK and the SNR for the
binary ASK modulated wave is compared and the values are matching.
2) BPSK
CODE:
WAVEFORM:
OBSERVATION: The theoretical bit error rate of BPSK and the SNR for the
binary PSK modulated wave is compared and the values are matching.
3) QPSK
CODE:
clear
all;
close
all;
l=10000;
snrdb=1:1:10;
snrlin=10.^(snrdb/10);
for snrdb=1:1:10
si=2*(round(rand(1,l))-0.5);
sq=2*(round(rand(1,l))-
0.5); s=si+j*sq;
w=awgn(s,snrdb,'measured')
; r=w;
si_=sign(real(r));
sq_=sign(imag(r));
ber1=(l-
sum(si==si_))/l;
ber2=(l-
sum(sq==sq_))/l;
ber(snrdb)=mean([ber1
ber2]); end
%semilogy(snrdb, ber,'o-')
snrdb=1:1:10;
snrlin=10.^(snrdb./10);
tber=0.5.*erfc(sqrt(snrlin));
semilogy(snrdb,ber,'-bo',snrdb,tber,'-mh')
title('QPSK with awgn');
xlabel('Signal to noise
ratio'); ylabel('Bit error
rate');
legend('simulation','theoretical
') grid on;
OBSERVATION: The theoretical bit error rate of QPSK and the SNR for
QPSK modulated wave is compared and the values are matching.
WAVEFORM:
4) BFSK
CODE:
clear
all;
close
all; N =
1000;
m = randi([0,1],1,N);
%% BFSK
Modulation for
i=1:N
if m(i)==0
x(i)=sqrt(-
1); else
x(i)=1;
end
end
figure;
scatterplot(x);
%% AWGN Channel and Reception
ber_sim=[];
ber_th=[];
for EbN0dB=0:1:15
EbN0=10^(EbN0dB/10);
sigma=sqrt(1/(EbN0));
n=(1/sqrt(2))*[randn(1,N)+sqrt(-
1)*randn(1,N)];
%Received Signal
%r=x+sigma.*n; %AWGN Channel
r=awgn(complex(x),EbN0dB);
scatterplot(r);
% Randn generates gaussian distribution of noise
% Decision device
m_cap=(real(r)>imag(r));
% BER calculation
noe=sum(m~=m_cap); %Returns the count of where m is not equal
to m_cap
% returns the number of operations
ber_sim1=noe/N;
ber_sim=[ber_sim ber_sim1];
ber_th1=0.5*erfc(sqrt(EbN0/2));
ber_th=[ber_th ber_th1];
end
%% Plot BER vs EbN0 Actual
EbN0dB=0:1:15;
figure;
semilogy(EbN0dB,ber_sim,'r*-',EbN0dB,ber_sim,'bo
-'); xlabel('EbN0 (dB)');
ylabel('BER');
legend('Simulation','Theoritical
'); grid on;
WAVEFORM:
OBSERVATION: The theoretical bit error rate of BFSK and the SNR for the
binary FSK modulated wave is compared and the values are matching.
Direct Sequence Spread Signal:
Algorithm: The algorithm is as follows the input bit sequence is first multiplied
by a randomly generated pseudo noise sequence using shift registers with
feedback then this obtained signal is modulated using the BPSK modulator here
the bit rate of the PSN should always be greater than the bit rate of the input
signal.
CODE:
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;
en
d
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...');
WAVEFORM:
OBSERVATION: The binary data is multiplied with the pseudo noise signal
and the obtained output is multiplied with the carrier wave to get the output DS-
SS signal as shown in the diagram.
Frequency Hop Spread Spectrum:
Algorithm: There are 2 types of frequency hop fast frequency hop and slow
frequency hop spectrum in fast frequency hop for every bit of data multiple
hops are done where as in slow frequency for every hop multiple bits are taken
So we are generating random carrier frequency which gets added to the original
carrier frequency of the binary data we are implementing mixture of fast
frequency hop and slow frequency hops so for every bit we are adding multiple
hops or multiple data for one hop to the base carrier frequency and the output is
obtained which is then demodulated to recover the original message signal
CODE:
clear
;
clc;
for k = 1:25
if s(k) == 0
% Creating 120 samples of -1 for
bit 0 sig = -ones(1, 120);
else
% Creating 120 samples of 1 for bit
1 sig = ones(1, 120);
end
c = cos(t); % Carrier
wave carrier = [carrier
c]; signal = [signal
en sig];
d
subplot(2, 1, 2);
fft_result = abs(fft(freq_hopped_sig));
plot(fft_result, 'LineWidth', 1.5);
title('\bf\it FFT of Frequency Hopped
Signal'); xlabel('Frequency Index');
ylabel('Amplitude');
WAVEFORMS:
OBSERVATIONS: the data signal is pulse modulated then multiplied with the
randomly generated carrier frequency as described in the algorithm the FFT of
the obtained spreaded frequency indicates a low power wideband noise signal to
an unintended receiver
HUFFMAN CODING:
ALGORITHM: We arrange the given probabilities into descending order and
then logic one and 0 are given to the smallest probability and the adjacent small
probability then those two are added and sorted such that if there are
probabilities similar to the added then added will be placed in the highest and
this continues till all the numbers are added to get 1.
CODE:
clc;
close all;
clear all;
% While there is more than one set, combine the least probable
sets while length(set_contents) > 1
% Sort the sets based on probabilities (ascending
order) [temp, sorted_indices] =
sort(set_probabilities);
zero_set = set_contents{sorted_indices(1)}; %
Smallest set zero_probability =
set_probabilities(sorted_indices(1));
set_probabilities(sorted_indices(2));
OUTPUT:
NTERPRETATION: The obtained output and the codes for the symbols is
matching with the calculated output using the algorithm
SHANNON FANO CODING:
ALGORITHM: In this method we are again arranging the probabilities into
descending order then we are creating 2 sets called zero sets and one sets such
that the sum of the probabilities in each set will be almost equal or must be such
that the difference between them must be minimum amongst all combinations.
This is done until every set has only one element
CODE:
% MATLAB code for Shannon-Fano
coding clc;
close all;
clear all;
% Normalize probabilities
% Initialization of
variables sta = [];
ar = [];
coded = [];
other = [];
first = 0;
final =
length(probability_vec); sta
= [first final];
% Algorithmic logic for Shannon-Fano coding
for f = 1:length(probability_vec) % Loop for every
step other = [];
ar = [];
for h = 1:(length(sta) - 1) % Loop for each sub-
group first = sta(h) + 1;
final = sta(h +
1); if (first >=
final)
other = [other; 2]; % When only one element in a sub-
grou
p continue;
en
d
asum = 0;
difmat = [];
for i = first:final % Loop for finding difference
vector asum = asum + probability_vec(i);
resum = 0;
for j = i + 1:final
resum = resum + probability_vec(j);
end
dif = abs(asum - resum);
difmat = [difmat dif];
end
small =
min(difmat);
k = 1;
for i = first:final % Loop for finding index of
min difference
if (small ==
difmat(k)) break;
end
k = k + 1;
end
index = i;
ar = [ar index]; % Storing index in temporary stack
ind = (index + 1) - first; % Calculating number of
zeros remind = final - index; % And ones for each
sub-group other = [other; zeros(ind, 1);
en ones(remind, 1)];
d
sta = [ar sta]; % Creating final stack for each
step sta = sort(sta);
coded = [coded other]; % Creating final codeword matrix
if (length(sta) > length(probability_vec)) % Break when all
subgroups have one element
break;
end
end
% Display codewords
codewords = cell(1, length(probability_vec)); %
Initialize codewords cell array
len = [];
for i =
1:length(probability_vec)
word = [];
for j = 1:f % 'f' contains max number of bits among codes
if (coded(i, j) == 2) % Break when invalid number
(i.e. 2) is reached
break;
end
word = [word coded(i, j)];
end
len = [len length(word)]; fprintf('\
nSymbol %d code - ', i); disp(word);
codewords{i} = word;
en
d
% Calculation of entropy and average word
length ent = 0;
av_length = 0;
for i = 1:length(probability_vec)
ent = ent + (probability_vec(i) * log2(1 /
probability_vec(i)));
av_length = av_length + len(i) * probability_vec(i);
end
% Calculation of efficiency
eff = (ent / av_length) *
100;
% Calculation of variance
variance_val = 0;
for ind = 1:length(codewords)
variance_val = variance_val + probability_vec(ind) *
(length(codewords{ind}) - av_length)^2;
end
OUTPUT:
INTERPRETATION:
The output obtained from the matlab is matching with the output traced using the
algorithm as mentioned above hence the data has been coded successfully