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

Lab Manual Pcs(Bec402)

The document covers various principles of communication systems, including basic signal types such as unit step, sine, cosine, exponential, triangular, and rectangular waveforms. It also discusses signal representation in time and frequency domains, AM and FM modulation and demodulation, sampling, low-pass filtering, time division multiplexing, PCM sampling, quantization, and encoding. Additionally, it includes the generation of NRZ, RZ, and raised cosine waveforms, as well as the probability density function of Gaussian distribution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Lab Manual Pcs(Bec402)

The document covers various principles of communication systems, including basic signal types such as unit step, sine, cosine, exponential, triangular, and rectangular waveforms. It also discusses signal representation in time and frequency domains, AM and FM modulation and demodulation, sampling, low-pass filtering, time division multiplexing, PCM sampling, quantization, and encoding. Additionally, it includes the generation of NRZ, RZ, and raised cosine waveforms, as well as the probability density function of Gaussian distribution.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

PRINCIPLES OF COMMUNICATION SYSTEM (BEC402)

1. Basic signals and signal graphing


a. UNIT STEP SIGNAL:

clc;
clear all;
close all;
t = -5 : 0.1 : 5;
u1 = zeros(size(t));
u1(t >= 0) = 1;
u2 = zeros(size(t));
u2(t >= 2) = 1;
figure;
subplot(2, 1, 1);
plot(t, u1);
xlabel('Time');
ylabel('Amplitude');
title('Unit Step Signal (t>=0)');
subplot(2, 1, 2);
plot(t, u2);
xlabel('Time');
ylabel('Amplitude');
title('Unit Step Signal (t>=2)');

b. SINE AND COSINE WAVEFORM:


clc;
clear all;
close all;
f = 5;
T = 1/f;
t = 0 : 0.0001 : T;
A = 2;
x = A * sin(2*pi*f*t);
y = A * cos(2*pi*f*t);
figure;
subplot(2, 1, 1);
plot(t, x, 'r');
xlabel('Time');
ylabel('Amplitude');
title('Sine Wave Signal');
subplot(2, 1, 2);
plot(t, y, 'r');
xlabel('Time');
ylabel('Amplitude');
title('Cosine Wave Signal');

c. EXPONENTIAL WAVEFORM:
clc;
clear all;
close all;
t = 0 : 0.001 : 4;
A = 5;
a = 0.7;
b = 0.6;
x = A * exp(a * t);
y = A * exp(-b * t);
figure;
subplot(2, 1, 1);
plot(t, x);
xlabel('Time');
ylabel('Amplitude');
title('Growing Exponential Signal');
subplot(2, 1, 2);
plot(t, y);
xlabel('Time');
ylabel('Amplitude');
title('Decaying Exponential Signal');

d. TRIANGULAR WAVEFORM:
clc;
clear all;
close all;
T = 10*(1/50);
fs = 1000;
t = 0:1/fs: T-1/fs;
x = sawtooth(2*pi*50*t,1/2);
plot(t,x);
grid on;

e. RECTANGULAR SIGNAL:
clc;
clear all;
close all;
A = 1;
T = 1;
Fs = 1000;
t = 0:1/Fs:5;
duty_cycle = 50;
x = A * square(2 * pi * (1/T) * t, duty_cycle);
figure;
plot(t, x);
title('Rectangular Wave in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
2. SIGNAL REPRESENTATION IN TIME AND FREQUENCY DOMAIN OF
RECTANGULAR PULSE:
clc;
clear all;
close all;
T = 1;
Fs = 1000;
t = -2:1/Fs:2;
rect_pulse = double(abs(t) <= T/2);
n = length(t);
f = (-n/2:n/2-1)*(Fs/n);
Rect_pulse_fft = fftshift(fft(rect_pulse)/n);
figure;
subplot(2,1,1);
plot(t, rect_pulse);
title('Rectangular Pulse in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
plot(f, abs(Rect_pulse_fft));
title('Magnitude Spectrum of Rectangular Pulse');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;

3. AM Modulation and demodulation


clc;
clear all;
close all;
Fs=10000;
t=0:1/Fs:0.1;
fc=1000;
Am=1;
Ac=1;
fm=50;
m=Am*cos(2*pi*fm*t);
c=Ac*cos(2*pi*fc*t);
s=(1+m).*c;
s_demod=s.*(2*cos(2*pi*fc*t));
[b,a]=butter(5,fm/(Fs/2));
m_rec=filter(b,a,s_demod);
n=length(t);
f=(-n/2:n/2-1)*(Fs/n);
M=fftshift(fft(m)/n);
C=fftshift(fft(c)/n);
S=fftshift(fft(s)/n);
M_rec=fftshift(fft(m_rec)/n);
figure;
subplot(4,1,1);
plot(t,m);
title('message signal(time domain)');
xlabel('time(s)');
ylabel('amplitude');
grid on;
subplot(4,1,2);
plot(t,c);
title('carrier signal(time domain)');
xlabel('time(s)');
ylabel('amplitude');
grid on;
subplot(4,1,3);
plot(t,s);
title('am signal(time domain)');
xlabel('time(s)');
ylabel('amplitude');
grid on;
subplot(4,1,4);
plot(t,m_rec);
title('recovered message signal(time domain)');
xlabel('time(s)');
ylabel('amplitude');
grid on;
figure;
subplot(4,1,1);
plot(f,abs(M));
title('message signal(frequency domain)');
xlabel('frequency(hz)');
ylabel('magnitude');
grid on;
subplot(4,1,2);
plot(f,abs(C));
title('carrier signal(frequency domain)');
xlabel('frequency(hz)');
ylabel('magnitude');
grid on;
subplot(4,1,3);
plot(f,abs(S));
title('am signal(frequency domain)');
xlabel('frequency(hz)');
ylabel('magnitude');
grid on;
subplot(4,1,4);
plot(f,abs(M_rec));
title('recovered message signal(frequency domain)');
xlabel('frequency(hz)');
ylabel('magnitude');
grid on;

4. FREQUENCY Modulation and demodulation


clc;
clear all;
close all;
Fs=1e4;
T=1;
t=0:1/Fs:T-1/Fs;
fc=1000;
kf=2*pi*500;
Am=1;
fm=50;
m=Am*sin(2*pi*fm*t);
int_m=cumtrapz(t,m);
s=cos(2*pi*fc*t+kf*int_m);
s_diff=[0 diff(s)];
s_demod=abs(hilbert(s_diff));
figure;
subplot(4,1,1);
plot(t,m);
title('message signal');
xlabel('time(s)');
ylabel('amplitude');
subplot(4,1,2);
plot(t,s);
title('fm signal');
xlabel('time(s)');
ylabel('amplitude');
subplot(4,1,3);
plot(t,s_demod);
title('demodulated signal');
xlabel('time(s)');
ylabel('amplitude');
subplot(4,1,4);
N=length(s);
f=linspace(-Fs/2,Fs/2,N);
s=fftshift(fft(s));
plot(t,abs(s)/N);
title('spectrum of fm signal');
xlabel('frequency(hz)');
ylabel('magnitude');
sgtitle('frequency modulation and demodulation');

5. SAMPLING AND LOW PASS:


clc;
clear all;
close all;
Fs=1000;
t=0:1/Fs:1-1/Fs;
f=5;
f_samp=50;
x=sin(2*pi*f*t);
Ts=1/f_samp;
t_samp=0:Ts:1-Ts;
x_samp=sin(2*pi*f*t_samp);
x_recon=interp1(t_samp,x_samp,t,'previous');
X=fft(x);
X_samp=fft(x_samp,length(x));
X_recon=fft(x_recon);
f_vector=(0:length(X)-1)*Fs/length(X);
figure;
subplot(3,2,1);
plot(t,x);
title('original signal');
xlabel('time(s)');
ylabel('amplitude');
subplot(3,2,2);
plot(f_vector,abs(X)/length(X));
title('spectrum of original signal');
xlabel('frequency(hz)');
ylabel('magnitude');
subplot(3,2,3);
stem(t_samp,x_samp);
title('sampled signal');
xlabel('time(s)');
ylabel('amplitude');
subplot(3,2,4);
plot(f_vector,abs(X_samp)/length(X_samp));
title('spectrum of sampled signal');
xlabel('frequency(hz)');
ylabel('magnitude');
subplot(3,2,5);
plot(t,x_recon);
title('reconstructed signal');
xlabel('time(s)');
ylabel('amplitude');
subplot(3,2,6);
plot(f_vector,abs(X_recon)/length(X_recon));
title('spectrum of reconstructed signal');
xlabel('frequency(hz)');
ylabel('magnitude');
6. TIME DIVISION MULTIPLEXING AND DEMULTIPLEXING:
clc;
clear all;
close all;
Fs = 1000;
T = 1;
t = 0:1/Fs:T-1/Fs;
signal1 = sin(2*pi*10*t);
signal2 = sin(2*pi*20*t);
signal3 = sin(2*pi*30*t);
signal4 = sin(2*pi*40*t);
numSignals = 4;
combinedSignal = zeros(1, numSignals * length(t));
for i = 1:length(t)
combinedSignal(numSignals*(i-1)+1) = signal1(i);
combinedSignal(numSignals*(i-1)+2) = signal2(i);
combinedSignal(numSignals*(i-1)+3) = signal3(i);
combinedSignal(numSignals*(i-1)+4) = signal4(i);
end
figure;
plot(combinedSignal);
title('Combined Signal');
xlabel('Sample Number');
ylabel('Amplitude');
demuxSignal1 = zeros(1, length(t));
demuxSignal2 = zeros(1, length(t));
demuxSignal3 = zeros(1, length(t));
demuxSignal4 = zeros(1, length(t));
for i = 1:length(t)
demuxSignal1(i) = combinedSignal(numSignals*(i-1)+1);
demuxSignal2(i) = combinedSignal(numSignals*(i-1)+2);
demuxSignal3(i) = combinedSignal(numSignals*(i-1)+3);
demuxSignal4(i) = combinedSignal(numSignals*(i-1)+4);
end
figure;
subplot(4, 1, 1);
plot(t, demuxSignal1);
title('Demultiplexed Signal 1');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4, 1, 2);
plot(t, demuxSignal2);
title('Demultiplexed Signal 2');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4, 1, 3);
plot(t, demuxSignal3);
title('Demultiplexed Signal 3');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4, 1, 4);
plot(t, demuxSignal4);
title('Demultiplexed Signal 4');
xlabel('Time (s)');
ylabel('Amplitude');
7.PCM SAMPLING QUANTIZATION AND ENCODING:

clc;
clear all;
close all;
fs = 100;
t = 0:1/fs:0.2;
f = 5;
x = sin(2*pi*f*t);
n = length(t);
sampled_signal = x(1:n);
n_bits = 3;
L = 2^n_bits;
x_max = max(sampled_signal);
x_min = min(sampled_signal);
delta = (x_max - x_min) / L;
quantized_signal = round((sampled_signal - x_min) / delta) * delta + x_min;
encoded_signal = dec2bin(floor((quantized_signal - x_min) / delta), n_bits);
figure;
subplot(3, 1, 1);
plot(t, x);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3, 1, 2);
stem(t, sampled_signal);
title('Sampled Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(3, 1, 3);
stairs(t, quantized_signal);
title('Quantized Signal');
xlabel('Time (s)');
ylabel('Amplitude');
disp('Encoded Signal:');
disp(encoded_signal);
8. Generate NRZ,RZ AND RAISE COSINE WAVEFORMS:
clc;
clear all;
close all;
bits = [1 0 1 1 0 1 0 0 1];
bitrate = 1e3;
amplitude = 1;
T = 1/bitrate;
samples_per_bit = 100;
t = linspace(0, T, samples_per_bit);
nrz_pulse = amplitude * ones(1, samples_per_bit);
nrz_signal = [];
for bit = bits
if bit == 1
nrz_signal = [nrz_signal nrz_pulse];
else
nrz_signal = [nrz_signal -nrz_pulse];
end
end
figure;
plot(nrz_signal);
title('NRZ Signal');
xlabel('Time');
ylabel('Amplitude');
grid on;
rz_pulse = amplitude * [ones(1, samples_per_bit/2) zeros(1, samples_per_bit/2)];
rz_signal = [];
for bit = bits
if bit == 1
rz_signal = [rz_signal rz_pulse];
else
rz_signal = [rz_signal -rz_pulse];
end
end
figure;
plot(rz_signal);
title('RZ Signal');
xlabel('Time');
ylabel('Amplitude');
grid on;
alpha = 0.5;
Ts = T;
t_rc = linspace(-3*Ts, 3*Ts, 600);
raised_cosine_pulse = sinc(t_rc / Ts) .* cos(pi*alpha*t_rc/Ts) ./ (1 - (2*alpha*t_rc/Ts).^2);
raised_cosine_pulse(isnan(raised_cosine_pulse)) = cos(pi/(2*alpha)) / (2*alpha);
raised_cosine_signal = [];
for bit = bits
if bit == 1
raised_cosine_signal = [raised_cosine_signal amplitude * raised_cosine_pulse];
else
raised_cosine_signal = [raised_cosine_signal -amplitude * raised_cosine_pulse];
end
end
figure;
plot(raised_cosine_signal);
title('Raised Cosine Signal');
xlabel('Time');
ylabel('Amplitude');
grid on;
9. PDF of GAUSSIAN DISTRIBUTION:
clc;
clear all;
close all;
mu = 0;
sigma = 1;
x = linspace(-5, 5, 1000);
pdf = (1/(sigma * sqrt(2 * pi))) * exp(-0.5 * ((x - mu)/sigma).^2);
figure;
plot(x, pdf, 'LineWidth', 2);
title('Probability Density Function of Gaussian Distribution');
xlabel('x');
ylabel('Probability Density');
grid on;

You might also like