Iot Labetronical
Iot Labetronical
DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINEERING
IV SEMESTER
NEP - 2022 Scheme
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
CONTENTS
Sl.No. Experiments
5 Sampling and reconstruction of low pass signals. Display the signals and its
spectrum.
8 Generate a)NRZ, RZ and Raised cosine pulse, b) Generate and plot eye diagram
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 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.
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.
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).
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.
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
10
// Scilab script to generate and plot a triangular wave signal
11
// Scilab script to generate and plot a sinusoidal wave signal
12
// Scilab script to generate and plot an exponential signal
13
2.Illustration of signal representation in time and frequency domains for a
rectangular pulse.
14
15
3.Amplitude Modulation and demodulation: Generation and display the relevant
signals and its spectrums.
// 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);
// 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);
// Parameters
fs = 10000; // Sampling frequency
t = 0:1/fs:0.1; // Time vector
// Carrier signal
fc = 200; // Carrier frequency
// 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);
// 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
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.
// Parameters
fs = 1000; // Original sampling frequency (Hz)
t = 0:1/fs:0.1; // Time vector for original signal
// 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);
// 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
// Define parameters
sampling_rate = 1000; // Sampling rate in Hz
duration = 1; // Duration in seconds
t = 0:1/sampling_rate:duration; // Time vector
subplot(3, 1, 2);
plot(t, signal2);
title('Original Signal 2 (7 Hz cosine)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
figure();
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
// 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;
26
8. Generate a)NRZ, RZ and Raised cosine pulse, b) Generate and plot eye diagram
// 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
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;
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');
31