Digital Signal Processing
Introduction to DSP
1.1 What is Digital Signal Processing?
Signal processing is an engineering discipline that involves the modification, analysis, and
manipulation of signals to optimize their transmission, storage, or interpretation. A signal is
formally defined as any time-varying or space-varying physical quantity that conveys
information. Examples include the acoustic pressure waves of speech, the voltage fluctuations of
an electrocardiogram (ECG), or the pixel intensities of a satellite image.
In the physical world, almost all signals are analog—meaning they are continuous in both time
and amplitude. Digital Signal Processing (DSP) is the systematic study and algorithmic
manipulation of these signals after they have been converted into a discrete-time, discrete-
amplitude (quantized) format.
Mathematically , while ananalog signal is represented as a continuous function x ( t ) where
t ∈ R , a digital signal is represented as a sequence of numbers x [ n ] wheren ∈ Z represents the discrete time index . Th
prone analog hardware components ( such as resistors, capacitors , andinductors )
with mathematically precises of tware algorithms executed on programmable processors .
1.2 Analog vs. Digital Signals: A Comprehensive Comparison
To understand why modern technology has overwhelmingly shifted toward digital processing,
we must evaluate the fundamental characteristics of analog and digital paradigms across several
engineering vectors.
Digital Signals (x[n]): Defined only at discrete integer intervals n. The amplitude is constrained
to a finite set of predetermined levels (quantization). They are governed by difference equations
and discrete transforms.
Cross-correlation (Rxy[l])
Eg. Let's formally define the signals :
( x [ n ] ) : \{ 2 ,3 , 4 , 2, 5 , 4 }for n=\{ 0 , 1, 2 , 3 , 4 , 5 }( Length=6 ) ∧¿
( y [ n ] ) :\{ 3 , 4 ,2 }for n=\{ 0 ,1 , 2} ( Length=3 )
Range of Lags Determination
Cross-correlation (Rxy[l]) calculates match strength across various spatial displacements, known
as lags (l).
Minimum Lag ( l min ) : nx ,start −n y , end=−2
Maximum Lag ( l max ) :n x ,end −n y ,start =5−0=5
Our output correlation sequence will have a length of 6+3−1=8 samples ,running ¿ lag l=−2¿ l=5.
The Mathematical Formula Method
The cross-correlation formula is defined as:
∞
R xy [ l ] = ∑ x [ n ] y [ n−l ]
n=−∞
Let's compute the value for each lag individually by tracking how the samples align
Lagl=−2 : y [ n+2 ] shifts ¿ 2units . Only y [ 2 ] overlaps with x [ 0 ]
R xy [−2 ]=x [ 0 ] y [ 2 ] =2 ×2=4
Lag l=−1 : y [ n+ 1 ] shifts¿ 1 unit . Elements \{ y [ 1 ] , y [ 2 ] overlap with \{ x [ 0 ] , x [ 1 ]
R xy [−1 ]=x [ 0 ] y [ 1 ] + x [ 1 ] y [ 2 ] =( 2 ×4 ) + ( 3 ×2 ) =8+6=14
Lag l=0 : Perfect origin alignment . y [ n ] is unshifted
R xy [ 0 ] =x [ 0 ] y [ 0 ] + x [ 1 ] y [ 1 ] + x [ 2 ] y [ 2 ]= ( 2× 3 ) + ( 3 ×4 ) + ( 4 ×2 )=6+12+8=26
Lagl=1 : y [ n−1 ] shifts ¿ by 1 unit
R xy [ 1 ] =x [ 1 ] y [ 0 ] + x [ 2 ] y [ 1 ] + x [ 3 ] y [ 2 ] =( 3 ×3 )+ ( 4 × 4 )+ ( 2× 2 )=9+16+ 4=29
Lagl=2 : y [ n−2 ] shifts ¿ by 2units
R xy [ 2 ]=x [ 2 ] y [ 0 ] + x [ 3 ] y [ 1 ] + x [ 4 ] y [ 2 ] =( 4 ×3 )+ ( 2 × 4 )+ (5 × 2 )=12+8+10=30
Lagl=3 : y [ n−3 ] shifts ¿ by 3 units
R xy [ 3 ] =x [ 3 ] y [ 0 ] + x [ 4 ] y [ 1 ] + x [ 5 ] y [ 2 ]= (2 ×3 )+ ( 5× 4 ) + ( 4 × 2 )=6 +20+8=34
Lagl=4 : y [ n−4 ] shifts ¿ by 4 units
R xy [ 4 ]=x [ 4 ] y [ 0 ] + x [ 5 ] y [ 1 ] =( 5 ×3 )+ ( 4 × 4 )=15+16=31
Lagl=5 : y [ n−5 ] shifts ¿ by 5 units .Only y [ 0 ] overlaps with x [ 5 ]
R xy [ 5 ]=x [ 5 ] y [ 0 ] =4 ×3=12
Final Mathematical Output Vector :
R xy [ l ] =\{ 4 ,14 ,26 ,29 , 30 , 34 , 31 ,12 }
The Tabular Sliding Method
To construct this table, we place the stationary sequence x[n] across the top header row. We write out
the values of y[n] without flipping them on the rows below, shifting one step to the right for each
subsequent lag.
Lag Summation
x[0]=2 x[1]=3 x[2]=4 x[3]=2 x[4]=5 x[5]=4
(l) Result
-2 2 2x2=4
(2 x 4) + (3 x 2)
-1 4 2
= 14
(2 x 3) + (3 x 4)
0 3 4 2
+ (4 x 2) = 26
(3 x 3) + (4 x 4)
1 3 4 2
+ (2 x 2) = 29
(4 x 3) + (2 x 4)
2 3 4 2
+ (5 x 2) = 30
(2 x 3) + (5 x 4)
3 3 4 2 + (4 x 2) = 34
MAX PEAK
(5 x 3) + (4 x 4)
4 3 4
= 31
5 3 4 x 3 = 12
Our target sequence {3, 4, 2} finds its highest raw cross-product sum starting at index n = 3 of our
master sequence (where x[3], x[4], x[5] = {2, 5, 4}).
The raw cross-correlation peak occurs at Lag l = 3 with an amplitude of 34. At Lag l = 3, the template {3,
4, 2} is being multiplied by the last three samples of the signal, which are {2, 5, 4}. If you look closely at
the numbers, {2, 5, 4} is not an exact match for {3, 4, 2}.
The exact target sequence {3, 4, 2} is sitting perfectly inside your master signal starting at index n = 1
(Indices 1, 2, and 3 are x[1]=3, x[2]=4, x[3]=2). Yet, at Lag l = 1, the unnormalized score is only 29.
Unnormalized correlation measures total joint energy, not shape similarity. At Lag l = 3, the presence of
the large value 5 inflates the multiplication (5 times 4 = 20). The raw math gets blinded by the sheer
amplitude of that single sample, ignoring the fact that the overall pattern at Lag l = 1 is a literal 100%
identical match.
To fix this, we must transition from raw cross-correlation to Normalized Cross-Correlation (NCC), which
calculates a pure similarity score bounded strictly between -1.0 and +1.0.
Normalized Process
Let’s isolate the two main competing windows of your signal x[n] = {2, 3, 4, 2, 5, 4} using the template
y[n] = {3, 4, 2}.
First, we calculate the baseline energy of the template (Energyy):
Energy y =∑ ( y [ n ]) =32+ 4 2+ 22=9+16+ 4=29
2
The local normalization formula applied to each sliding window is:
NCC [ l ] =
∑ ( x window ⋅ y )
√Energy x _ window ⋅Energy y
Step-by-Step Calculation for Lag l = 1 (The True Pattern Window)
At Lagl=1 ,the sliding template aligns withthe master signal segment ¿ index
n=1¿ n=3 , which is \{ 3 , 4 ,2 \} .
Calculate the raw dotproduct ( Numerator ) :
∑ ( x window ⋅ y )= (3 × 3 ) +( 4 × 4 ) +( 2 ×2 )=9+16+ 4=29
Calculate the local window energy of the master signal :
2 2 2
Energy x _ window =3 +4 +2 =9+16 +4=29
Calculate the final similarity score:
29 29
NCC [ 1 ] = = =1.000
√29 ×29 29
for Lag l=2 (Testing Window \{ 4 , 2 ,5 \} )
RawDotProduct ( Numerator ) :
∑ ( x window ⋅ y )= ( 4 ×3 )+ ( 2× 4 ) +( 5× 2 )=12+8+ 10=30
Local Master Window Energy :
2 2 2
Energy x _ window =4 +2 + 5 =16+ 4+25=45
Similarity Score :
30 30 30
NCC [ 2 ] = = = ≈ 0.830
√ 45× 29 √1305 36.125
for Lag l = 3 (The High-Energy Window)
At Lag l = 3, the template aligns with the master signal segment from index n=3 to n=5, which is
{2, 5, 4}.
Calculate the raw dotproduct ( Numerator ) :
∑ ( x window ⋅ y )= (2 ×3 )+ ( 5× 4 ) +( 4 × 2 )=6 +20+8=34
Calculate the local window energy of the master signal :
2 2 2
Energy x _ window =2 +5 +4 =4 +25+16=45
Calculate the final similarity score :
34 34 34
NCC [ 3 ] = = = =0.941
√ 45 ×29 √1305 36.125
By removing the amplitude bias, the similarity score at Lag l = 1 reaches an absolute perfect
1.000, proving mathematically that it is the exact match location.
This gives you a comprehensive view of how the values evolve across the entire length of the signal.
Final
Raw Local
Lag Sliding Time Frame Normalized
Dot Window Interpretation
(l) Window Similarity
Product Energy
Score
Good shape
n = {0, 1, 2} trend match,
l=0 26 29 0.897
{2, 3, 4} slightly
different scale.
Absolute
n = {1, 2, 3}
l=1 29 29 1.000 Perfect Match
{3, 4, 2}
Found
Poor shape
n = {2, 3, 4} match (drops
l=2 30 45 0.830
{4, 2, 5} then rises
sharply).
High raw
n = {3, 4, 5} energy false
l=3 34 45 0.941
{2, 5, 4} peak, but strong
scaling.
Row by Row Derivations
Row 1: Lag l=0 ( Master Window=\{ 2 , 3 , 4 \} )
This window grabs the first three samples of themaster signal :
x [ 0 ] =2 , x [ 1 ] =3 ,∧x [ 2 ]=4
˙
How the Raw Product was calculated :
Multiply the window elements by thetemplate elements \{3 , 4 , 2 \} side by side:
Raw Dot Product= ( 2× 3 ) + ( 3 ×4 ) + ( 4 ×2 )
Raw Dot Product=6+12+8=26
How the Local Window Energy was calculated :
Square each value inside this specific window∧∑ them :
2 2 2
Local Window Energy =2 +3 +4
Local Window Energy =4 +9+16=29
Row 2: Lag l=1 ( MasterWindow=\{3 , 4 , 2 \} )
The window slides ¿ by one index , capturing : x [ 1 ]=3 , x [ 2 ]=4 ,∧x [ 3 ]=2
˙
How the Raw Product was calculated :
Multiply this new window by the template elements \{ 3 , 4 ,2 \} side by side :
Raw Dot Product= ( 3× 3 ) + ( 4 ×4 ) + ( 2 ×2 )
Raw Dot Product=9+16+ 4=29
How the Local Window Energy was calculated :
Square each value inside this sliding window frame :
2 2 2
Local Window Energy =3 +4 +2
Local Window Energy =9+16+ 4=29
Row 3: Lag l=2 ( MasterWindow=\{ 4 ,2 , 5 \} )
The window slides ¿ by another index , capturing : x [ 2 ]=4 , x [ 3 ] =2 ,∧x [ 4 ] =5
˙
How the Raw Product was calculated :
Multiply this window by the template elements \{ 3 , 4 , 2 \} side by side :
Raw Dot Product= ( 4 × 3 ) + ( 2× 4 ) + ( 5 ×2 )
Raw Dot Product=12+ 8+10=30
How the Local Window Energy was calculated :
Square each value inside this window frame :
2 2 2
Local Window Energy =4 +2 +5
Local Window Energy =16+ 4+25=45
Row 4 : Lag l=3 ( MasterWindow=\{ 2 ,5 , 4 \} )
The window reaches its final positionat the end of the signal , capturing :
x [ 3 ] =2 , x [ 4 ]=5 ,∧x [ 5 ]=4
˙
How the Raw Product was calculated :
Multiply the final window elements by the template elements \{3 , 4 , 2 \} side by side:
Raw Dot Product= ( 2× 3 ) + ( 5 ×4 ) + ( 4 ×2 )
Raw Dot Product=6+20+8=34
How the Local Window Energy was calculated :
Square each value inside this final window frame :
2 2 2
Local Window Energy =2 +5 +4
Local Window Energy =4 +25+16=45
How They Combine Intothe Similarity Score
Once these two distinct numbers are found forarow , they are plugged directly into the final
normalizationstep . Forexample , lookingatthelastrow ( Lagl=3 )
Raw Dot Product
NCC [ 3 ] =
√ Local Window Energy ×Template Energy
34 34 34
NCC [ 3 ] = = = ≈ 0.941
√ 45 ×29 √1305 36.125
The Equation for Valid Window Steps
You can always calculate exactly how many valid sliding positions you have using this simple
length formula:
{Number of Valid Windows} = {Length of Master Signal} - {Length of Template} + 1
Plugging in your exact signal dimensions:
{Number of Valid Windows} = 6 - 3 + 1 = 4 windows
Because our indexing starts at 0, our 4 valid sliding window positions are locked to Lags l = 0, 1,
2, and 3.
show the exact timeframe where the template matches the signal, we can alter the plotting strategy.
Instead of plotting a static lag profile, we can display the Sliding Target Window moving in real-time
across the master time axis.
It calculates the normalized match score, loops through the valid timeframes, and dynamically highlights
the exact window of matching samples on a single, shared time axis.
CONVOLUTION
While cross-correlation slides a template unchanged to find similarity, convolution flips the template
horizontally before sliding it. In engineering, convolution is used to find out how a system's
impulse response (h[n]) modifies an input signal (x[n]) over time.
The mathematical equation for discrete convolution is:
∞
y [ n]= ∑ x [ k ] h [ n−k ]
k=−∞
Notice the negative sign inside
h [ n−k ] .This tellsus that before we do any sliding∨multiplying ,
we must physically reversethe impulse response array
Original h [ n ]=3 , 4 , 2
Flipped h [ −k ] =2 , 4 , 3
The Tabular Sliding Method (For Convolution)
To easily calculate all 8 output points without making algebraic mistakes, we place x[n] across
the top. Then, we write our flipped array {2, 4, 3} underneath, sliding it one step to the right for
every increasing time index n.
Summatio
Tim x[0]= x[1]= x[2]= x[3]= x[4]= x[5]= n& Outpu
e (n) 2 3 4 2 5 4 Calculatio t y[n]
ns
0 3 2x3 6
(2 x 4) + (3
1 4 3 17
x 3)
(2 x 2) + (3
2 2 4 3 x 4) + (4 x 28
3)
(3 x 2) + (4
3 2 4 3 x 4) + (2 x 28
3)
4 2 4 3 (4 x 2) + (2 31
Summatio
Tim x[0]= x[1]= x[2]= x[3]= x[4]= x[5]= n& Outpu
e (n) 2 3 4 2 5 4 Calculatio t y[n]
ns
x 4) + (5 x
3)
(2 x 2) + (5
5 2 4 3 x 4) + (4 x 36
3)
(5 x 2) + (4
6 2 4 26
x 4)
7 2 4x2 8
Our final calculated mathematical convolution array is:
y[n] = {6, 17, 28, 28, 31, 36, 26, 8}
why normalization is never applied to convolution:
Cross-Correlation is an analytical scanning tool. We normalize it because we want to
force the output to look like a percentage/scale (between -1 and 1) so a human or
computer can judge similarity regardless of signal volume.
Convolution is a physical filtering process. If you feed a loud sound signal (x[n]) into a
physical acoustic amplifier system (h[n]), you want the output values to explode upward
to reflect the real-world increase in physical energy and volume. Normalizing
convolution would destroy the physical reality of the system's gain and amplification
characteristics.
Mathematical solution for the convolution of your sequences using the formal summation
formula.
Our input sequences are:
x [ n ] =\{2 , 3 , 4 , 2 , 5}for n=\{ 0 ,1 , 2 , 3 , 4 , 5 }
h [ n ] =\{ 3 , 4 }for n=\{ 0 ,1 , 2 }
Step 1: Boundary & Range Generation
Before calculating any values, we must mathematically define the exact boundaries of the output
signal y[n] using the direct mapping index rules:
n( start )=n( x , start )+n (h , start )=0+0=0
n( end )=n( x ,end ) +n (h ,end )=5+ 2=7
The output sequence spans the time window 0 ≤ n ≤7 giving us a total of 8 individual discrete
points to evaluate.
Step 2: Setting up the Formula
The formal mathematical definition of discrete linear convolution is:
∞
y [ n]= ∑ x [ k ] h [ n−k ]
k=−∞
Because our input signal x [ k ] is only non zero between k =0∧k=5
we can compress theinfinite limitsof the summation strictly ¿ the active window of x
5
y [ n ] =∑ x [ k ] h [ n−k ]
k=0
Expanding this summation formula gives us our master equation for every single time step:
y [ n ] =x [ 0 ] h [ n ] + x [ 1 ] h [ n−1 ] + x [ 2 ] h [ n−2 ] + x [ 3 ] h [ n−3 ] + x [ 4 ] h [ n−4 ] + x [ 5 ] h [ n−5 ]
Any term where the index inside h[.] drops below 0 or goes above 2 automatically evaluates to 0
(since h[n] is undefined outside those bounds).
working out for every value of n
evaluating y [0]
Substitute n = 0 into our master equation:
y [ 0 ] =x [ 0 ] h [ 0 ] + x [ 1 ] h [−1 ] + x [ 2 ] h [ −2 ] + x [ 3 ] h [−3 ] + x [ 4 ] h [ −4 ] + x [ 5 ] h [−5 ]
Since h[-1] through h[-5] are outside the boundaries of h, they become 0:
y [ 0 ] =( 2 ×3 ) +0+ 0+0+0+ 0=6
Evaluating y[1]
Substitute n = 1 into our master equation:
y [ 1 ] =x [ 0 ] h [ 1 ] + x [ 1 ] h [ 0 ] + x [ 2 ] h [−1 ] + x [ 3 ] h [ −2 ] + x [ 4 ] h [ −3 ] + x [ 5 ] h [ −4 ]
y [ 1 ] =( 2× 4 ) + ( 3 ×3 ) +0+ 0+0+0
y [ 1 ] =8+9=17
Evaluating y[2]
Substitute n = 2 into our master equation (all three terms of h[n] are now fully active):
y [ 2 ] =x [ 0 ] h [ 2 ] + x [ 1 ] h [ 1 ] + x [ 2 ] h [ 0 ] + x [ 3 ] h [ −1 ] + x [ 4 ] h [ −2 ] + x [ 5 ] h [−3 ]
y [ 2 ] =( 2× 2 ) + ( 3 ×4 ) + ( 4 ×3 ) +0+ 0+0
y [ 2 ] =4 +12+12=28
Evaluating y[3]
Substitute n = 3 into our master equation (the window slides forward; x[0] drops out because
h[3]=0):
y [ 3 ] =x [ 0 ] h [ 3 ] + x [ 1 ] h [ 2 ] + x [ 2 ] h [ 1 ] + x [ 3 ] h [ 0 ] + x [ 4 ] h [−1 ] + x [ 5 ] h [ −2 ]
y [ 3 ] =0+ ( 3 ×2 )+ ( 4 × 4 )+ ( 2× 3 ) +0+0
y [ 3 ] =6+16+ 6=28
Evaluating y[4]
Substitute n = 4 into our master equation:
y [ 4 ] =x [ 0 ] h [ 4 ] + x [ 1 ] h [ 3 ] + x [ 2 ] h [ 2 ] + x [ 3 ] h [ 1 ] + x [ 4 ] h [ 0 ] + x [ 5 ] h [−1 ]
y [ 4 ] =0+0+ ( 4 ×2 )+ ( 2× 4 )+ ( 5× 3 ) +0
y [ 4 ] =8+8+15=31
Evaluating y[5]
Substitute n = 5 into our master equation:
y [ 5 ] =x [ 0 ] h [ 5 ] + x [ 1 ] h [ 4 ] + x [ 2 ] h [ 3 ] + x [ 3 ] h [ 2 ] + x [ 4 ] h [ 1 ] + x [ 5 ] h [ 0 ]
y [ 5 ] =0+0+ 0+ ( 2 ×2 ) + ( 5 × 4 ) + ( 4 ×3 )
y [ 5 ] =4 +20+12=36
Evaluating y[6]
Substitute n = 6 into our master equation (the system response is now sliding off the right edge):
y [ 6 ] =x [ 0 ] h [ 6 ] + x [ 1 ] h [ 5 ] + x [ 2 ] h [ 4 ] + x [ 3 ] h [ 3 ] + x [ 4 ] h [ 2 ] + x [ 5 ] h [ 1 ]
y [ 6 ] =0+ 0+0+0+ (5 × 2 ) + ( 4 × 4 )
y [ 6 ] =10+16=26
Evaluating y[7]
Substitute n = 7 into our master equation (the very last point of overlapping contact):
y [ 7 ] =x [ 0 ] h [ 7 ] + x [ 1 ] h [ 6 ] + x [ 2 ] h [ 5 ] + x [ 3 ] h [ 4 ] + x [ 4 ] h [ 3 ] + x [ 5 ] h [ 2 ]
y [ 7 ] =0+ 0+0+0+ 0+ ( 4 × 2 )=8