Introduction To SP
Introduction To SP
Table of Contents
What is a Signal?
• Dependent and Independent variables
• Types-1D,2D,3D-Examples
MATLAB Basics
Classification of Signals
• Continous time and discrete time signals
• Deterministic and random signals
• Even and odd signals
What is a Signal?
• Any physical quantity that carries information.
• physical quantity-dependent variable(amplitude,intensity,distance,velocity...)
• physical quantity that varies with one or more independent
variables(time,pressure,temperature ...)
• Both the independent variable and the physical variable can be either scalars or vectors
Note:
The independent variable is the one you change or control in an experiment. Sometimes this is called the
manipulated variable
1
How do you remember what independent and dependent variables are and where to put them on the graph?
There is a handy acronym: DRY MIX
D = dependent variable
R = responding variable
M = manipulated variable
I = independent variable
Types of Signals
• Signals are defined as a function of one or more independent variables.
Other examples:
• Sound wave: The amplitude (volume) of a sound wave varies over time.
2
Courtesy:Springerlink
• Electrocardiogram (ECG).: An ECG measures the electrical activity of the heart over time.
Note:The brightness or color intensity of each pixel in an image changes based on its x and y position within the
image
3
➢ Eg. of 3 dimensional signal – Video signal represented by f(x,y,t)
Note:A video is nothing else but two dimensional pictures move over time (third) dimension.
Signal Processing-Processing of signals-Signal processing is the art of extracting insights and valuable
information from signals, which are functions that convey data.
4
- Analyze signals to extract features or characteristics
1. Signal Processing Engineer: Design and develop algorithms for signal processing applications using AI
techniques.
2. AI Research Scientist: Conduct research in AI and signal processing to develop new theories and
applications.
3. Data Scientist: Analyze and interpret complex data using AI and signal processing techniques.
4. Machine Learning Engineer: Develop and implement machine learning models for signal processing
applications.
5. Computer Vision Engineer: Apply AI and signal processing techniques to image and video processing.
6. Audio Processing Specialist: Use AI and signal processing to analyze and enhance audio signals.
7. Biomedical Signal Processing Specialist: Apply AI and signal processing techniques to biomedical signals
like ECG, EEG, etc.
5
8. Control Systems Engineer: Design and develop control systems using AI and signal processing techniques.
9. Robotics Engineer: Apply AI and signal processing to robotics and autonomous systems.
10. Quantum Signal Processing Specialist: Explore the intersection of quantum computing and signal
processing using AI techniques
Classification of signals
eg: Asinwt
w=2*pi*f
plot(t,y1)%plot(x,y)
xlabel('Time')%(label of x-axis)
ylabel('Amplitude')%label of y-axis
t = 1×501
6
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700
%pi
y1
y1 = 1×501
0 0.3140 0.6267 0.9369 1.2434 1.5451 1.8406 2.1289
grid on
➢ Discrete time signals are defined for only integer values of time- represented as x(n).
7
xlabel('Time'); % Label the x-axis as 'Time'
% Generate a sine wave with the given frequency and time vector
x = sin(2*pi*f*t);
8
plot(t, x); % Plot x vs. t
% Set the sampling frequency (fs1) to twice the value of f (which needs to be
defined)
fs1 = 2*f;
% Generate the sinusoidal signal (y1) with frequency f, sampled at points specified
by n
y1 = sin(2*pi*n*f/fs1);
% Open a new figure window (or make the existing figure 2 the current window)
figure(2);
9
2.Deterministic and random signals
Deterministic signals
➢ we can predict the result or the graphical representation with the help of that formula
% Create a time array t with values ranging from 0 to 1, with a step size of 0.01
t = 0:0.01:1;
% Generate the sine wave signal x using the time array t and frequency f
x = sin(2*pi*f*t);
10
% Set the y-axis label to "Amplitude"
ylabel('Amplitude');
Random signals
11
% Set the title of the plot to "Random Signal"
title('Random Signal');
➢ The odd signals are signals that is unsymmetrical at the time origin or the vertical
axis
➢ Mathematically x(t)=-x(-t)
x(-t)=-Asint
% Create a time array t with values ranging from 0 to 2, with a step size of 0.01
t = 0:0.01:2;
12
% Set the frequency f to 1 Hz
f = 1;
% Generate the sine wave signal x using the time array t and frequency f
x = sin(2*pi*f*t);
% Plot the original signal x in blue and the time-reversed signal x0 in red
plot(t, x, 'b', t, x0, 'r');
13
Even signals
➢ The even signals are signals that is symmetrical at the time origin or the vertical
axis
➢ Mathematically x(t)=x(-t)
x(-t)= Acost
% Create a time array t with values ranging from 0 to 2, with a step size of 0.01
t = 0:0.01:2;
% Generate the cosine wave signal x using the time array t and frequency f
x = cos(2*pi*f*t);
% Plot the original signal x as a solid line and the time-reversed signal x0 as
asterisks
plot(t, x, '-', t, x0, '*');
14
Basic Operations on Signals
1.Signal Addition
The addition of the signal is the process in which the amplitude of two signals is added and as a result, the
signal obtain has the combination amplitude of both of these. The simplest example of this operation is:
x1=sin(2πt)
x2=cos(2πt)
y=x1+x2
The resultant Y has the value of the addition of both these signals.
% Define a time array t with values ranging from 0 to 0.1, with a step size of 0.01
t = 0:0.01:0.1;
% Define the frequency f as 25 Hz
f = 25;
% Generate the angular frequency array t1 by multiplying the time array t with
2*pi*f
t1 = 2*pi*f*t;
% Generate the sine wave signal x1 using the angular frequency array t1
x1 = sin(t1);
15
% Create the first subplot and plot the signal x1
subplot(3,1,1);%creates a subplot grid with 3 rows and 1 column, and selects the
first subplot (topmost) for plotting.
plot(t,x1);
title('x1'); % Set the title of the first subplot
grid on; % Turn on the grid for the first subplot
% Generate the cosine wave signal x2 using the angular frequency array t1
x2 = cos(t1);
16
% Define signal x1 as a vector
x1 = [1 2 3 1 1];
% Create the first subplot in a 3x1 grid and select it for plotting
subplot(3,1,1);
% Set the x-axis ticks and labels for the first subplot
xticks(1:5);
xticklabels({'1','2','3','4','5'});
17
% Enable grid for the first subplot
grid on;
% Create the second subplot in a 3x1 grid and select it for plotting
subplot(3,1,2);
% Set the x-axis ticks and labels for the second subplot
xticks(1:5);
xticklabels({'1','2','3','4','5'});
% Create the third subplot in a 3x1 grid and select it for plotting
subplot(3,1,3);
% Set the x-axis ticks and labels for the third subplot
xticks(1:5);
xticklabels({'1','2','3','4','5'});
18
2.Signal Substraction
Subtraction between the two signals takes place when the value of the second signal (the one that is written
after the subtraction sign) is subtracted from the first signal.
t=0:0.01:0.1
t = 1×11
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700
f=25;
t1=2*pi*f*t;
x1=sin(t1);
subplot(3,1,1)
plot(t,x1)
title('x1')
ylabel('Amplitude')
19
grid on;
x2=cos(t1)
x2 = 1×11
1.0000 0.0000 -1.0000 -0.0000 1.0000 -0.0000 -1.0000 0.0000
subplot(3,1,2)
plot(t,x2)
title('x2')
ylabel('Amplitude')
grid on;
y = 1×11
-1.0000 1.0000 1.0000 -1.0000 -1.0000 1.0000 1.0000 -1.0000
subplot(3,1,3)
plot(t,y)
title('y= x1-x2')
xlabel('Time')
ylabel('Amplitude')
grid on;
ylim([-2 2]) % Set y-axis limits to [-2 2]
20
x1 = [1 2 3 4 5];
x2 = [2 4 6 8 10];
y = x2 - x1;
%y = x1 - x2;
subplot(3,1,1); stem(x1, 'Color', 'red'); title('x1'); xline(0); xticks(1:5);
xticklabels({'1','2','3','4','5'});
subplot(3,1,2); stem(x2, 'Color', 'green'); title('x2'); xline(0); xticks(1:5);
xticklabels({'1','2','3','4','5'});
subplot(3,1,3); stem(y, 'Color', 'blue'); title('y = x1 - x2'); xline(0);
xticks(1:5); xticklabels({'1','2','3','4','5'});
21
2.Signal Multiplication
The multiplication of two signals is obtained when the values of the amplitude of two
signals are multiplied and the resultant signal has the multiplied amplitude.
t=0:0.01:0.1
t = 1×11
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700
f=25;
t1=2*pi*f*t;
x1=sin(t1);
subplot(3,1,1)
plot(t,x1)
title('x1')
ylabel('Amplitude')
grid on;
22
x2=cos(t1)
x2 = 1×11
1.0000 0.0000 -1.0000 -0.0000 1.0000 -0.0000 -1.0000 0.0000
subplot(3,1,2)
plot(t,x2)
title('x2')
ylabel('Amplitude')
grid on;
y = 1×11
10-14 ×
0 0.0061 -0.0122 0.0184 -0.0245 -0.0582 0.1409 -0.1348
subplot(3,1,3)
plot(t,y)
title('y= x1*x2')
xlabel('Time')
ylabel('Amplitude')
grid on;
23
x1 = [1 2 3 1 1];
x2 = [1 2 2 1 2];
y = x1 .* x2;
subplot(3,1,1);
stem(x1, 'Color', 'red');
title('x1');
xline(0);
xticks(1:5);
xticklabels({'1','2','3','4','5'});
subplot(3,1,2);
stem(x2, 'Color', 'green');
title('x2');
xline(0);
xticks(1:5);
xticklabels({'1','2','3','4','5'});
subplot(3,1,3);
stem(y, 'Color', 'blue');
title('y = x1 .* x2'); % Element-wise multiplication
xline(0);
xticks(1:5);
xticklabels({'1','2','3','4','5'});
24
Note: Multiplication -element wise multiplicaion.Without a dot, MATLAB performs the operation of an array
operation, but for the multiplication of a single element with other single elements, we need the matrix type of
multiplication.
3.Time scaling
Depending on the magnitude of the constant or scaling factor, the time scale of a signal
has two possibilities:
1. Compression
2. Expansion
t = 1×2514
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700
x=sin(t);
subplot(3,1,1)
25
plot(t,x)
title('Simple Signal')
xlabel('Time')
ylabel('Amplitude')
grid on;
y = 1×2514
0 0.0050 0.0100 0.0150 0.0200 0.0250 0.0300 0.0350
subplot(3,1,2)
plot(t,y)
title('Expanded Signal')
xlabel('Time')
ylabel('Amplitude')
grid on;
z = 1×2514
0 0.0200 0.0400 0.0600 0.0799 0.0998 0.1197 0.1395
subplot(3,1,3)
plot(t,z)
title('Compressed Signal')
xlabel('Time')
ylabel('Amplitude')
grid on;
26
% Define a function named rect that takes one input argument t
function y = rect(t)
% The function returns 1 (true) if t is within the range [-0.5, 0.5) and 0
(false) otherwise
y = (t >= -0.5) & (t < 0.5);
end
t = -2:0.01:2;
x = rect(t); % Rectangular function
subplot(3,1,1);
plot(t,x);
title('Simple Rectangular Signal');
xlabel('Time');
ylabel('Amplitude');
ylim([0 2]); % Set y-axis limits to [0 5]
grid on;
y = rect(t/2);
subplot(3,1,2);
plot(t,y);
title('Expanded Signal');
xlabel('Time');
ylabel('Amplitude');
ylim([0 2]); % Set y-axis limits to [0 5]
grid on;
z = rect(t*2);
subplot(3,1,3);
plot(t,z);
title('Compressed Signal');
xlabel('Time');
ylabel('Amplitude');
ylim([0 2]); % Set y-axis limits to [0 5]
grid on;
27
3.Time shifting
The process of moving a signal forward or backward in time, the time shifting of a signal
has two possibilities:
1. Addition in Time Shifting-The whole signal moves towards the right side and the
amplitude does not change.
2. Substraction in Time Shifting- Here the signal moves towards left side.
t=0:4;
x=[0 1 2 1 0];
subplot(3,1,1)
plot(t,x)
xlabel('Time')
ylabel('Amplitude')
grid on;
28
axis([-2 8 0 4]);% Set x-axis range to [-2, 8] and y-axis range to [0, 4]
subplot(3,1,2)
plot(t+2,x)%plot will be shifted 2 units to the right compared to the original plot
xlabel('Time')
ylabel('Amplitude')
grid on;
axis([-2 8 0 4]);%The axis([-2 8 0 4]) command sets the axis limits for the plot,-2
to 8 for x-axis and 0 to 4 as y axis
subplot(3,1,3)
xlabel('Time')
ylabel('Amplitude')
grid on;
axis([-2 8 0 4]);% Set x-axis range to [-2, 8] and y-axis range to [0, 4]
n = 0:5;
x = [0 1 2 3 1 0];
subplot(3,1,1);
stem(n,x);
title('Simple Discrete Signal x(n)');
xlabel('Time');
ylabel('Amplitude');
grid on;
axis([-2 8 0 4]);% Set x-axis range to [-2, 8] and y-axis range to [0, 4]
29
General Error occurred in WebControllerFactory::create()
subplot(3,1,2);
stem(n+2,x);
title('Shifting by Addition x(n + 2)');
xlabel('Time');
ylabel('Amplitude');
grid on;
axis([-2 8 0 4]);% Set x-axis range to [-2, 8] and y-axis range to [0, 4]
subplot(3,1,3);
stem(n-2,x);
title('Shifting by Subtraction x(n - 2)');
xlabel('Time');
ylabel('Amplitude');
grid on;
axis([-2 8 0 4]);
4.Time reversal
The process of flipping the whole signal by using the flipping function or by multiplying
the whole signal with a negative number is called reversal of the signal because each and
every value of signals is reversed.
t=0:10;
30
x=[0 1 2 3 4 -5 -4 -3 -2 -1 0];
subplot(1,2,1)
stem(t,x)
title('Simple Signal')
xlabel('Time')
ylabel('Amplitude')
grid on;
y=fliplr(x);%reverses the signal x using the fliplr function, which flips the
signal left-to-right.
subplot(1,2,2)
stem(t,y)
title('reversed signal')
xlabel('Time')
ylabel('Amplitude')
grid on;
31