PCS LAB (Matlab Code)
PCS LAB (Matlab Code)
Aim: To generate and plot basic signals including unit step, rectangular, standard triangle,
sinusoidal, and exponential signals.
Theory:
• Unit Step Signal: A function that is 0 for negative time and 1 for positive time.
• Rectangular Signal: A function that has a constant value within a specific interval
and zero elsewhere.
• Standard Triangle Signal: A function that forms a triangle shape, starting from zero,
increasing linearly to a maximum, and then decreasing back to zero.
• Sinusoidal Signal: A sine wave defined by the function sin(2πft)\sin(2\pi
ft)sin(2πft), where fff is the frequency.
• Exponential Signal: A function that increases or decreases exponentially over time,
defined by exp(-t).
MATLAB Code:
% Rectangular Signal
rectangular = (t >= -2) & (t <= 2);
% Sinusoidal Signal
sinusoidal = sin(2*pi*0.5*t);
% Exponential Signal
exponential = exp(-0.5*t);
subplot(5,1,1);
plot(t, unit_step);
title('Unit Step Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(5,1,2);
plot(t, rectangular);
title('Rectangular Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(5,1,3);
plot(t, triangle);
title('Standard Triangle Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(5,1,4);
plot(t, sinusoidal);
title('Sinusoidal Signal');
xlabel('Time');
ylabel('Amplitude');
subplot(5,1,5);
plot(t, exponential);
title('Exponential Signal');
xlabel('Time');
ylabel('Amplitude');
Result:
Aim: To illustrate the representation of a rectangular pulse in both time and frequency
domains.
Theory:
• Time Domain: A rectangular pulse is a signal that remains constant over a specified
interval and zero elsewhere.
• Frequency Domain: The Fourier Transform of a rectangular pulse shows its
frequency components.
MATLAB Code:
• The rectangular pulse in both time and frequency domains graphs are displayed.
Experiment 3: Amplitude Modulation and Demodulation
Aim: To generate and display amplitude modulated (AM) signals and their spectrums, and to
demodulate the AM signal.
Theory:
MATLAB Code:
% Define parameters
fc = 100; % Carrier frequency
fm = 10; % Modulation frequency
fs =1000;
Ac = 1; % Carrier amplitude
Am = 0.5; % Modulation amplitude
t = 0:0.001:1; % Time vector
% Amplitude modulation
s = ammod(m, fc, fs);
% Amplitude demodulation
d = amdemod(s, fc, fs);
subplot(4,1,2);
plot(t, carrier);
title('Carrier Signal');
subplot(4,1,3);
plot(t, s);
title('Modulated Signal');
subplot(4,1,4);
plot(t, d);
title('Demodulated Signal');
Result:
• The message signal, AM signal, spectrum of AM signal, and the demodulated signal
graphs are displayed.
Experiment 4: Frequency Modulation and Demodulation
Aim: To generate and display frequency modulated (FM) signals and their spectrums, and to
demodulate the FM signal.
Theory:
MATLAB Code:
%Parameters
fs = 10000; % Sampling frequency
fc = 200; % Carrier frequency
fd = 50; % Frequency deviation
t = 0:1/fs:1; % Time vector
m = sin(2 * pi * 5 * t); % Message signal (5 Hz sine wave)
c=sin(2 * pi * fc * t);
% Plotting
figure;
Result:
• The message signal, FM signal, spectrum of FM signal, and the demodulated signal
graphs are displayed.
Experiment 5: Sampling and Reconstruction of Low Pass Signals
Aim: To sample a low pass signal and reconstruct it using zero-order hold.
Theory:
MATLAB Code:
% Parameters
fm = 5; % Message frequency in Hz
fs = 20; % Sampling frequency in Hz
t = 0:0.001:1; % Continuous time vector
ts = 0:1/fs:1; % Sampled time vector
% Message Signal
m = cos(2 * pi * fm * t);
% Sampled Signal
m_samp = cos(2 * pi * fm * ts);
subplot(3,1,2);
stem(ts, m_samp, 'LineWidth', 2);
title('Sampled Signal');
xlabel('t');
ylabel('m[n]');
grid on;
subplot(3,1,3);
plot(t, m_recon, 'LineWidth', 2);
title('Reconstructed Signal');
xlabel('t');
ylabel('m_{recon}(t)');
grid on;
Result:
Theory:
clc;
close all;
clear all;
% Signal generation
x=0:.5:4*pi; % siganal taken upto 4pi
sig1=8*sin(x); % generate 1st sinusoidal signal
l=length(sig1);
sig2=8*triang(l); % Generate 2nd traingular Sigal
The original signals, multiplexed signal, and demultiplexed signals are displayed.
Aim: To illustrate the process of Pulse Code Modulation (PCM) including sampling,
quantization, and encoding.
Theory:
MATLAB Code:
% Parameters
fm = 5; % Message frequency in Hz
t = 0:0.001:1; % Continuous time vector
m = cos(2 * pi * fm * t); % Message signal
% Sampling
fs = 20; % Sampling frequency in Hz
ts = 0:1/fs:1; % Sampled time vector
m_samp = cos(2 * pi * fm * ts); % Sampled message signal
% Quantization
L = 16; % Number of quantization levels
m_min = min(m_samp);
m_max = max(m_samp);
delta = (m_max - m_min) / L;
m_quant = round((m_samp - m_min) / delta) * delta + m_min;
% Encoding
m_encoded = dec2bin(round((m_samp - m_min) / delta), log2(L));
% Plotting
figure;
subplot(3,1,1);
plot(t, m, 'LineWidth', 2);
title('Original Message Signal');
xlabel('t');
ylabel('m(t)');
grid on;
subplot(3,1,2);
stem(ts, m_samp, 'LineWidth', 2);
title('Sampled Signal');
xlabel('t');
ylabel('m[n]');
grid on;
subplot(3,1,3);
stem(ts, m_quant, 'LineWidth', 2);
title('Quantized Signal');
xlabel('t');
ylabel('m_q[n]');
grid on;
Result: The original message, sampled, and quantized signals are displayed along with the
encoded binary representation.
Experiment 8: Generate NRZ, RZ, Raised Cosine Pulse, and Eye Diagram
Aim: To generate and plot NRZ, RZ, Raised Cosine pulse signals, and their eye diagrams.
Theory:
• NRZ (Non-Return to Zero): A binary signal that does not return to zero between
bits.
• RZ (Return to Zero): A binary signal that returns to zero between each bit.
• Raised Cosine Pulse: A pulse shaping filter used to minimize intersymbol
interference.
• Eye Diagram: A tool used to evaluate the quality of a digital signal.
MATLAB Code:
% Parameters
data = [1 0 1 1 0]; % Binary data sequence
bit_duration = 1; % Duration of each bit in seconds
fs = 1000; % Sampling frequency in Hz
samples_per_bit = bit_duration * fs; % Number of samples per bit
% Generate RZ signal
rz = zeros(1, length(data) * samples_per_bit);
for i = 1:length(data)
if data(i) == 1
rz((i-1)*samples_per_bit + 1 : (i-1)*samples_per_bit + samples_per_bit/2)
= 1;
end
end
% Plotting
figure;
% Plot RZ signal
subplot(3, 1, 2);
plot(t, rz, 'LineWidth', 2);
title('RZ Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Generate and plot the eye diagram for the Raised Cosine pulse signal
figure;
eyediagram(rc_signal, samples_per_bit);
title('Eye Diagram of Raised Cosine Pulse Signal');
Result:
• Graphs showing the NRZ, RZ, Raised Cosine pulse signals and their eye diagrams
will be displayed.
Experiment 9: Generate the Probability Density Function of Gaussian
Distribution
Aim: To generate and plot the probability density function (PDF) of a Gaussian distribution.
Theory:
MATLAB Code:
% Gaussian Distribution
mu = 0; % Mean
sigma = 1; % Standard deviation
x = -5:0.01:5; % Range of values
pdf = (1/(sigma * sqrt(2 * pi))) * exp(-0.5 * ((x - mu) / sigma).^2);
figure;
plot(x, pdf, 'LineWidth', 2);
title('Gaussian Distribution - PDF');
xlabel('x');
ylabel('f(x)');
grid on;
Result:
Aim: To display the time-domain signal and its frequency spectrum for an audio file.
Theory:
Result:
• Graphs showing the audio signal in both time and frequency domains will be
displayed.
MATLAB Code:
% Time Vector
t = (0:length(audio)-1)/fs;
% Frequency Domain
n = length(audio);
f = (-n/2:n/2-1)*(fs/n);
audio_fft = fftshift(fft(audio));