Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
20 views27 pages

Signals and Systems Lab 1

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)
20 views27 pages

Signals and Systems Lab 1

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/ 27

Signals and systems Lab 1

Denzel Onyango Ninga


March 2025

1 Abstract
In this lab report, I will be able to analyse and explain the plots of specific
signals: signum, rectangular, triangular, sinc, impulse, step, square, discrete
exponential, and discrete cosine.I will also analyze the relationship between
frequencies for discrete cosine and exponential signals. I will State and verify
the Cauchy-Schwarz inequality, Classify systems based on linearity, time-
invariance, causality, and stability and perform advanced signal operations
and analyze their properties.By use of MATLAB plot and calculate these ,
I’ll verify.

2 Introduction
First off, a signal is a function representing a physical quantity or variable
and a system is a mathematical model of a physical process that relates the
input signal to the output signal. The origin of the word systems dates back
to the 15th century, when it was used as a Latin word systema, which means
the entire universe.1 Signal and system concepts arise in a wide variety of ar-
eas, from home-oriented consumer electronics and multimedia entertainment
products to sophisticated communications, aeronautics and astronautics, and
control. Of course, signals and systems are the entire universe, prove me
wrong! Signals and systems are the backbone of communication.
1
Fatoş Tunay Yarman Vural and Emre Akbaş, Signals and Systems: Theory and Prac-
tical Explorations with Python (CRC Press, 2022), p. 19.

1
3 Methodology
Most of this lab was completing the skeleton codes provided in the Lab
Manual ’Signal and System Analysis Lab 1’.I did this using MATLAB R2024b
and I did use alternatives for certain codes since I just did not have certain
toolboxes such as the rectangular Toolbox, so I used Rectangular function
alternatively for rectangularPulse, but believe me ,you! It was a success. I
ran all my codes in the live script in MATLAB, ran each section separately,
making the necessary changes to ensure it was a success and of course it was.
Also, I did the hand calculations and verified the results.It was rough here
as I was involved with finding the inner product and calculating the catchy-
schwartz inequalities, thanks to Indian YouTubers-they are geniuses.The
YouTube channel The grade Academy ,video titled ’Real Analysis lecture
10 -catchy-schwartz inequality Proof’ was a life saver.2 The methodology
included:

• Running MATLAB codes to generate and analyze signal plots.

• Reading necessary materials,including Textbooks to understand various


concepts and just to cross check them.

• Watching YouTube videos to grasp the underlying concepts.

• Performing hand calculations to verify MATLAB results and ensure


theoretical accuracy.

• Researching the internet and using ChatGPT to understand concepts


,while ensuring it is never misused.

4 Results
The results after completing or even making necessary improvements to the
MATLAB skeleton codes were as follows;
2
The Grade Academy, Real Analysis Lecture 10 - Cauchy-Schwarz Inequality
Proof,YouTube,Published on[2021],https://youtu.be/i851HnlBpv8?si=HBe9MPFa9HZwLYDF,accessed
on [18/3/2025].

2
5 MATLAB Code
The MATLAB code used in this lab is provided in the following PDF.
It contains the full implementation for generating and analyzing the sig-
nals:

3
Exercise 1: Plotting Specific Signals

Tasks: Plot the continuous-time (CT) signals and discrete-time (DT) signals

using subplots. Complete the missing trit_t and sinc_t functions.

% Continuous-Time (CT) Signals


t = -5:0.01:5;

% Signum function
sgn_t = sign(t);

% Rectangular function (Alternative for rectangularPulse)


rect_t = double(abs(t) <= 0.5);

% Triangular function
tri_t = (1 - abs(t)) .* (abs(t) <= 1);

% Sinc function (Using MATLAB's built-in sinc function)


sinc_t = sinc(t);

% Plot CT signals
figure;
subplot(2,2,1); plot(t, sgn_t); title('Signum Function');
subplot(2,2,2); plot(t, rect_t); title('Rectangular Function');
subplot(2,2,3); plot(t, tri_t); title('Triangular Function');
subplot(2,2,4); plot(t, sinc_t); title('Sinc Function');

1
% Discrete-Time (DT) Signals
n = -10:10;

% Impulse function
delta_n = (n == 0);

% Step function
u_n = (n >= 0);

% Square impulse (nonzero for n = 0,1,2,3,4)


square_n = (n >= 0) & (n < 5);

% Discrete exponential
exp_n = exp(1j * pi * n / 5);

% Discrete cosine (added as a missing subplot)


cos_n = cos(pi * n / 5);

% Plotting DT signals in a 2x3 grid so that all signals are visible.


figure;
subplot(2,3,1); stem(n, delta_n, 'filled'); title('Impulse Function');
subplot(2,3,2); stem(n, u_n, 'filled'); title('Step Function');
subplot(2,3,3); stem(n, square_n, 'filled'); title('Square Impulse');

2
subplot(2,3,4); stem(n, real(exp_n), 'filled'); title('Discrete
Exponential');
subplot(2,3,5); stem(n, cos_n, 'filled'); title('Discrete Cosine');

Exercise 2: Frequency Analysis Using Subplots

Tasks: Implementing exp_k and exp_l for discrete exponential signals.

N = 10;
n = 0:N-1;
k = 2;
l = N - k;

% Discrete Cosine signals


cos_k = cos(2*pi*k*n/N);
cos_l = cos(2*pi*l*n/N);

% Discrete Exponential signals


exp_k = exp(1j * 2 * pi * k * n / N);
exp_l = exp(1j * 2 * pi * l * n / N);

% Plot Cosine signals

3
figure;
subplot(2,1,1); stem(n, cos_k, 'filled'); title(['Cosine: k = ',
num2str(k)]);
subplot(2,1,2); stem(n, cos_l, 'filled'); title(['Cosine: l = ',
num2str(l)]);

% Plot Exponential signals (real parts)


figure;
subplot(2,1,1); stem(n, real(exp_k), 'filled'); title(['Exponential: k = ',
num2str(k)]);
subplot(2,1,2); stem(n, real(exp_l), 'filled'); title(['Exponential: l = ',
num2str(l)]);

4
Exercise 3: Completing Inner Products, Energy, and Power

Tasks: Compute inner products, energy of signals, power of periodic signals,

verify the Cauchy-Schwarz inequality.

% Discrete-Time (DT) Inner Product


n = 0:9;
x_dt = cos(2*pi*n/10);
y_dt = sin(2*pi*n/10);
inner_dt = sum(x_dt .* conj(y_dt));

% Display DT inner product result


fprintf('DT Inner Product = %.16f\n', inner_dt);

DT Inner Product = -0.0000000000000001

% Continuous-Time (CT) Inner Product


t = 0:0.01:1;
x_ct = sin(2*pi*t);
y_ct = cos(2*pi*t);

5
inner_ct = trapz(t, x_ct .* conj(y_ct)); % Using trapz for numerical
integration

% Display CT inner product result


fprintf('CT Inner Product = %.16f\n', inner_ct);

CT Inner Product = 0.0000000000000000

% Energy Calculation
% DT Energy
energy_x_dt = sum(abs(x_dt).^2);
energy_y_dt = sum(abs(y_dt).^2);

% CT Energy
energy_x_ct = trapz(t, abs(x_ct).^2);
energy_y_ct = trapz(t, abs(y_ct).^2);

% Display Energy Results


fprintf('DT Energy of x_dt = %.16f\n', energy_x_dt);

DT Energy of x_dt = 4.9999999999999991

fprintf('DT Energy of y_dt = %.16f\n', energy_y_dt);

DT Energy of y_dt = 5.0000000000000009

fprintf('CT Energy of x_ct = %.16f\n', energy_x_ct);

CT Energy of x_ct = 0.5000000000000000

fprintf('CT Energy of y_ct = %.16f\n', energy_y_ct);

CT Energy of y_ct = 0.5000000000000000

% Power Calculation (Average energy over time)


power_x_ct = energy_x_ct / (max(t) - min(t));
power_x_dt = energy_x_dt / length(n);

% Display Power Results


fprintf('CT Power of x_ct = %.16f\n', power_x_ct);

CT Power of x_ct = 0.5000000000000000

fprintf('DT Power of x_dt = %.16f\n', power_x_dt);

DT Power of x_dt = 0.4999999999999999

% Verify Cauchy-Schwarz Inequality


cauchy_schwarz_dt = abs(inner_dt) <= sqrt(energy_x_dt * energy_y_dt);
cauchy_schwarz_ct = abs(inner_ct) <= sqrt(energy_x_ct * energy_y_ct);

6
% Display Cauchy-Schwarz Results
disp(['Cauchy-Schwarz DT holds: ', num2str(cauchy_schwarz_dt)]);

Cauchy-Schwarz DT holds: 1

disp(['Cauchy-Schwarz CT holds: ', num2str(cauchy_schwarz_ct)]);

Cauchy-Schwarz CT holds: 1

Exercise 4: System Classifications

Tasks: Check Linearity and Time-Invariance for CT and DT systems.

Check Causality and Stability of given systems.

% Linearity and Time-Invariance (CT)


t = 0:0.01:5;
x1 = sin(2*pi*t);
x2 = cos(2*pi*t);
y1 = x1 + circshift(x1, 100);
y2 = x2 + circshift(x2, 100);
y3 = x1 + x2 + circshift(x1 + x2, 100);
is_linear_ct = isequal(y1 + y2, y3);

% Linearity and Time-Invariance (DT)


n = 0:50;
x1_dt = sin(2*pi*n/10);
x2_dt = cos(2*pi*n/10);
y1_dt = x1_dt + circshift(x1_dt, 10);
y2_dt = x2_dt + circshift(x2_dt, 10);
y3_dt = x1_dt + x2_dt + circshift(x1_dt + x2_dt, 10);
is_linear_dt = isequal(y1_dt + y2_dt, y3_dt);

% Causality and Stability


% For CT System: Integral from -∞ to t (example representation)
syms tau t_sym;
x_tau = exp(-tau);
y_t = int(x_tau, tau, -inf, t_sym); % This is an example; in practice, a CT
system's causality is determined by its impulse response.

% For DT System: Summation from -∞ to n (example representation)


syms k n_sym;
x_k = k^2;
y_n = symsum(x_k, k, -inf, n_sym); % Example sum (diverges, but used here
illustratively)

% Checking causality (using the signal domains)


is_causal_ct = all(t >= 0); % System is causal if t >= 0 (for t vector
defined earlier)

7
is_stable_ct = energy_x_ct < inf; % System is stable if it has finite energy

is_causal_dt = all(n >= 0); % System is causal if n >= 0


is_stable_dt = energy_x_dt < inf; % System is stable if it has finite energy

% Display system classification results


disp(['System is Linear (CT): ', num2str(is_linear_ct)]);

System is Linear (CT): 0

disp(['System is Linear (DT): ', num2str(is_linear_dt)]);

System is Linear (DT): 0

disp(['System is Causal (CT): ', num2str(is_causal_ct)]);

System is Causal (CT): 1

disp(['System is Causal (DT): ', num2str(is_causal_dt)]);

System is Causal (DT): 1

disp(['System is Stable (CT): ', num2str(is_stable_ct)]);

System is Stable (CT): 1

disp(['System is Stable (DT): ', num2str(is_stable_dt)]);

System is Stable (DT): 1

8
6 Discussion and Analysis
Here is an experimental insertion of a discussion part made in WPS Office:

12
DISCUSSIONS AND OBSERVATIONS

Exercise 1: Plotting Specific Signals

1) Continuous-Time (CT) Signals

The following were the results after running the codes for the continuous-time signals

1.Signum function
From the graph above for the signum function, it can be observed that the graph
jumps to +1 for positive values of the signal, but dips to -1 for the negative values of
the signal. This implies that the signum function is used to show whether a signal is
positive or negative. The word itself “signum” comes from a latin word meaning
‘mark,’ what else do you think it shows if not the sign of a signal(positive or negative)?
It
is an odd mathematical function which extracts the sign of a real number.
The signum function usually satifies the following conditions;
 If the number is positive, the function returns 1 (.sgn(t)=1 for t > 0)
 If the number is zero, it returns 0.(sgn(t)=0 for t = 0)
 If the number is negative, it returns -1 (sgn(t)=−1for t < 0)
These conditions basically proves the math representing the signum function,
Thus the lab was a success as this was proved.
Application(s) of signum function
 Detecting the change of signs
 Zero crossing

2. Rectangular function
Observing the graph of the rectangular function above ,it is seen that the signal is
rectangular shaped . We can see that the height of that rectangle is one, and if a centre
line is to be drawn that cuts the rectangle in the middle( along its width), it passes
through t=0.The rectangular signal is also known as the unit pulse. Also, the
rectangular function is an even function of time because it satisfies the condition:
x(t)=x(-t)
Mathematically, the unit rectangular signal is defined as,

The signal graphed basically just proves this, hence this was a success.
Application(s) of rectangular function
 Systems use rectangular pulses as the base shape for sending bits over a channel.

3.Triangular function:
Again here ,it is so clear that the graphed signal took the shape of a triangular
signal .The triangular signal is also an even function of time as observed as well, it
satisfies that same condition to be an even signal.
Mathematically , it satifies:
This was also successfully verified.
Application(s) of triangular functions
 Used in signal analysis system as it is has certain frequency analysis properties
which makes it a useful function. This include tasks like filtering and
interpolation of signals in communication.
4..Sinc function: sinc(t)
From my plots above, the sinc function shows a clear central peak at t = 0, where its
value is 1. The oscillations diminish symmetrically on either side of t=0 verifying that
it is an even function.
Mathematically, it is defined as;

So , all the functions for the CT signals were a success.


The advantage(s) of Sinc Function
 Its even symmetric nature along with its oscillating property is very useful which
is applied in various modulation schemes
.
The disadvantage(s) of Sinc Function
 It oscillates between negative and positive infinity without dropping amplitude to
0. This can be a major problem when using it in computer applications due to
infinite support.

Application(s) of Sinc Function


 Used in signal analysis system as it is has certain frequency analysis properties
which makes it a useful function. This include tasks like filtering and
interpolation of signals in communication.
This code implementation was a success.

2) Discrete time (D.T) signals


The following were the results after running the codes for the discrete-time signals

1. Impulse function

From the above graph for the impulse function , it’s observed that impulse function
has only one nonzero value at the origin, which is equal to 1.That’s why it’s called a
unit impulse function. Otherwise all zeros. We see a small dot at every point to show
that the height is either zero or finite value of 1, at n = 0.
Mathematically , this function is ;

This was a success.


Application(s) of impulse function
By using the impulse function as an input, it helps in deriving the impulse response
of a system, this helps in understanding how systems process different signals.
2. Step function
This function suddenly rises to one and remains the same from n = 0 to positive
values.
By observation , the step function is 0 for negative values of its argument and 1 for
the positive values of its argument.We see little dots at the top of each bar of
magnitude one and zero showing that the function exists at only integer values and it
is bounded for all values of n, as shown in the graph above.
Mathematically;

;
This was implemented successfully.
Application(s) of step function
Can be used for modelling sudden changes in a system, such as a switching
system ,that is , turning it on and off.
3. Square impulse function

It is observed that the amplitude of the signal remains one from n=0 to n= 5,
otherwise it’s 0.This creates a ‘block’ or ‘pulse’ shape in the discrete domain.This
observation satisfies the definition of a square impulse function; it usually remains
constant at 1 for a given amount of time.
Mathematically ;

The lab was a success.


Application(s) of square impulse function
Can be used in modelling time-limited signals since they remain constant for limited
amount time .
4. Discrete exponential function
As shown in the Discrete Exponential plot, the real part oscillates between
positive and negative values. This signal maintains a constant magnitude of 1,
indicating that it’s tracing out points on the unit circle in the complex plane. The
periodicity in the real part is evident.
Mathematically ;

This was successful.


5. Discrete cosine function

It can be observed that the discrete cosine and the discrete exponential functions are
Identical.They have the same frequencies
Mathematically;

This was satisfied , hence success.

This Exercise 1: Plotting Specific Signals, was a success , the D-T and C-T plots
confirmed the theoretical and mathematical description. I understood most of them
clearly.
Exercise 2: Frequency Analysis Using Subplots
1. DiscreteCosine
Frequency Analysis of Discrete Cosine Signal
Below were the output of the codes after running them on MATLAB;

The above are subplots since they are just smaller plots of a larger figure, they help in
comparison and analysis .
Now , it’s observable that the top subplot is a discrete cosine signal with k=2 and the
downer one is a cosine function with l = 8, but again the difference in the values of k
and l doesn’t mean one has a higher frequency than the other.We can observe that the
two signals are identical, which implies symmetrical frequency.
This is Due to the periodic nature of discrete signals, l=8 is equivalent to k= −2,
meaning both signals represent the same frequency component but in different forms
(negative and positive). This demonstrates frequency symmetry in the discrete domain.
Mathematically ;
k +l = N that is 8+2=10,
verifying the Discrete Fourier Transform (DFT) symmetry properties.
This was successfully implemented.
2. Discrete Exponential
Frequency Analysis of Discrete Exponential Signals
After successfully running the code for discrete exponential signals in MATLAB,
the output were as shown below;

This is very similar to the previous analysis of the discrete cosine signal.As
observed the values of k and l differ , but not frequency .The two signals are similar
visually, thus symmetrical frequency.Since k + l= N, this implies that l=8 is just
another way of writing k = -2, which is actually the same frequency but in a
different form. This shows DFT symmetry, where certain frequencies repeat and
appear mirrored.
Mathematically, it was successful.

Exercise 3: Inner Products and Energy


1. Inner product
The following were the result after running the code in MATLAB vs by hand
calculation respectively;
For descrete-time
The results of D.T inner product by hand was exactly =0, while the one for
MATLAB was -0.0000000000000001 which is very close to 0, the difference
comes in that floating-point arithmetic in MATLAB can produce tiny residual, but
it’s just zero.
The MATLAB result, which is effectively 0, confirms the orthogonality property.
Therefore this lab was successful.
For continuous-time
In MATLAB and by hand respectively;

In MATLAB , this was exactly =0,the same as the hand calculations.


The MATLAB result, which is effectively 0, confirms the orthogonality property.
Therefore this lab was successful.
2. Energy and Power
By hand;

Both energy and power of the signal x(t) = sin(2πt), are both 0.5 , and this was
verified by the running the codes as well as shown below;
And power ;

This was a success .


3. Cauchy-Schwartz Inequality
According to the Cauchy-Schwartz inequality in an inner product space, we must
have;

The code confirmed the inequality was satisfied since output = 1 for both the CT
and DT signals,

indicating that our numerical computations are consistent with the theoretical
properties of inner product spaces.
Hence this was a success.
Exercise 4: System Classifications

1. Linearity and Time-Invariance


Linearity
A system is said to be linear if it holds the superposition theory, that is both;
 Additivity (i.e., y1+y2=y)
 Homogeneity (or Scaling) (i.e y=ky1)
For both the systems y(t) = x(t) + x(t-1) in CT and y[n] = x[n] + x[n-1] in DT,
linearity fails because it doesn’t satisfy the two conditions here. The MATLAB code
verified this part by displaying
0;

This was a success.


Time-Invariance
A system is called time-invariant if a time shift (delay or advance) in the input signal
causes the same time shift in the output signal, thus there is no change in the shape of
the output signal if there is time shift.
Mathematically;
 y(t − t0)=h(x(t − t0)). for CT signals
 y[n −n0]=h[x[n−n0]]. for DT signals
Now this was not the case here ;
The presence of the shifted term (x(t−1) for CT or x[n−1] for DT causes the system's
output to vary depending on the input's time shift, thus the system is NOT time-
invariant. The MATLAB code verified this by displaying 0
This was a successful.
2. Causality and Stability
Causality
By definition, the output of a causal system at the present time depends on only the
present and/or past values of the input, not on its future values. Therefore , all
memoryless systems are causal,though not vice varsa. Responses cannot come before
the signals in causal systems. Mathematically, the signal in question here;

Both of them both for CT and DT depends on the past inputs, because of the
presence of negative infinity. So the summation all leads to dependence on past inputs,
and then the presence of both t and k also shows dependence on present inputs, thus it
is a causal system.
This was verified by our MATLAB code as it returned 1 for both CT and DT signals;

This was successfully verified.

Stability
By definition, a BIBO stable system produces bounded outputs for bounded
inputs.Mathematically an input |x(t)| ≤ b leads to are corresponding output |y(t)| ≤ c ,
where c and b are finite for CT signals , or |x[n]| ≤ b leads to |y[n]| ≤ c , for DT signals.
In our case here ,the CT system's energy is finite, and the DT system's energy is also
finite, as verified by our energy calculations. Hence, both systems are stable.
After running the code on MATLAB , this was verified as it returned 1;

Thus our lab was a success in everything.

You might also like