Experiment 1: Basic Signals and Signal Graphing
Aim: To generate and plot basic signals including unit step, rectangular, standard triangle,
sinusoidal, and exponential signals.
Tools Needed: MATLAB software.
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:
% Define time vector
t = -10:0.01:10;
% Unit Step Signal
unit_step = t >= 0;
% Rectangular Signal
rectangular = (t >= -2) & (t <= 2);
% Standard Triangle Signal
triangle = max(0, 1 - abs(t)/5);
% Sinusoidal Signal
sinusoidal = sin(2*pi*0.5*t);
% Exponential Signal
exponential = exp(-0.5*t);
% Plotting the signals
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:
• The respective signal graphs are displayed.
Experiment 2: Illustration of Signal Representation in Time and Frequency
Domains for a Rectangular Pulse
Aim: To illustrate the representation of a rectangular pulse in both time and frequency
domains.
Tools Needed: MATLAB software.
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:
% Rectangular Pulse in Time Domain
t = -5:0.01:5; % time vector
rect = (t >= -0.5) & (t <= 0.5); % rectangular pulse
figure;
subplot(2,1,1);
plot(t, rect, 'LineWidth', 2);
title('Rectangular Pulse - Time Domain');
xlabel('t');
ylabel('rect(t)');
grid on;
% Frequency Domain Representation
%Define the frequency range
f = -10:0.1:10; % frequency vector from -10 to 10 Hz with 0.1 Hz step
% Define the pulse duration and amplitude
T = 2; % pulse duration (s)
A = 1; % pulse amplitude
% Generate the rectangular pulse in the frequency domain
X = A*T*sinc(f*T); % sinc function to generate the rectangular pulse
% Plot the frequency response
figure;
subplot(2,1,2);
plot(f, abs(X)); % plot the magnitude of the frequency response
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Rectangular Pulse in Frequency Domain');
Result:
• 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.
Tools Needed: MATLAB software.
Theory:
• Amplitude Modulation: A technique where the amplitude of a carrier signal is varied
in proportion to a message signal.
• Demodulation: The process of extracting the original message signal from the
modulated carrier wave.
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
% Generate carrier and modulation signals
c = Ac * sin(2 * pi * fc * t);
m = Am * sin(2 * pi * fm * t);
% Amplitude modulation
s = ammod(m, fc, fs);
% Amplitude demodulation
d = amdemod(s, fc, fs);
% Plot the signals
subplot(4,1,1);
plot(t, modulation);
title('Modulation Signal');
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.
Tools Needed: MATLAB software.
Theory:
• Frequency Modulation: A technique where the frequency of a carrier signal is varied
in proportion to a message signal.
• Demodulation: The process of extracting the original message signal from the
modulated carrier wave.
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);
% Frequency modulation using fmmod
s = fmmod(m, fc, fs, fd);
% Frequency demodulation using fmdemod
d = fmdemod(s, fc, fs, fd);
% Plotting
figure;
% Plot message signal
subplot(3, 1, 1);
plot(t, m);
title('Message Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Plot Carrier signal
subplot(3, 1, 1);
plot(t, m);
title('Carrier Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Plot FM modulated signal
subplot(4, 1, 3);
plot(t, s);
title('FM Modulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Plot demodulated signal
subplot(4, 1, 4);
plot(t, d);
title('Demodulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
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.
Tools Needed: MATLAB software.
Theory:
• Sampling: The process of converting a continuous-time signal into a discrete-time
signal by taking samples at regular intervals.
• Reconstruction: The process of converting a discrete-time signal back into a
continuous-time signal.
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);
% Reconstruction using Zero-Order Hold
m_recon = interp1(ts, m_samp, t, 'previous');
% Plotting the signals
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);
plot(t, m_recon, 'LineWidth', 2);
title('Reconstructed Signal');
xlabel('t');
ylabel('m_{recon}(t)');
grid on;
Result:
• The original, sampled, and reconstructed signals graphs are displayed.
Experiment 6: Time Division Multiplexing and Demultiplexing
Aim: To illustrate time division multiplexing and demultiplexing of two signals.
Tools Needed: MATLAB software.
Theory:
• Time Division Multiplexing (TDM): A method of transmitting multiple signals over
a single communication channel by dividing the time frame into slots, each carrying a
different signal.
• Demultiplexing: The process of separating the multiplexed signals back into their
original forms.
MATLAB Code:
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
% Display of Both Signal
subplot(2,2,1);
plot(sig1);
title('Sinusoidal Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,2,2);
plot(sig2);
title('Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Display of Both Sampled Signal
subplot(2,2,3);
stem(sig1);
title('Sampled Sinusoidal Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,2,4);
stem(sig2);
title('Sampled Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
l1=length(sig1);
l2=length(sig2);
for i=1:l1
sig(1,i)=sig1(i); % Making Both row vector to a matrix
sig(2,i)=sig2(i);
end
% TDM of both quantize signal
tdmsig=reshape(sig,1,2*l1);
% Display of TDM Signal
figure
stem(tdmsig);
title('TDM Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Demultiplexing of TDM Signal
demux=reshape(tdmsig,2,l1);
for i=1:l1
sig3(i)=demux(1,i); % Converting The matrix into row vectors
sig4(i)=demux(2,i);
end
% display of demultiplexed signal
figure
subplot(2,1,1)
plot(sig3);
title('Recovered Sinusoidal Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,1,2)
plot(sig4);
title('Recovered Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
Result:
The original signals, multiplexed signal, and demultiplexed signals are displayed.
Experiment 7: PCM Illustration: Sampling, Quantization, and Encoding
Aim: To illustrate the process of Pulse Code Modulation (PCM) including sampling,
quantization, and encoding.
Tools Needed: MATLAB software.
Theory:
• Sampling: Converting a continuous-time signal into a discrete-time signal.
• Quantization: Mapping the sampled signal to a finite set of values.
• Encoding: Converting quantized values into binary code.
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;
% Displaying Encoded Signal
disp('Encoded Signal:');
disp(m_encoded);
Encoded Signal:
10000
01000
00000
01000
10000
01000
00000
01000
10000
01000
00000
01000
10000
01000
00000
01000
10000
01000
00000
01000
10000
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.
Tools Needed: MATLAB software.
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 NRZ signal
nrz = repelem(data, 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
% Generate Raised Cosine pulse signal
alpha = 0.5; % Roll-off factor
t_rc = -bit_duration:1/fs:bit_duration; % Time vector for RC pulse
rc_pulse = (sin(pi*t_rc*(1-alpha)/bit_duration) + 4*alpha*t_rc/bit_duration .*
cos(pi*t_rc*(1+alpha)/bit_duration)) ./ (pi*t_rc.*(1-
(4*alpha*t_rc/bit_duration).^2));
rc_pulse(isnan(rc_pulse)) = 1; % Handle NaN at t = 0
rc_signal = conv(repelem(data, samples_per_bit), rc_pulse, 'same');
% Time vector for the entire data sequence
t = linspace(0, bit_duration * length(data), length(data) * samples_per_bit);
% Plotting
figure;
% Plot NRZ signal
subplot(3, 1, 1);
plot(t, nrz, 'LineWidth', 2);
title('NRZ Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Plot RZ signal
subplot(3, 1, 2);
plot(t, rz, 'LineWidth', 2);
title('RZ Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Plot Raised Cosine pulse signal
subplot(3, 1, 3);
plot(t, rc_signal(1:length(t)), 'LineWidth', 2);
title('Raised Cosine Pulse Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
b) Eye Diagram
% Eye Diagram for NRZ
eyediagram(nrz, 20);
title('Eye Diagram of NRZ Signal');
xlabel('Time');
ylabel('Amplitude');
grid on;
% Eye Diagram for RZ
% Generate and plot the eye diagram for the RZ signal
figure;
eyediagram(rz, samples_per_bit);
title('Eye Diagram of RZ Signal');
% Eye Diagram for Raised Cosine pulse
% 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.
Tools Needed: MATLAB software.
Theory:
• Gaussian Distribution: A continuous probability distribution characterized by a bell-
shaped curve, defined by its mean (μ\muμ) and standard deviation (σ\sigmaσ).
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:
• Graph showing the PDF of a Gaussian distribution will be displayed.
Experiment 10: Display the Signal and its Spectrum of an Audio Signal
Aim: To display the time-domain signal and its frequency spectrum for an audio file.
Tools Needed: MATLAB software, audio file.
Theory:
• Time Domain: The representation of a signal in terms of time.
• Frequency Domain: The representation of a signal in terms of its frequency
components obtained using Fourier Transform.
Result:
• Graphs showing the audio signal in both time and frequency domains will be
displayed.
MATLAB Code:
% Load Audio File
[audio, fs] = audioread('audiofile.wav'); % Load audio file
% Time Vector
t = (0:length(audio)-1)/fs;
% Plot Time-Domain Signal
figure;
subplot(2,1,1);
plot(t, audio, 'LineWidth', 2);
title('Audio Signal - Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Frequency Domain
n = length(audio);
f = (-n/2:n/2-1)*(fs/n);
audio_fft = fftshift(fft(audio));
% Plot Frequency-Domain Signal
subplot(2,1,2);
plot(f, abs(audio_fft)/n, 'LineWidth', 2);
title('Audio Signal - Frequency Domain');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
grid on;