Lab Manual Pcs(Bec402)
Lab Manual Pcs(Bec402)
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)');
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;
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;