Principles of Communication Engineering Practical
Principles of Communication Engineering Practical
AM
clc;
clear all;
close all;
t=0:0.001:1;
set(0,‘defaultlinelinewidth’,2);
A=5;%Amplitude of signal
fm=input(‘Message frequency=’);%Accepting input value
fc=input(‘Carrier frequency=’);%Accepting input value (f2>f1)
mi=input(‘Modulation Index=’);%Modulation Index
Sm=A*sin(2*pi*fm*t);%Message Signal
subplot(3,1,1);%Plotting frame divided in to 3 rows and this fig appear at 1st
plot(t,Sm);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘Message Signal’);
grid on;
Sc=A*sin(2*pi*fc*t);%Carrier Signal
subplot(3,1,2);
plot(t,Sc);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘Carrier Signal’);
grid on;
Sfm=(A+mi*Sm).*sin(2*pi*fc*t);%AM Signal, Amplitude of Carrier changes to (A+Message)
subplot(3,1,3);
plot(t,Sfm);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘AM Signal’);
grid on;[/cc]
FM
clc;
clear all;
close all;
fm=input(‘Message Frequency=’);
fc=input(‘Carrier Frequency=’);
mi=input(‘Modulation Index=’);
t=0:0.0001:0.1;
m=sin(2*pi*fm*t);
subplot(3,1,1);
plot(t,m);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘Message Signal’);
grid on;
c=sin(2*pi*fc*t);
subplot(3,1,2);
plot(t,c);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘Carrier Signal’);
grid on;
y=sin(2*pi*fc*t+(mi.*sin(2*pi*fm*t)));%Frequency changing w.r.t Message
subplot(3,1,3);
plot(t,y);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘FM Signal’);
grid on;
Message Frequency=25
Carrier Frequency=400
Modulation Index=10
PM
clc;
clear all;
t = 0:0.001:1;
vm = input('Enter the amplitude of message signal = ');
vc = input('Enter the amplitude of carrier signal = ');
fm = input('Enter the message frequency = ');
fc = input('Enter the carrier frequency = ');
m = input('Enter modulation index = ');
sm = vm*sin(2*pi*fm*t);
subplot(3,1,1);
plot(t,sm);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Message Signal');
grid on;
sc = vc*sin(2*pi*fc*t);
subplot(3,1,2);
plot(t,sc);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('Carrier Signal');
grid on;
y = vc*sin(2*pi*fc*t+m.*sin(2*pi*fm*t));
subplot(3,1,3);
plot(t,y);
xlabel('Time ---->');
ylabel('Amplitude ---->');
title('PM Wave');
grid on;
Output:
Enter the amplitude of message signal = 5
Enter the amplitude of carrier signal = 5
Enter the message frequency = 10
Enter the carrier frequency = 100
Enter modulation index = 4
Question no 2.
ASK (binary)
%b is the input binary bit stream
% f is the frequency of the carrier
b= input('Enter the Bit stream\n');
fc=input ('Carrier Frequency=');
n = length (b); %determine the length of bit stream
t= 0: .01: n; %time axis
x=1: 1: (n+1)*100;
for i = 1:n
for j= i:.1:i+1
bw(x(i*100:(i+1)*100)) = b(i); %loop
end
end
bw = bw(100:end); % binary bit stream
carrier = cos (2*pi*fc*t); %carrier signal
modulated = bw.*carrier; %modulated signal
subplot (3, 1, 1)
plot(t,bw)
grid on;
ylabel('amplitude')
xlabel('time')
title('message signal')
subplot(3,1,2)
plot(t, carrier)
grid on;
ylabel('amplitude')
xlabel('time')
title('carrier signal')
subplot(3,1,3)
plot (t, modulated)
grid on;
ylabel('amplitude')
xlabel('time')
title('modulated signal')
for j= i:.1:i+1
bw(x(i*100:(i+1)*100)) = b_p(i); %loop
end
end
bw = bw(100:end); % binary bit stream
wo=3*(2*pi*fc*t);
W=2*(2*pi*fc*t);
sinHt=sin(wo+W)
sinLt=sin(wo-W)
modulated = sin(wo+(bw).*W) %modulated signal
subplot (4, 1, 1)
plot(t,bw)
grid on;
ylabel('amplitude')
xlabel('time')
title('input signal')
subplot(4,1,2)
plot(t, sinHt)
grid on;
ylabel('amplitude')
xlabel('time')
title('High Frequency carrier signal')
subplot(4,1,3)
figure();
subplot(2,1,1)
plot(X);
title(['White noise : \mu_x=',num2str(mu),' \sigma^2=',num2str(sigma^2)])
xlabel('Samples')
ylabel('Sample Values')
grid on;
Question no 6.
%program to generate sine wave
I. Impulse function
n1=input('Lower limit')
n2=input('Upper limit')
x=n1:n2;
y=[x==0];
stem(x,y,);
Output :
Discrete
Output:
Output :
t = linspace(0,3*pi)';
x = square(t);
plot(t/pi,x,'.-',t/pi,sin(t))
xlabel('t / \pi')
grid on
/*Repeat the calculation, but now evaluate square(2*t) at 121 equally spaced numbers
between and . Change the amplitude to . Plot the wave and overlay a sine with the same
parameters. This new wave is negative at and positive at the endpoints.*/
t = linspace(-pi,2*pi,121);
x = 1.15*square(2*t);
plot(t/pi,x,'.-',t/pi,1.15*sin(2*t))
xlabel('t / \pi')
grid on
Unit step signal program
t = (-1:0.01:1)';
impulse = t==0;
unitstep = t>=0;
ramp = t.*unitstep;
quad = t.^2.*unitstep;
IMPULSE SIGNAL
t = (-1:0.01:1)';
impulse = t==0;
unitstep = t>=0;
ramp = t.*unitstep;
quad = t.^2.*unitstep;
All of these sequences are column vectors that inherit their shapes from t. Plot the sequences.
plot(t,[impulse unitstep ramp quad])
Generate and plot a square wave with period 0.5 and amplitude 0.81.
sqwave = 0.81*square(4*pi*t);
plot(t,sqwave)
Calculate Power and to plot Power spectral density
T=10; %Total evaluation time
Ts=0.001; %Sampling time => 1000 samples per second
Fs=1/Ts; % Sampling period
t=[0:Ts:T]; %define simulation time
For energy
x=(1/2)*(1+cos(2*pi*n));
n=-4:1:4;
syms pi
x=(1/2)*(1+cos(2*pi*n))
sum(x)
Question no 8.
Output:
Waveform:
Pulse Width Modulation
[cc lang=”Matlab”]clc;
clear all;
close all;
F2=input(‘Message frequency=’);
F1=input(‘Carrier Sawtooth frequency=’);
A=5;
t=0:0.001:1;
c=A.*sawtooth(2*pi*F1*t);%Carrier sawtooth
subplot(3,1,1);
plot(t,c);
xlabel(‘time’);
ylabel(‘Amplitude’);
title(‘Carrier sawtooth wave’);
grid on;
m=0.75*A.*sin(2*pi*F2*t);%Message amplitude must be less than Sawtooth
subplot(3,1,2);
plot(t,m);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘Message Signal’);
grid on;
n=length(c);%Length of carrier sawtooth is stored to ‘n’
for i=1:n%Comparing Message and Sawtooth amplitudes
if (m(i)>=c(i))
pwm(i)=1;
else
pwm(i)=0;
end
end
subplot(3,1,3);
plot(t,pwm);
xlabel(‘Time’);
ylabel(‘Amplitude’);
title(‘plot of PWM’);
axis([0 1 0 2]);%X-Axis varies from 0 to 1 & Y-Axis from 0 to 2
grid on;[/cc]
Generated PWM Signal
Inputs and Observation:
Message frequency=1
Carrier Saw tooth frequency=10
Pulse position modulation
clc;
clear all;
close all;
fc=1000;
fs=10000;
fm=200;
t=0:1/fs:(2/fm-1/fs);
mt=0.4*sin(2*pi*fm*t)+0.5;
st=modulate(mt,fc,fs,'PPM');
dt=demod(st,fc,fs,'PPM');
figure
subplot(3,1,1);
plot(mt);
title('message signal');
xlabel('timeperiod');
ylabel('amplitude');
axis([0 50 0 1])
subplot(3,1,2);
plot(st);
title('modulated signal');
xlabel('timeperiod');
ylabel('amplitude');
axis([0 500 -0.2 1.2])
subplot(3,1,3);
plot(dt);
title('demodulated signal');
xlabel('timeperiod');
ylabel('amplitude');
axis([0 50 0 1])
Question no 9.
MATLAB Implementation (Simulation) Of Pulse Code Modulation (PCM)
clc
close all
clear all
t = 0:0.0001:20; %sampling at niquist rate
c=input('Enter Bit Depth Of PCM Coding:');
part = -1:0.1:1; %A quantization partition defines several contiguous, nonoverlapping ranges
%of values within the set of real numbers.
codebook = -1:0.1:1.1;% A codebook tells the quantizer which common value to assign to inputs that
%fall into each range of the partition.
msg = cos(t);
[~,quants] = quantiz(msg,part,codebook);%returns a vector that tells which interval each input is in
subplot(3,1,1);
plot(t,msg);
title('Message Signal');
subplot(3,1,2);
plot(t,quants);
title('Quantized Signal');
y = uencode(quants,c);
ybin=dec2bin(y,c); %converting it to final binary form to make it transmit ready
subplot(3,1,3);
plot(t,y);
title('PCM PLOT');
% % Signal Generation
% x=0:1/100:4*pi;
% y=8*sin(x); % Amplitude Of signal is 8v
% subplot(2,2,1);
% plot(x,y);grid on;
% Sampling Operation
x=0:2*pi/n1:4*pi; % n1 nuber of samples have tobe selected
s=8*sin(x);
subplot(3,1,1);
plot(s);
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(3,1,2);
stem(s);grid on; title('Sampled Sinal'); ylabel('Amplitude--->'); xlabel('Time--->');
% Quantization Process
vmax=8;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax; % level are between vmin and vmax with difference of del
code=vmin-(del/2):del:vmax+(del/2); % Contaion Quantized valuses
[ind,q]=quantiz(s,part,code); % Quantization process
% ind contain index number and q contain quantized values
l1=length(ind);
l2=length(q);
for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
i=i+1;
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value inbetween the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,3);
stem(q);grid on; % Display the Quantize values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Encoding Process
figure
code=de2bi(ind,'left-msb'); % Cnvert the decimal to binary
k=1;
for i=1:l1
for j=1:n
coded(k)=code(i,j); % convert code matrix to a coded row vector
j=j+1;
k=k+1;
end
i=i+1;
end
subplot(2,1,1); grid on;
stairs(coded); % Display the encoded signal
axis([0 100 -2 3]); title('Encoded Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
qunt=reshape(coded,n,length(coded)/n);
index=bi2de(qunt','left-msb'); % Getback the index in decimal form
q=del*index+vmin+(del/2); % getback Quantized values
subplot(2,1,2); grid on;
plot(q); % Plot Demodulated signal
title('Demodulated Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
Question no 10.
Eb/No (SNR) Vs BER Curve Plotting for BPSK in AWGN Channel:
clc
clear all
close all
bit_count = 100000; %no. of random bits to be generated for a single shot of BER calculation
SNR = 0: 1: 10; %Range of SNR over which to simulate
for k = 1: 1: length(SNR)
tote = 0; %total error bits
totb = 0; %total bits
while tote < 100 %until you get 100 errors
rbits = round(rand(1,bit_count)); %generate random bits
tx = -2*(rbits-0.5); % BPSK Modulation: Directly to Bipolar NRZ
N0 = 1/10^(SNR(k)/10); %noise level
rx = tx + sqrt(N0/2)*(randn(1,length(tx))+i*randn(1,length(tx)));
rx2 = rx < 0; % BPSK demodulator logic at the Receiver
diff = rbits - rx2; % Calculate Bit Errors
tote = tote + sum(abs(diff)); %total errors
totb = totb + length(rbits); %total bits generated
end
BER(k) = tote / totb; % Calculate Bit Error Rate
end
semilogy(SNR,BER,'*r');
hold on;
xlabel('Eb/No (dB)');
ylabel('BER');
title('Eb/No(SNR) Vs BER plot for BPSK Modualtion in AWGN Channel');
thber = 0.5*erfc(sqrt(10.^(SNR/10))); % Theoretical BER
semilogy(SNR,thber);
grid on;
legend('Simulated Curve', 'Theoretical Curve');