Arab Academy for Science & Technology
and Maritime Transport – Aswan Branch
                                 College of Engineering & technology
                       Electronics & Communication Engineering Department
     Course: Intro. To Digital communication                   Course Code: EC422
     Lecturer: Dr/ Moataz salah
     Tutors: Eng.Hoda khalaf
                                           Lab (0)
1)- Design matlab code calculates the energy and power of sinusoidal signal.
% Parameters
Fs = 1000;          % Sampling frequency
T = 1/Fs;           % Sampling period
t = 0:T:1;          % Time vector
f = 5;              % Frequency of the sinusoid
A = 1;              % Amplitude of the sinusoid
% Generate sinusoidal signal
x = A*sin(2*pi*f*t);
% Calculate energy
energy = sum(x.^2) * T;
% Calculate power
power = energy / length(x);             %total energy /total time
disp(['Energy of the sinusoidal signal: ', num2str(energy)]);
disp(['Power of the sinusoidal signal: ', num2str(power)]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Parameters
Fs = 1000;                 %   Sampling frequency
T = 1/Fs;                  %   Sampling period
t = 0:T:1;                 %   Time vector
f = 5;                     %   Frequency of the sinusoid
A = 1;                     %   Amplitude of the sinusoid
% Generate sinusoidal signal
x = A*sin(2*pi*f*t);
% Calculate energy using numerical integration
energy = trapz(t, x.^2);
% Calculate power (average power)
power = energy / (t(end) - t(1)); % Total energy / total time
disp(['Energy of the sinusoidal signal: ', num2str(energy)]);
disp(['Power of the sinusoidal signal: ', num2str(power)]);
2)- Design matlab code checks the orthogonality of two signals.
clear all;
close all;
clc;
% Define time vector
t = linspace(0, 1, 1000);
% Define frequencies
f1 = 5; % Frequency of the first sinusoid
f2 = 10; % Frequency of the second sinusoid
% Define sinusoidal signals
x1 = sin(2*pi*f1*t);
x2 = sin(2*pi*f2*t);
% Calculate inner product
inner_product = trapz(t, x1 .* x2);
% Check orthogonality
if abs(inner_product) < 1e-10 % Tolerance for numerical errors
     disp('The signals are orthogonal.');
else
     disp('The signals are not orthogonal.');
end
% Plot the signals
figure;
plot(t, x1, 'b', t, x2, 'r');
legend('x1', 'x2');
xlabel('Time');
ylabel('Amplitude');
title('Orthogonal Sinusoidal Signals');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all; close all;
clc;
syms t;
s = -4:0.1:4;
x1 = 5.*cos(2*pi*10*t);
x2 = sin(2*pi*10*t);
y = x1.*x2;
orth = int(y, t, 0, 2);
disp ('the orthogonality is equal to ' )
disp(orth)
Help commands:
[sin, subplot, plot]
3-   Ideal sampling
% Parameters
Fs = 1000;                % Sampling frequency
t = 0:1/Fs:1;             % Time vector
f = 5;                    % Signal frequency
A = 1;                    % Amplitude
% Continuous-time signal
x = A * sin(2 * pi * f * t);
% Ideal sampling
T_sample = 0.1;           % Sampling period
t_sample = 0:T_sample:1; % Sampling instances
x_sampled = A * sin(2 * pi * f * t_sample);
% Plot
subplot(2,1,1);
plot(t, x);
title('Continuous-Time Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(2,1,2);
stem(t_sample, x_sampled);
title('Ideal Sampled Signal');
xlabel('Time (s)');
ylabel('Amplitude');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=4;
fm=2;
fs=100*fm;
t=0:1/fs:1;%for sampling
x=a*sin(2*pi*fm*t);%let us take one simple sin signla for
Pulse code modulation
subplot(5,1,1);
plot(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('Original message signal');
subplot(5,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('Sampled message signal');
4-sampling and quantization
a=4;
fm=2;
fs=100*fm;
t=0:1/fs:1;%for sampling
x=a*sin(2*pi*fm*t);%let us take one simple sin signla for
Pulse code modulation
subplot(5,1,1);
plot(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('Original message signal');
subplot(5,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('Sampled message signal');
 for i=1:length(x)
 if (x(i)>0 && x(i)<=1)
 e=[1 0 0];
 xq(i)=0.5;
 elseif (x(i)>1 && x(i)<=2)
 e=[1 0 1];
 xq(i)=1.5;
 elseif (x(i)>2 && x(i)<=3)
 e=[1 1 0];
 xq(i)=2.5;
 elseif (x(i)>3 && x(i)<=4)
 e=[1 1 1];
 xq(i)=3.5;
 elseif (x(i)>-4 && x(i)<=-3)
 e=[0 0 0];
 xq(i)=-3.5;
 elseif (x(i)>-3 && x(i)<=-2)
 e=[0 0 1];
 xq(i)=-2.5;
 elseif (x(i)>-2 && x(i)<=-1)
 e=[0 1 0];
 xq(i)=-1.5;
 elseif (x(i)>-1 && x(i)<=0)
 e=[0 1 1];
 xq(i)=-0.5;
 end
 %enc=[enc e];
 end
 subplot(5,1,3);
 plot(t,xq,'b');
 title('Quantised signla');