0% found this document useful (0 votes)
10 views31 pages

Iot Labetronical

The document outlines the Principles of Communication Laboratory (BEC402) curriculum at SJC Institute of Technology, detailing the vision and mission of the institute and department, along with program educational objectives. It includes a list of experiments focusing on various signal types, modulation techniques, and the use of Scilab for signal processing. Additionally, it provides insights into the capabilities of Scilab and includes example codes for generating and plotting different types of signals.

Uploaded by

mojir33433
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views31 pages

Iot Labetronical

The document outlines the Principles of Communication Laboratory (BEC402) curriculum at SJC Institute of Technology, detailing the vision and mission of the institute and department, along with program educational objectives. It includes a list of experiments focusing on various signal types, modulation techniques, and the use of Scilab for signal processing. Additionally, it provides insights into the capabilities of Scilab and includes example codes for generating and plotting different types of signals.

Uploaded by

mojir33433
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

PRINCIPLES OF COMMUNICATION LAB [BEC402]

|| Jai Sri Gurudev ||

Sri Adichunchanagiri Shikshana Trust[R]

SJC INSTITUTE OF TECHNOLOGY


CHICKBALLAPUR – 562101

DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING

Principles of Communication Laboratory


(BEC402)

IV SEMESTER
NEP - 2022 Scheme

PREPARED BY REVIEWED & APPROVED BY


Dr. S.Bhargavi Dr. C Rangaswamy
Professor Professor & Head

Dept. of ECE SJCIT 1


PRINCIPLES OF COMMUNICATION LAB [BEC402]

SJC INSTITUTE OF TECHNOLOGY

Vision of the Institute

Preparing Competent Engineering and Management Professionals to Serve the Society.


Mission of the Institute

1. Providing Students with a Sound Knowledge in Fundamentals of their branch of Study.


2. Promoting Excellence in Teaching, Training, Research and Consultancy.
3. Exposing Students to Emerging Frontiers in various domains enabling Continuous Learning.
4. Developing Entrepreneurial acumen to venture into Innovative areas.
5. Imparting Value based Professional Education with a sense of Social Responsibility.

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

Vision of the Department


To achieve academic excellence in Electronics and Communication engineering by imparting quality
technical education and facilitating research activities

Mission of the department

M1: Establishing state of the art laboratory facilities and infrastructure to develop the spirit of
innovation and entrepreneurship
M2: Nurturing the students with technical expertise along with professional ethics to provide
solutions for societal needs
M3: Encourage lifelong learning and research among the students and faculty

Program Educational Objectives:


After successful completion of the program,
PEO1: Graduates of the program will have successful technical and professional career in engineering,
technology and multidisciplinary environments.
PEO2: Graduates of the program will utilize their knowledge, technical and communication skills to
propose optimal solutions to problems related to society in the field of Electronics and
Communication.
PEO3: Graduates of the program will exhibit good interpersonal skills, leadership qualities

Dept. of ECE SJCIT 2


PRINCIPLES OF COMMUNICATION LAB [BEC402]

CONTENTS

Sl.No. Experiments

Basic Signals and Signal Graphing: a) unit Step, b) Rectangular, c) standard


1
triangle d) sinusoidal and e) Exponential signal.

2 Illustration of signal representation in time and frequency domains for a


rectangular pulse.

3 Amplitude Modulation and demodulation: Generation and display the relevant


signals and its spectrums.

4 Frequency Modulation and demodulation: Generation and display the relevant


signals and its spectrums.

5 Sampling and reconstruction of low pass signals. Display the signals and its
spectrum.

6 Time Division Multiplexing and demultiplexing.

7 PCM Illustration: Sampling, Quantization and Encoding

8 Generate a)NRZ, RZ and Raised cosine pulse, b) Generate and plot eye diagram

9 Generate the Probability density function of Gaussian distribution function.

10 Display the signal and its spectrum of an audio signal.

Dept. of ECE SJCIT 3


INTRODUCTION
Scilab is a programming language associated with a rich collection of numerical algorithms covering many
aspects of scientific computing problems. From the software point of view, Scilab is an interpreted language.
This generally allows to get faster development processes, because the user directly accesses a high-level
language, with a rich set of features provided by the library. The Scilab language is meant to be extended so
that user-defined data types can be defined with possibly overloaded operations. Scilab users can develop
their own modules so that they can solve their particular problems. The Scilab language allows to
dynamically compile and link other languages such as Fortran and C: this way,external libraries can be used
as if they were a part of Scilab built-in features. Scilab also interfaces LabVIEW, a platform and development
environment for a visual programming language from National Instruments.
At the very beginning of Scilab, features were focused on linear algebra. But, rapidly, the number of features
extended to cover many areas of scienti_c computing. The following is a short list of its capabilities:
• Linear algebra, sparse matrices,
• Polynomials and rational functions,
• Interpolation, approximation,
• Linear, quadratic and non linear optimization,
• Ordinary Differential Equation solver and Differential Algebraic Equations solver,
• Classic and robust control, Linear Matrix Inequality optimization,
• Differentiable and non-differentiable optimization,
• Signal processing,
• Statistics.
Scilab provides many graphics features, including a set of plotting functions, which allow to create 2D and
3D plots as well as user interfaces. The Xcos environment provides a hybrid dynamic systems modeler and
simulator.
How to get and install Scilab

Whatever your platform is (i.e. Windows, Linux or Mac), Scilab binaries can be downloaded directly from
the Scilab homepage
http://www.scilab.org
or from the Download area
http://www.scilab.org/download
Scilab binaries are provided for both 32 and 64-bit platforms so that they match the target installation
machine.

4
Creating real variables

In Scilab, the "=" operator means that we want to set the variable on the left hand side to the value
associated with the right hand side (it is not the comparison operator, which syntax is associated with the
"==" operator).
-->x=1
x = 1.
-->x = x * 2

x = 2.

Scilab elementary mathematical operators.

Scilab is case sensitive, which means that upper and lower case letters are considered to be different by
Scilab.

Any line which begins with two slashes "//" is considered by Scilab as a comment
and is ignored.

-->// This is my comment .


-->x =1..
- - >+2..
- - >+3..
-->+4
x=1

Elementary mathematical functions

5
Comparison operators.

Complex numbers

Scilab provides complex numbers, which are stored as pairs of oating point numbers.
The pre-defined variable %i represents the mathematical imaginary number i.
-->x= 1+ %i
x=
1. + i
--> isreal (x)
ans =
F

6
Strings
Strings can be stored in variables, provided that they are delimited by double quotes "" ". The concatenation
operation is available from the "+" operator. In the following Scilab session, we define two strings and then
concatenate them with the "+"
operator.
-->x = "foo"
x=
foo
-->y="bar"
y=
bar
-->x+y
ans =
foobar

Matrices
In the Scilab language, matrices play a central role.

There is a simple and efficient syntax to create a matrix with given values. The
following is the list of symbols used to define a matrix:
_ square brackets "[" and "]"mark the beginning and the end of the matrix,
_ commas "," separate the values in different columns,
_ semicolons ";" separate the values of different rows.

-->A = [1 , 2 , 3 ; 4 , 5 , 6]
A=
1. 2. 3.
4. 5. 6.

7
1. Basic Signals and Signal Graphing: a) unit Step, b) Rectangular, c) standard
triangle d) sinusoidal and e) Exponential signal.

Unit Step Signal

The step signal or step function is that type of standard signal which exists only for
positive time and it is zero for negative time. In other words, a signal x(t) is said to be step
signal if and only if it exists for t > 0 and zero for t < 0. The step signal is an important
signal used for analysis of many systems.

If a step signal has unity magnitude, then it is known as unit step signal or unit step
function. It is denoted by u(t).

// Scilab Code to generate and plot a Unit Step Signal

clear; // Clear all variables from the workspace


clc; // Clear the command window
close; // Close all figure windows
// Define the upper limit for the signal range
L=100;// Upper Limit
// Create a vector n ranging from -L to L
n=-L:L; // n ranges from -100 to 100
// Generate the unit step signal x[n]
// The signal is 0 for n < 0 and 1 for n >= 0
x=[zeros(1,L),ones(1,L+1)]; // Concatenate L zeros and L+1 ones
// Get the current axes handle
a=gca(); // Get current axes
// Set the y-axis to cross the x-axis in the middle
a.y_location= "middle"; // Set the y-axis location to the middle
// Plot the unit step signal
plot2d3('gnn',n,x) // Plot the signal using plot2d3 function
// Add title and labels to the plot
title( ' Unit Step Signal') // Add title to the plot
xlabel('n'); // Label the x-axis as 'n'
ylabel('x[n]'); // Label the y-axis as 'x[n]'

8
Rectangular Wave
A pulse wave or pulse train or rectangular wave is a non-sinusoidal waveform that
is the periodic version of the rectangular function. It is held high a percent each
cycle (period) called the duty cycle and for the remainder of each cycle is low.

// Scilab Code to generate and plot a rectangular wave signal

// Clear previous data and close any existing plots


clear;
clf;

9
// Define the parameters of the rectangular wave
amplitude = 1; // Amplitude of the wave
frequency = 1; // Frequency in Hz
period = 1 / frequency; // Period of the wave (T = 1/frequency)
duty_cycle = 0.5; // Duty cycle (percentage of one period in which the signal is
high)
duration = 5; // Total duration for the signal in seconds
sampling_rate = 1000; // Number of samples per second

// Generate the time vector


t = 0:1/sampling_rate:duration; // Time vector from 0 to duration with steps of
1/sampling_rate

// Generate the rectangular wave signal


signal = amplitude * (modulo(t, period) < duty_cycle * period);

// Plot the rectangular wave signal


plot(t, signal);
title('Rectangular Wave Signal');
xlabel('Time (s)');
ylabel('Amplitude');
xtitle('Rectangular Wave Signal', 'Time (s)', 'Amplitude');
grid on;

// Optional: Set the axes limits for better visualization


xmax = duration;
ymax = amplitude * 1.5;
axis([0 xmax -amplitude ymax]);

10
// Scilab script to generate and plot a triangular wave signal

// Clear previous data and close any existing plots


clear;
clf;

// Define the parameters of the triangular wave


amplitude = 1; // Amplitude of the wave
frequency = 1; // Frequency in Hz
period = 1 / frequency; // Period of the wave (T = 1/frequency)
duration = 5; // Total duration for the signal in seconds
sampling_rate = 1000; // Number of samples per second

// Generate the time vector


t = 0:1/sampling_rate:duration; // Time vector from 0 to duration with steps of
1/sampling_rate

// Generate the triangular wave signal


signal = 2 * amplitude * (2 * (t / period - floor(1/2 + t / period))) - amplitude;

// Plot the triangular wave signal


plot(t, signal);
title('Triangular Wave Signal');
xlabel('Time (s)');
ylabel('Amplitude');
xtitle('Triangular Wave Signal', 'Time (s)', 'Amplitude');
grid on;

// Optional: Set the axes limits for better visualization


xmax = duration;
ymax = amplitude * 1.5;
axis([0 xmax -amplitude ymax]);

11
// Scilab script to generate and plot a sinusoidal wave signal

// Clear previous data and close any existing plots


clear;
clc;
close;

// Define the parameters of the sinusoidal wave


amplitude = 1; // Amplitude of the wave
frequency = 1; // Frequency in Hz
phase = 0; // Phase in radians
sampling_rate = 100; // Number of samples per second
duration = 2; // Duration in seconds

// Generate the time vector


t = 0:1/sampling_rate:duration; // Time vector from 0 to duration with steps of
1/sampling_rate

// Generate the sinusoidal wave signal


signal = amplitude * sin(2 * %pi * frequency * t + phase); // Sinusoidal wave formula

// Plot the sinusoidal wave signal


plot(t, signal);
title('Sinusoidal Wave Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

// Optional: Set the axes limits for better visualization


xmax = duration;
ymax = amplitude * 1.5;
axis([0 xmax -amplitude ymax]);

12
// Scilab script to generate and plot an exponential signal

// Clear previous data and close any existing plots


clear;
clc;
close;

// Define the parameters of the exponential signal


amplitude = 1; // Amplitude of the signal
decay_rate = 1; // Decay rate (positive for decaying, negative for growing)
sampling_rate = 100; // Number of samples per second
duration = 5; // Duration in seconds

// Generate the time vector


t = 0:1/sampling_rate:duration; // Time vector from 0 to duration with steps of
1/sampling_rate

// Generate the exponential signal


signal = amplitude * exp(-decay_rate * t); // Exponential signal formula

// Plot the exponential signal


plot(t, signal);
title('Exponential Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

// Optional: Set the axes limits for better visualization


xmax = duration;
ymax = amplitude;
axis([0 xmax 0 ymax]);

13
2.Illustration of signal representation in time and frequency domains for a
rectangular pulse.

// Scilab script to illustrate signal representation in time and frequency domains


for a rectangular pulse

// Clear previous data and close any existing plots


clear;
clc;
close;

// Define the parameters of the rectangular pulse


amplitude = 1; // Amplitude of the pulse
pulse_width = 1; // Width of the pulse in seconds
sampling_rate = 1000; // Number of samples per second
duration = 5; // Total duration of the signal in seconds

// Generate the time vector


t = -duration/2:1/sampling_rate:duration/2; // Time vector from -duration/2 to
duration/2

// Generate the rectangular pulse signal


pulse = amplitude * (abs(t) <= pulse_width/2);

// Plot the rectangular pulse in the time domain


subplot(2,1,1); // Create a subplot for the time domain
plot(t, pulse);
title('Rectangular Pulse in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

// Compute the Fourier Transform of the rectangular pulse


N = length(t); // Number of points in the signal
pulse_fft = fftshift(fft(pulse)); // Compute the FFT and shift zero frequency to the
center
frequencies = (-N/2:N/2-1)*(sampling_rate/N); // Frequency vector

// Plot the magnitude spectrum in the frequency domain


subplot(2,1,2); // Create a subplot for the frequency domain
plot(frequencies, abs(pulse_fft)/N);
title('Magnitude Spectrum in Frequency Domain');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;

14
15
3.Amplitude Modulation and demodulation: Generation and display the relevant
signals and its spectrums.

// Clear all variables and close all previous plots


clear;
clc;
clf;

// Parameters
fs = 10000; // Sampling frequency
t = 0:1/fs:0.1; // Time vector

// Carrier signal
fc = 200; // Carrier frequency
carrier = cos(2 * %pi * fc * t);

// Message signal (modulating signal)


fm = 20; // Message frequency
message = cos(2 * %pi * fm * t);

// Amplitude Modulation
modulated_signal = (1 + message) .* carrier;
// Fourier Transform function
function [freq, spectrum]=compute_fft(signal, fs)
N = length(signal);
spectrum = fftshift(fft(signal));
spectrum = abs(spectrum) / N;
freq = (-N/2:N/2-1)*(fs/N);
endfunction

// Compute spectra
[freq, carrier_spectrum] = compute_fft(carrier, fs);
[freq, message_spectrum] = compute_fft(message, fs);
[freq, modulated_spectrum] = compute_fft(modulated_signal, fs);

// Plotting
figure;
subplot(3, 2, 1);
plot(t, message);
title('Message Signal in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3, 2, 2);
plot(freq, message_spectrum);
title('Message Signal Spectrum');
xlabel('Frequency (Hz)');

16
ylabel('Magnitude');
grid on;

subplot(3, 2, 3);
plot(t, carrier);
title('Carrier Signal in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(3, 2, 4);
plot(freq, carrier_spectrum);
title('Carrier Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
subplot(3, 2, 5);
plot(t, modulated_signal);
title('Modulated Signal in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3, 2, 6);
plot(freq, modulated_spectrum);
title('Modulated Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
// Demodulation using envelope detection
demodulated_signal = abs(hilbert(modulated_signal));
// Compute demodulated signal spectrum
[freq, demodulated_spectrum] = compute_fft(demodulated_signal, fs);

// Plot demodulated signal


figure;
subplot(2, 1, 1);
plot(t, demodulated_signal);
title('Demodulated Signal in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2, 1, 2);
plot(freq, demodulated_spectrum);
title('Demodulated Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
17
18
4. Frequency Modulation and demodulation: Generation and display the relevant
signals and its spectrums.

// Clear all variables and close all previous plots


clear;
clc;
clf;

// Parameters
fs = 10000; // Sampling frequency
t = 0:1/fs:0.1; // Time vector

// Carrier signal
fc = 200; // Carrier frequency

// Message signal (modulating signal)


fm = 20; // Message frequency
message = cos(2 * %pi * fm * t);

// Frequency Modulation
kf = 50; // Frequency sensitivity
integrated_message = cumsum(message) / fs; // Integral of the message signal
modulated_signal = cos(2 * %pi * fc * t + 2 * %pi * kf * integrated_message);

// Fourier Transform function


function [freq, spectrum]=compute_fft(signal, fs)
N = length(signal);
spectrum = fftshift(fft(signal));
spectrum = abs(spectrum) / N;
freq = (-N/2:N/2-1)*(fs/N);
endfunction

// Compute spectra
[freq, message_spectrum] = compute_fft(message, fs);
[freq, modulated_spectrum] = compute_fft(modulated_signal, fs);

// Plotting
figure;
subplot(3, 2, 1);
plot(t, message);
title('Message Signal in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
// Frequency Demodulation using differentiation and Hilbert transform
demodulated_signal = diff([0 modulated_signal]) .* (fs / (2 * %pi * kf)); //
Differentiate and scale

19
demodulated_signal = demodulated_signal - mean(demodulated_signal); // Remove
DC offset

// Compute demodulated signal spectrum


[freq, demodulated_spectrum] = compute_fft(demodulated_signal, fs);

// Plot demodulated signal


figure;
subplot(2, 1, 1);
plot(t, demodulated_signal);
title('FM Demodulated Signal in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(2, 1, 2);
plot(freq, demodulated_spectrum);
title('FM Demodulated Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;

20
5.Sampling and reconstruction of low pass signals. Display the signals and its
spectrum.

// Clear all variables and close all previous plots


clear;
clc;
clf;

// Parameters
fs = 1000; // Original sampling frequency (Hz)
t = 0:1/fs:0.1; // Time vector for original signal

// Original low-pass signal (e.g., a sine wave)


f_signal = 50; // Frequency of the low-pass signal (Hz)
signal = sin(2 * %pi * f_signal * t);

// Sampling parameters
fs_sample = 200; // Sampling frequency (Hz)
Ts_sample = 1/fs_sample; // Sampling period
n_sample = 0:Ts_sample:0.1; // Sampled time vector
sampled_signal = sin(2 * %pi * f_signal * n_sample);

// Reconstruction using ideal low-pass filter (sinc interpolation)


reconstructed_signal = zeros(1, length(t));
for k = 1:length(n_sample)
reconstructed_signal = reconstructed_signal + sampled_signal(k) * sinc(fs_sample
* (t - n_sample(k)));
end

// Fourier Transform function


function [freq, spectrum]=compute_fft(signal, fs)
N = length(signal);
spectrum = fftshift(fft(signal));
spectrum = abs(spectrum) / N;
freq = (-N/2:N/2-1)*(fs/N);
endfunction

// Compute spectra
[freq, signal_spectrum] = compute_fft(signal, fs);
[freq, sampled_spectrum] = compute_fft(sampled_signal, fs);
[freq, reconstructed_spectrum] = compute_fft(reconstructed_signal, fs);

// Plotting
figure;
subplot(3, 2, 1);
plot(t, signal);
title('Original Signal in Time Domain');
xlabel('Time (s)');

21
ylabel('Amplitude');
grid on;

subplot(3, 2, 2);
plot(freq, signal_spectrum);
title('Original Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;

subplot(3, 2, 3);
stem(n_sample, sampled_signal);
title('Sampled Signal in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(3, 2, 4);
plot(freq, sampled_spectrum);
title('Sampled Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;

subplot(3, 2, 5);
plot(t, reconstructed_signal);
title('Reconstructed Signal in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(3, 2, 6);
plot(freq, reconstructed_spectrum);
title('Reconstructed Signal Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;

22
6.Time Division Multiplexing and demultiplexing.

// Scilab script for simple Time Division Multiplexing (TDM) and Demultiplexing

// Clear previous data and close any existing plots


clear;
clc;
close;

// Define parameters
sampling_rate = 1000; // Sampling rate in Hz
duration = 1; // Duration in seconds
t = 0:1/sampling_rate:duration; // Time vector

// Generate two signals


signal1 = sin(2 * %pi * 5 * t); // 5 Hz sine wave
signal2 = cos(2 * %pi * 7 * t); // 7 Hz cosine wave

// Perform Time Division Multiplexing (TDM)


N = length(t); // Length of the time vector
tdm_signal = zeros(1, 2 * N); // Initialize TDM signal
tdm_signal(1:2:2*N) = signal1; // Signal 1 on odd indices
tdm_signal(2:2:2*N) = signal2; // Signal 2 on even indices

// Perform Time Division Demultiplexing


demux_signal1 = tdm_signal(1:2:2*N); // Extract Signal 1
demux_signal2 = tdm_signal(2:2:2*N); // Extract Signal 2

// Plot the original signals


figure();
subplot(3, 1, 1);
plot(t, signal1);
title('Original Signal 1 (5 Hz sine)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(3, 1, 2);
plot(t, signal2);
title('Original Signal 2 (7 Hz cosine)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

// Plot the multiplexed TDM signal


subplot(3, 1, 3);
tdm_time = 0:1/(2*sampling_rate):duration - 1/(2*sampling_rate); // Time vector for TDM
signal
23
plot(tdm_time, tdm_signal);
title('Time Division Multiplexed Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

figure();

// Plot the demultiplexed signals


subplot(2, 1, 1);
plot(t, demux_signal1);
title('Demultiplexed Signal 1');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(2, 1, 2);
plot(t, demux_signal2);
title('Demultiplexed Signal 2');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

24
7. PCM Illustration: Sampling, Quantization and Encoding

// Clear all variables and close all previous plots


clear;
clc;
clf;

// Parameters
fs = 1000; // Original sampling frequency (Hz)
t = 0:1/fs:0.1; // Time vector
f_signal = 50; // Frequency of the signal (Hz)
signal = sin(2 * %pi * f_signal * t); // Original signal

// Sampling
fs_sample = 200; // Sampling frequency (Hz)
Ts_sample = 1/fs_sample; // Sampling period
n_sample = 0:Ts_sample:0.1; // Sampled time vector
sampled_signal = sin(2 * %pi * f_signal * n_sample);

// Quantization
num_levels = 16; // Number of quantization levels
max_amplitude = max(abs(sampled_signal)); // Maximum amplitude for
normalization
quantized_signal = round((sampled_signal / max_amplitude) * (num_levels / 2 - 1));
// Quantization

// Encoding
encoded_signal = dec2bin(quantized_signal + num_levels / 2, log2(num_levels)); //
Binary encoding

// Plotting
figure;
subplot(4, 1, 1);
plot(t, signal);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(4, 1, 2);
stem(n_sample, sampled_signal);
title('Sampled Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(4, 1, 3);
stem(n_sample, quantized_signal);

25
title('Quantized Signal');
xlabel('Time (s)');
ylabel('Quantized Value');
grid on;

subplot(4, 1, 4);
disp(encoded_signal);
title('Encoded Signal');
text(0.1, 0.5, 'Check Console for Encoded Signal');
xlabel('Time (s)');
ylabel('Binary Code');
grid on;

// Display the encoded signal in the console


disp('Encoded Signal:');
for i = 1:length(encoded_signal)
disp(encoded_signal(i, :));
end

26
8. Generate a)NRZ, RZ and Raised cosine pulse, b) Generate and plot eye diagram

a) NRZ, RZ and Raised cosine pulse

// Clear all variables and close all previous plots


clear;
clc;
clf;

// Parameters
bit_rate = 1; // Bit rate in bits per second
fs = 100; // Sampling frequency in Hz
T = 1/bit_rate; // Bit duration in seconds
t = 0:1/fs:T-1/fs; // Time vector for one bit

// Generate a random binary sequence


num_bits = 10;
bits = round(rand(1, num_bits));

// NRZ (Non-Return-to-Zero) Pulse Generation


nrz_signal = [];
for i = 1:num_bits
nrz_signal = [nrz_signal bits(i) * ones(1, length(t))];
end

// RZ (Return-to-Zero) Pulse Generation


rz_signal = [];
for i = 1:num_bits
rz_signal = [rz_signal bits(i) * ones(1, length(t)/2) zeros(1, length(t)/2)];
end

// Raised Cosine Pulse Generation


alpha = 0.5; // Roll-off factor
raised_cosine_pulse = [];
for i = 1:num_bits
bit = bits(i);
for j = 1:length(t)
raised_cosine_pulse = [raised_cosine_pulse bit * (cos(2 * %pi * alpha * (t(j) - T/2)
/ T) / (1 - (2 * alpha * (t(j) - T/2) / T)^2))];
end
end

// Plot the pulses


figure;
subplot(3, 1, 1);
plot(0:1/fs:num_bits*T-1/fs, nrz_signal);
title('NRZ Signal');
xlabel('Time (s)');
27
ylabel('Amplitude');
grid on;

subplot(3, 1, 2);
plot(0:1/fs:num_bits*T-1/fs, rz_signal);
title('RZ Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(3, 1, 3);
plot(0:1/fs:num_bits*T-1/fs, raised_cosine_pulse);
title('Raised Cosine Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

b) Generate and plot eye diagram

// Eye Diagram Generation Function


function eye_diagram(signal, fs, T, num_bits)
samples_per_bit = fs * T;
figure;
for i = 1:num_bits-1
segment = signal((i-1)*samples_per_bit+1:(i+1)*samples_per_bit);
plot(0:1/fs:2*T-1/fs, segment);
28
hold on;
end
title('Eye Diagram');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
endfunction

// Generate and plot eye diagram for NRZ signal


eye_diagram(nrz_signal, fs, T, num_bits);

29
9. Generate the Probability density function of Gaussian distribution function.

// Define parameters
mu = 0; // Mean
sigma = 1; // Standard deviation

// Define range
x = linspace(-5, 5, 1000); // Range of x values

// Calculate PDF
pdf = (1/(sqrt(2*%pi)*sigma)) * exp(-((x-mu).^2)/(2*sigma^2));

// Plot PDF
plot(x, pdf, 'b');
xlabel('x');
ylabel('Probability Density');
title('Gaussian Distribution PDF');

30
10. Display the signal and its spectrum of an audio signal.

// Load the audio file (change the file path to your audio file)
[y, Fs] = wavread('path_to_audio_file.wav');

// Plot the time-domain representation of the audio signal


t = (0:length(y)-1) / Fs; // Time vector
plot(t, y);
xlabel('Time (s)');
ylabel('Amplitude');
title('Audio Signal in Time Domain');
grid on;

// Compute the frequency-domain representation (spectrum) of the audio signal


Y = fft(y); // Compute Fourier transform
f = (0:length(Y)-1) * Fs / length(Y); // Frequency vector
magnitude = abs(Y); // Magnitude spectrum

// Plot the magnitude spectrum


figure;
plot(f, magnitude);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude Spectrum of the Audio Signal');
grid on;

31

You might also like