FormalPara Learning Objectives

After completing this chapter, the reader is expected to

  • Generate standard discrete-time sequences like unit sample, unit step, unit ramp sequences, etc.

  • Perform operations like folding, shifting and scaling on the discrete-time sequence.

  • Perform linear convolution and circular convolution between discrete-time sequences.

  • Perform autocorrelation and cross-correlation between discrete-time sequences.

FormalPara Road Map of the Chapter

This chapter aims to generate different discrete-time signals or sequences and perform various mathematical operations on the discrete-time signal. The flow of the concept in this chapter is illustrated in the form of a block diagram, which is given below:

A flow diagram of discrete-time sequence is classified into generation of D T signals, including standard D T signals and arbitrary D T signals, and mathematical operation on D T signals, including folding, shifting, and scaling with linear and circular convolutions and auto and cross correlations.
FormalPara PreLab Questions
  1. 1.

    What are the steps involved in converting the continuous-time signal into a discrete-time signal?

  2. 2.

    Mention different forms of representations of discrete-time signals?

  3. 3.

    Mention a few standard discrete-time sequences.

  4. 4.

    Mention the significant features of the unit sample sequence (δ[n]).

  5. 5.

    State the condition for the discrete-time signal to be periodic.

  6. 6.

    Distinguish between energy and power signal.

  7. 7.

    What are the various mathematical operations that can be performed on discrete-time signals?

  8. 8.

    When a discrete-time signal is said to be (a) an even signal (b) an odd signal? Give an example for each class of signal. Also, give an example of a signal which is neither even nor odd.

  9. 9.

    Give an example of an energy and power signal. Also, give an example of a discrete-time signal which is neither energy nor power signal.

  10. 10.

    Explain in your own word regarding the significance of convolution operation in signal processing.

  11. 11.

    What is the relationship between convolution and correlation? Mention two applications of correlation.

3.1 Generation of Discrete-Time Signals

This section deals with the generation of different types of discrete-time signals like unit sample signal, unit step signal, unit ramp signal, real and complex exponential signals. The following section discusses about different mathematical operations that could be performed on discrete-time signals.

Experiment 3.1 Generation of the Unit Sample Sequence

The mathematical expression of the unit sample sequence (δ[n]) is given by

$$ \delta \left[n\right]=\left\{\begin{array}{cc}1,& \mathrm{if}\;n=0\\ {}0,& \mathrm{Otherwise}\end{array}\right. $$
(3.1)

This experiment discusses the generation of unit sample sequence using ‘if’ and ‘else’ conditions in python platform. The python code to generate unit sample sequence using ‘if’ and ‘else’ conditions is shown in Fig. 3.1, and the corresponding output is shown in Fig. 3.2. The built-in functions used in the program are given in Table 3.1.

Fig. 3.1
A Python code to generate a unit sample sequence has two steps, including generating the sequence, defining the X-axis, and plotting the sequence.

Python code to generate unit sample sequence

Fig. 3.2
An output graph compares amplitude versus n. The dots are plotted at an amplitude of 0.0, from negative 10 to negative 1 and 1 to 10. The horizontal line is drawn at 0.0. The dot labeled delta of n lies at (0, 1.0). The vertical line connects the dot labeled delta of n and the horizontal line.

Unit sample sequence

Table 3.1 Built-in functions used in unit sample signal generation

Inference

It is possible to observe that unit sample sequence takes a value of ‘1’ at ‘n’ equal to zero and zero at other instances of ‘n’.

Experiment 3.2 Generation of Unit Sample Sequence Using the Logical Operation

This experiment deals with the logical operation used to generate unit sample sequence, and the python code for this experiment is shown in Fig. 3.3, and the corresponding output is shown in Fig. 3.4.

Fig. 3.3
A Python code to generate a unit sample sequence has two steps, including generating the sequence, defining the X-axis, unit sample sequence, and plotting the sequence.

Logical operation to generate unit sample sequence

Fig. 3.4
An output graph compares amplitude versus n. The dots are plotted at an amplitude of 0.0, from negative 10 to negative 1 and 1 to 10. The horizontal line is drawn at 0.0. The dot labeled delta of n lies at (0, 1.0). The vertical line connects the dot labeled delta of n and the horizontal line.

Output of python code shown in Fig. 3.3

Inference

The statement (x = (n == 0)) given in Fig. 3.3 implies that the variable ‘x’ takes a value of ‘1’ if n = 0, and it takes a value of ‘0’ for all the other values of ‘n’.

Experiment 3.3 Generation of Unit Sample Sequence Using the Built-In Function from the Scipy Library

The built-in function in scipy library ‘unit_impulse’ can be used to generate unit sample sequence. The python code, which generates unit sample sequence using the built-in function from the scipy library, is shown in Fig. 3.5, and the corresponding output is shown in Fig. 3.6.

Fig. 3.5
A Python code to generate a unit sample sequence includes import matplotlib dot pyplot as p l t, import numpy as n p, from scipy import signal, n = n p dot arange left parenthesis negative 5, 6 right parenthesis, and x = signal dot unit underscore impulse of len of n, mid.

Unit sample sequence generation using scipy library

Fig. 3.6
An output graph compares amplitude versus n. The dots are plotted at an amplitude of 0.0 from negative 5 to negative 1 and 1 to 5. The horizontal line is drawn at 0.0. The dot labeled delta of n lies at (0, 1.0). The vertical line connects the dot labeled delta of n and the horizontal line.

Result of python code shown in Fig. 3.5

Inference

From Figs. 3.5 and 3.6, it is possible to confirm that unit sample sequence can be generated using the scipy library with the built-in command of ‘signal.unit_impulse’.

Experiment 3.4 Generation of Unit Step Sequence

The mathematical expression of the unit step sequence is written as

$$ u\left[n\right]=\left\{\begin{array}{cc}1,& \mathrm{if}\;n\ge 0\\ {}0,& \mathrm{Otherwise}\end{array}\right. $$
(3.2)

In this experiment, the unit step sequence is generated using two methods. In the first method, ‘if’ and ‘else’ conditions are used to generate unit step sequence. The second method uses logical operation to generate unit step signal. The python code, which generates unit step signal using two different methods, is shown in Fig. 3.7, and the corresponding output is shown in Fig. 3.8.

Fig. 3.7
A Python code to generate a unit-step signal includes import numpy as n p, import matplotlib dot pyplot as p l t, step 1 of generating the sequence, defining the X-axis, method 1 of if and else, method 2 of logical operation, plotting the result, and p l t dot tight underscore layout left and right parentheses.

Python code to generate unit step signal

Fig. 3.8
Two output graphs of amplitude versus n plot u of n. The horizontal line is drawn at an amplitude of 0.00. The dots lie on the horizontal line from negative 10 to negative 1 and at an amplitude of 1.00 from 0 to 10.

Result of python code shown in Fig. 3.7

Inference

From Fig. 3.8, it is possible to interpret that both methods yield the same result, which is a unit step signal. The unit step signal exhibits a sudden change in state from logic 0 to logic 1 instantaneously.

Experiment 3.5 Generation of the Unit Ramp Signal

The mathematical expression of the unit ramp sequence (r[n]) is written as

$$ r\left[n\right]=\left\{\begin{array}{cc}n,& \mathrm{if}\;n\ge 0\\ {}0,& \mathrm{Otherwise}\end{array}\right. $$
(3.3)

The python code, which generates unit ramp signal using two methods, is discussed in this experiment. In method 1, ‘if’ and ‘else’ conditions generate unit ramp signals, whereas in method 2, logical operation is used to generate unit ramp signals. The python code, which generates unit ramp signal using the two methods, is shown in Fig. 3.9, and the corresponding output is shown in Fig. 3.10.

Fig. 3.9
A Python code to generate unit ramp signal includes import numpy as n p, step 1 of generating the sequence, define X-axis, two methods to generate unit ramp signal, x 1 = i if greater than or equal to 0 else 0 for i in n unit ramp sequence, logical operation, and plotting the result.

Python code to generate unit ramp signal

Fig. 3.10
Two output graphs of amplitude versus n plot r of n. The horizontal line is drawn at an amplitude of 0.00. The dots lie on the horizontal line from negative 10 to 0. The dots trend in an increasing pattern from (1, 1) to (10, 10.0). The vertical lines connect the horizontal line and the dots from (1, 1) to (10, 10.0).

Result of python code shown in Fig. 3.9

Inference

From Fig. 3.10, it is possible to observe that the ramp signal generated using ‘if’ and ‘else’ condition and ‘logical operation’ are alike. Unlike step signal, the ramp signal gradually increases from low to high value.

Task

  1. 1.

    Write a python code to generate unit ramp signal from unit step signal.

Experiment 3.6

From unit sample signal generates unit step signal, and from unit step signal generates unit ramp signal.

The relationship between unit sample (δ[n]) and unit step (u[n]) sequence is given by

$$ u\left[n\right]=\sum \limits_{k=-\infty}^n\delta \left[k\right] $$
(3.4)

and

$$ \delta \left[n\right]=u\left[n\right]-u\left[n-1\right] $$
(3.5)

The relationship between the unit ramp and unit step sequence is given by

$$ r\left[n\right]= nu\left[n\right] $$
(3.6)

The flow chart, which depicts the objective of this experiment, is shown in Fig. 3.11.

Fig. 3.11
A flowchart depicts the objective of experiment 3.6. It includes the generation of unit sample sequence delta of n, derive unit sequence u of n from unit sample sequence delta of n, and derive unit ramp sequence r of n from unit step sequence u of n.

Flow chart depicting the problem statement of Experiment 3.6

From the flow chart, the unit sample sequence is generated first. From unit sample sequence, unit step sequence is obtained by repeated addition. From unit step sequence, unit ramp sequence is derived. The python code, which performs the above-mentioned task, is shown in Fig. 3.12, and the corresponding output is shown in Fig. 3.13.

Fig. 3.12
A Python code to generate test sequences from a unit sample sequence includes steps 1 of generation of the unit sample sequence, step 2 of unit step sequence from unit sample sequence, step 3 of unit ramp sequence from unit step sequence z = n times y, and step 4 of plotting the result.

Python code to generate test signals from unit sample sequence

Fig. 3.13
Three output graphs of amplitude versus n plot delta of n, u of n, and r of n. The horizontal line is drawn at an amplitude of 0. The dots lie on the horizontal line from negative 10 to negative 1. In r of n, the dots trend in an increasing pattern from (1, 1) to (10, 10.0).

Result of python code shown in Fig. 3.12

Inferences

From the python code shown in Fig. 3.12, it is possible to infer that unit step sequence is obtained by repeatedly adding the unit sample sequence. The unit ramp sequence is obtained by weighting the unit step signal by a factor of ‘n’. From this example, it is possible to infer that any arbitrary signal x[n] can be obtained from the unit sample sequence by scaling and shifting operations.

Task

  1. 1.

    Write a python code to generate a unit sample signal from the unit step signal.

Experiment 3.7 Generation of Real Exponential Sequence

The expression for a real exponential signal is given by

$$ x\left[n\right]={\alpha}^n $$
(3.7)

where α must be a real value. The aim of this experiment is to generate real exponential sequence for four different values of ‘α’, namely, α = 0.5, α =  − 0.5, α = 1.0 and α =  − 1.0. The python code, which performs this task, is shown in Fig. 3.14, and the corresponding output is shown in Fig. 3.15.

Fig. 3.14
A Python code to generate real exponential sequences includes import numpy as n p, import matplotlib dot pyplot as p l t, n = n p dot arange left parenthesis negative 5, 6, 1 right parenthesis define the X-axis, alpha = left square bracket 0.5, negative 0.5, 1.0, negative 1.0 right square bracket, and real exponential sequence.

Python code to generate real exponential signal

Fig. 3.15
Four output graphs of amplitude versus n for alpha = 0.5, negative 0.5, 1.0, and negative 1.0. The horizontal line is drawn at an amplitude of 0. In alpha = 0.5 and negative 0.5, the dots lie on the horizontal line from 0 to 5. In alpha = 1.0, the dots lie at an amplitude of 1.0 from negative 5 to 5.

Result of python code shown in Fig. 3.14

Inferences

The following inference can be made from this experiment:

  1. 1.

    If the value of α is 0 < α < 1, then the signal x[n] decreases in magnitude. This is evident by observing the first subplot for α = 0.5.

  2. 2.

    If the value of α is −1 < α < 0, then the signal x[n] alternates in sign but decreases in magnitude. This is evident by viewing the second subplot in Fig. 3.15 for α =  − 0.5.

  3. 3.

    For α = 1.0, there is no oscillation and the amplitude is always one.

  4. 4.

    For α =  − 1.0, the signal x[n] toggles. This is the highest frequency in digital sequence.

Task

  1. 1.

    Obtain the real exponential sequence for α = 2 and comment on the nature of the signal. Here the term ‘nature’ refers to whether the signal is a bounded or not.

Experiment 3.8 Generation of Complex Exponential Signal

The general form of complex exponential signal is given by

$$ x\left[n\right]={\mathrm{e}}^{j\omega n} $$
(3.8)

where ‘ω’ represents the angular frequency in radians. The python code to generate complex exponential sequences for four different values of ‘ω’ such as \( \omega =\left[0,\frac{\pi }{2},\pi, \frac{3\pi }{2}\right] \) is given in Fig. 3.16, and the corresponding output is shown in Fig. 3.17.

Fig. 3.16
A Python code to generate complex exponential sequences includes import numpy as n p, import matplotlib dot pyplot as p l t, n = n p dot arange left parenthesis negative 5, 6, 1 right parenthesis define the X-axis, omega degree = left square bracket 0, 90, 180, 270 right square bracket, and complex exponential sequences.

Python code to generate complex exponential sequences

Fig. 3.17
Four output graphs of amplitude versus n for omega = 0, 90, 180, and 270 degrees. The horizontal line is drawn at an amplitude of 0. In omega = 0 degrees, the dots lie at an amplitude of 1.0 from negative 5 to 5. In omega = 90 and 270 degrees, the dots lie at an amplitude of 0 in negative 5, negative 2, negative 1, 1, 3, and 5.

Complex exponential sequences for different values of ‘ω

Inferences

The following inference can be drawn from this experiment:

  1. 1.

    When ω = 0, the frequency is zero, the amplitude of the signal is constant and there is no variation in the signal. This is termed as DC signal. For a DC signal, the frequency is zero.

  2. 2.

    With increase in the value of ‘ω’, the oscillation exhibited by the signal increases. At ω = π, the signal takes alternate values of +1 and −1. It is the highest frequency in the digital signal.

Task

  1. 1.

    Write a python code to prove the fact that digital frequency ‘ω’ is unique in the range 0 to 2π or from –π to π.

Experiment 3.9 Generation of Signum Function

Signum function is defined as a mathematical function that gives the sign of a real number. The signum function f : R → R is defined as

$$ \operatorname{sgn}\left[n\right]=\left\{\begin{array}{c}1,\mathrm{if}\;n>0\\ {}0,\mathrm{if}\;n=0\\ {}-1,\mathrm{if}\;n<0\end{array}\right. $$
(3.9)

The python code to generate signum function is shown in Fig. 3.18, and the corresponding output is shown in Fig. 3.19.

Fig. 3.18
A Python code to generate a signum function includes import numpy as n p, import matplotlib dot pyplot as p l t, n = n p dot arange left parenthesis negative 5, 6 right parenthesis, x = n p dot sign left parenthesis n right parenthesis, and p l t dot stem of left parenthesis n, x right parenthesis.

Python code to generate signum function

Fig. 3.19
An output graph of the signum function compares amplitude versus n. The dots are plotted at (negative 5, negative 1), (negative 4, negative 1), (negative 3, negative 1), (negative 2, negative 1), (negative 1, negative 1), (0, 0), (1, 1), (2, 1), (3, 1), (4, 1), and (5, 1).

Result of python code shown in Fig. 3.18

Inference

From Fig. 3.19, it is possible to observe that the signum function takes only three values, which are −1, 0 and 1; whenever n < 0, the signum function takes the value of −1. At n = 0, the signum function takes a value of ‘0’. For the positive values of ‘n’, the signum function takes the value of +1.

Task

  1. 1.

    Is it possible to obtain signum function from unit step function? If yes, write a python code to generate discrete signum signal from unit step signal.

3.2 Mathematical Operation on Discrete-Time Signals

This section discusses various mathematical operations that are performed on discrete-time signals. The basic mathematical operations that could be performed on the discrete-time signals are given in Fig. 3.20.

Fig. 3.20
A mathematical operation on the D T signal is classified into amplitude modification and time modification. Amplitude modification includes amplitude scaling, amplitude shifting, the product of two signals, and the addition of two signals. Time modification includes time scaling, time shifting, and time reversal.

Different mathematical operations on DT signal

3.2.1 Amplitude Modification on DT Signal

The different signal operations that come under amplitude modification are discussed in this section.

  1. (a)

    Amplitude scaling

    If x[n] is the input signal, the scaling of the signal x[n] by a factor of ‘A’ is represented as

    $$ y\left[n\right]= Ax\left[n\right] $$
    (3.10)

    If A > 1, the operation is called as amplification, A < 1 represents attenuation. If A = 1, the output follows the input, it is called as input follower or buffer.

Experiment 3.10 Amplitude Scaling

Generate unit sample signal and perform the amplitude scaling for three different values of A, namely: A = 2, A = 0.5 and A = 1. Plot the input and output signal and comment on the observed output.

The python code, which performs the above-mentioned task, is shown in Fig. 3.21, and the corresponding output is shown in Fig. 3.22.

Fig. 3.21
A Python code to perform amplitude scaling includes step 1 of generating the input signal, n = n p dot arange left parenthesis negative 10, 11, 1 right parenthesis, obtaining the output signals for different values of A, A = 2, 0.5, 1 and three different values of factor A, and step 2 of plotting the result.

Python code to perform amplitude scaling

Fig. 3.22
Four output graphs of amplitude versus n plot x of n, y 1 of n, y 2 of n, and y 3 of n. The horizontal line is drawn at an amplitude of 0. The dots lie on the horizontal line from negative 5 to negative 1 and from 1 to 10. In y 1 of n, the peak dot lies at (0, 2).

Result of python code shown in Fig. 3.21

Inference

The following inferences can be made from this experiment:

  1. 1.

    From Fig. 3.22, it is possible to observe that y1[n] is the amplified version of x[n], and y2[n] is the attenuated version of x[n]. If the gain is unity, the output follows the input, which is evident from the output y3[n].

  2. 2.

    This example illustrates the scaling of the amplitude axis for different values of the factor ‘A’.

Task

  1. 1.

    Write a python code to illustrate the fact that amplitude scaling changes the energy of the signal.

  1. (b)

    Amplitude Shifting

    If x[n] is the input signal, the amplitude shifting of the signal x[n] by a factor of ‘C’ is represented as

    $$ y\left[n\right]=x\left[n\right]\pm C $$
    (3.11)

Experiment 3.11 Amplitude Shifting (DC Offset)

Let x[n] represent the discrete-time sinusoidal signal, and perform the DC offset of this signal x[n] to obtain the signals y1[n] = x[n] + C and y2[n] = x[n] − C. The value of ‘C’ for this experiment is to be chosen as 5. Write a python code to perform this task and comment on the observed output.

The python code, which performs the above-mentioned task, is shown in Fig. 3.23, and the corresponding output is shown in Fig. 3.24.

Fig. 3.23
A Python code to perform D C offset includes D C offset, step 1 of generation of the input sinusoidal sequence, step 2 of performing D C offset, offset = left bracket 5, negative 5 right square bracket, y 1 = x + offset of 0, y 2 = x + offset of 1, and step 3 of plotting the input and output signals.

Python code which performs DC offset

Fig. 3.24
Three output graphs of amplitude versus n plot x of n, y 1 of n, and y 2 of n. The horizontal line is drawn at an amplitude of 0. The sine waveform is plotted on x for n. In x of n, the waveform ranges between negative 1 and 1. In y 1 of n, the waveform lies between 2.5 and 5.

Result of python code shown in Fig. 3.23

Inference

By observing Fig. 3.24, it is possible to infer that the reference for signal y1[n] is +5 V, whereas the reference for signal y2[n] is −5 V. This is termed as DC offset.

Task

  1. 1.

    Does amplitude shifting affect the energy of the signal? Write a python code to answer this question.

  1. (c)

    Product of Two Signals

    The product of two signals x1[n] and x2[n] is represented by

    $$ y\left[n\right]={x}_1\left[n\right]\times {x}_2\left[n\right] $$
    (3.12)

    The amplitude of the resultant signal y[n] gets modified. For example, consider

    $$ {x}_1\left[n\right]=\sin \left(2\pi {f}_1n\right) $$
    (3.13)
    $$ {x}_2\left[n\right]=\cos \left(2\pi {f}_2n\right) $$
    (3.14)

    Substituting Eqs. (3.13) and (3.14) in Eq. (3.12), we get

    $$ y\left[n\right]=\sin \left(2\pi {f}_1n\right)\times \cos \left(2\pi {f}_2n\right) $$
    (3.15)

    Using the formula

    $$ \sin A\cos B=\frac{1}{2}\left\{\sin \left(A+B\right)+\sin \left(A-B\right)\right\} $$
    (3.16)

    Equation (3.15) can be written as

    $$ y\left[n\right]=\frac{1}{2}\left\{\sin 2\pi \left({f}_1+{f}_2\right)n+\sin 2\pi \left({f}_1-{f}_2\right)n\Big)\right\} $$
    (3.17)

    The amplitude of the output signal is different from the input signal x[n].

Experiment 3.12 Product of Two Signals

Obtain the product of the two signals given by x1[n] =  sin (2πf1n) and x2[n] =  sin (2πf2n). In this example, consider f1 = f2 = 5 Hz. Using the relation (3.17), the expression for the output signal is given by \( y\left[n\right]=\frac{1}{2}\left\{\sin 2\pi \left({f}_1+{f}_2\right)n+\sin 2\pi \left({f}_1-{f}_2\right)n\Big)\right\} \). In this case, f1 = f2 = 5 Hz; hence, the expression for the output signal is given by \( y\left[n\right]=\frac{1}{2}\left\{\sin 2\pi (10)n\Big)\right\} \). The frequency of the resultant signal should be 10 Hz, whereas its amplitude is reduced by half. The python code, which performs this task, is shown in Fig. 3.25, and the corresponding output is shown in Fig. 3.26.

Fig. 3.25
A Python code to obtain the product of the two signals includes import numpy as n p, import matplotlib dot pyplot as p l t, step of 1 generation of input signals, t = n p dot arange left parenthesis 0, 100, 1 right parenthesis, F s =100, step 2 of the product of the two signals, and step 3 of plotting the result.

Python code to obtain the product of the two signals

Fig. 3.26
Three output graphs of amplitude versus n plot x 1 of n, x 2 of n, and y of n. The horizontal line is drawn at an amplitude of 0. The sine waveform is plotted on x 1 of n. The cosine waveform is plotted on x 2 of n. The sinusoidal waveform is plotted on y of n. All the waveforms range between negative 1 and 1.

Result of python code shown in Fig. 3.25

Inference

The following inferences can be drawn from this experiment:

  1. 1.

    From Fig. 3.25, two signals of the same frequency are generated and multiplied.

  2. 2.

    From Fig. 3.26, it is possible to observe that x1[n] is a sine wave and x2[n] is a cosine wave. The resultant signal y[n] is a sinusoidal signal with a frequency of 10 Hz, whereas the amplitude of the output waveform is reduced by a factor of half.

  1. (d)

    Signal Addition

    The signal addition results in a change in the amplitude of the signal. Two signals x1[n] and x2[n] are added together to obtain the resultant output signal y[n], which is given by

    $$ y\left[n\right]={x}_1\left[n\right]+{x}_2\left[n\right] $$
    (3.18)

Experiment 3.13 Signal Addition

In this example, let x1[n] = u[n] and x2[n] = u[n]. The signal y[n] is the addition of two unit step signals. The python code which performs this task is shown in Fig. 3.27, and the corresponding output is shown in Fig. 3.28.

Fig. 3.27
A Python code to perform addition of two signals includes import numpy as n p, step 1 of generation of input signals, n = n p dot arange left parenthesis negative 10, 11, 1 right parenthesis, x and y = n greater than or equal to 0, step 2 of addition of the two signals, and step 3 of plotting the result.

Python code to perform addition of two signals

Fig. 3.28
Three output graphs of amplitude versus n plot x 1 of n, x 2 of n, and y of n. The horizontal line is drawn at an amplitude of 0. In all graphs, the dots lie on the horizontal line from negative 10 to negative 1. From 0 to 10, the dots lie at an amplitude of 1 in x 1 and x 2 of n and at an amplitude of 2 in y of n.

Result of python code shown in Fig. 3.27

Inferences

The following inferences are drawn from these Figs. 3.27 and 3.28:

  1. 1.

    By observing Fig. 3.27, it is possible to observe that the result of logical operation is converted to float using the command ‘.astype(‘float32’)’.

  2. 2.

    By observing Fig. 3.28, the inputs x1[n] and x2[n] are unit step signal, whose amplitude takes value from 0 to 1, whereas the amplitude of the output signal y[n] has variation from 0 to 2.

  3. 3.

    This experiment illustrates the fact that the amplitude of the signal can be changed by signal addition operation.

Task

  1. 1.

    Write a python code to illustrate the fact that ‘signal addition is a commutative operation’.

3.2.1.1 Time Scaling Operation

Time scaling operations can be classified into two types, namely, (1) downsampling and (2) upsampling.

  1. (a)

    Downsampling

    The downsampling of the signal x[n] by a factor of ‘M’ is represented as

    $$ y\left[n\right]=x\left[ Mn\right] $$
    (3.19)

    where ‘M’ is an integer. Here ‘M − 1’ samples will be discarded between two consecutive samples. Downsampling by a factor of ‘2’ is represented as

    $$ y\left[n\right]=x\left[2n\right] $$
    (3.20)

Experiment 3.14 Downsampling

This experiment discusses the downsampling operation on the input signal. The python code to perform downsampling by a factor of ‘2’ is shown in Fig. 3.29, and the corresponding output is shown in Fig. 3.30.

Fig. 3.29
A Python code to perform downsampling by a factor of M includes step 1 of generating the input signal, n = n p dot arange left parenthesis negative 10, 11, 1 right parenthesis, x = n, M = 2 downsampling factor, step 2 of performing downsampling operations, and step 3 of plotting the input and downsampled signal.

Python code to perform downsampling operation

Fig. 3.30
Two output graphs of amplitude versus n plot x of n and y of n. The horizontal line is drawn at an amplitude of 0. In x of n, the dots trend in an increasing pattern from (negative 10, negative 10) to (10, 10) via (0, 0). In y of n, the dots trend in an increasing pattern from (negative 5, 10) to (5, negative 10) via (0, 0).

Result of downsampling operation

Inferences

The following inferences can be drawn from this experiment:

  1. 1.

    By observing Fig. 3.30, the number of samples in the input signal x[n] is 21, whereas the number of samples in the output signal y[n] is 11.

  2. 2.

    Downsampling leads to a reduction in the number of samples.

Task

  1. 1.

    Write a python code to prove the fact that downsampling is an irreversible operation. That is, it is not possible to obtain the original signal from the downsampled signal because downsampling results in loss of signal samples.

  1. (b)

    Upsampling

    The upsampling of the signal x[n] by a factor of ‘L’ is represented by

    $$ y\left[n\right]=x\left[\frac{n}{L}\right] $$
    (3.21)

    The upsampling operation is basically inserting ‘L − 1’ zeros between two consecutive samples. For L = 2, the above expression can be written as

    $$ y\left[n\right]=x\left[\frac{n}{2}\right] $$

Experiment 3.15 Upsampling

This experiment deals with the upsampling process of discrete-time signal. The python code, which performs the upsampling operation by a factor of 2, is shown in Fig. 3.31, and the corresponding output is shown in Fig. 3.32.

Fig. 3.31
A Python code to perform upsampling by a factor of 2 includes step 1 of generating the input signal, L = 2 upsampling factor, n = n p dot arange left parenthesis negative 5, 6, 1 right parenthesis, N = len of n, step 2 of upsampling the input signal, and step 3 of plotting the input and output signal.

Python code performs upsampling by a factor of 2

Fig. 3.32
Two output graphs of amplitude versus n plot x of n and y of n. The horizontal line is drawn at an amplitude of 0.0. In x of n, the dots are plotted at an amplitude of 1.0 from negative 5 to 5. The vertical lines connect the dots to the horizontal line.

Result of upsampling by a factor of 2

Inference

The following observations can be made from this experiment:

By observing Fig. 3.32, it is possible to observe that in the case of upsampling by a factor of 2, one zero is inserted between successive samples. Generally, when upsampling by a factor of ‘L’, ‘L − 1’ zeros will be inserted between successive samples. Also, it shows that the number of samples in the output increases to almost L times than the number of samples in the input signal.

Task

  1. 1.

    Write a python code to illustrate the fact that ‘Upsampling is a reversible operation’. It is possible to obtain the original signal from the upsampled signal.

3.2.1.2 Time Shifting Operation

The time shifting operation can be broadly classified into two types: (1) delay operation and (2) advance operation.

  1. (a)

    Delay operation

    The delaying of the input signal by a factor of ‘k’ units is expressed as

    $$ y\left[n\right]=x\left[n-k\right] $$
    (3.22)

    where 'k' must be a positive integer.

  2. (b)

    Advance operation

    The advance of the input signal x[n] by a factor of ‘k’ units is expressed as

    $$ y\left[n\right]=x\left[n+k\right] $$
    (3.23)

    where ‘k’ must be a positive integer.

Experiment 3.16 Time Shifting Operation

This experiment performs both delay and advance operations by a factor of 'k' units on the unit step signal. First, the unit step signal is generated; then, it is delayed by a factor of 5 units. The unit step signal is advanced by the factor of 5 units. The python code, which performs this task, is shown in Fig. 3.33, and the corresponding output is shown in Fig. 3.34.

Fig. 3.33
A Python code to perform delay and advance operation includes import numpy as n p, import matplotlib dot pyplot as p l t, n = n p dot arange left parenthesis negative 10, 11 right parenthesis, x 1 = n greater than or equal to 0 u of n, k = 5, x 2 = n greater than or equal to delay of u of n, and advance of u of n.

Delay and advance of unit step sequence

Fig. 3.34
Three output graphs of amplitude versus n plot u of n, u of n minus 5, and u of n + 5. The horizontal line is drawn at an amplitude of 0. In u of n, the dots lie on the horizontal line from negative 10 to negative 1. In u of n minus 5, the dots lie on the horizontal line from negative 10 to 4.

Delay and advance of unit step sequence

Inference

This experiment illustrates the concept of shifting operation on the signal. Delay of the signal u[n] by a factor of ‘5’ units results in u[n − 5], whereas advance of the signal u[n] by a factor of 5 units results in u[n + 5]. It is to be observed that shifting operation on the signal will not alter the energy of the signal.

Task

  1. 1.

    Write a python code to illustrate the fact that the signal energy is unaltered due to signal shifting.

3.2.1.3 Time Reversal Operation

The time reversal of the signal x[n] is denoted as x[−n]. This refers to flipping the signal x[n] from left to right and right to left. It can be considered as a signal reflection about the origin. A discrete-time signal can be reversed in time by changing the sign of the independent variable for all instances. Two different ways to perform time reversal operation in python are given below.

Experiment 3.17 Time Reversal Without Built-In Function

This experiment deals with the time reversal operation using python without built-in function. In this method, the signal x[n] is flipped from left to right using the command" x[::−1]", the python code which performs the task of time reversal is shown in Fig. 3.35, and the corresponding output is shown in Fig. 3.36.

Fig. 3.35
A Python code to perform a time reversal operation includes import numpy as n p, import matplotlib dot pyplot as p l t, n = n p dot arange left parenthesis negative 10, 11, 1 right parenthesis, x = n, and p l t dot subplot left parenthesis 2, 1, 1 right parenthesis, p l t dot stem of n, x.

Method-1 to perform time reversal operation

Fig. 3.36
Two output graphs of amplitude versus n plot x of n and y of n. The horizontal line is drawn at an amplitude of 0. In x of n, the dots trend in an increasing pattern from (negative 10, negative 10) to (10, 10) via (0, 0). In y of n, the dots trend in a decreasing pattern from (negative 10, 10) to (10, negative 10) via (0, 0).

Result of python code shown in Fig. 3.35

Inference

Figure 3.36 clearly indicates that the left side of the input signal is moved into the right side of the output signal and the right side of the input signal is moved into the left side of the output signal.

Experiment 3.18 Time Reversal Using Built-In Function

This experiment tries to obtain the time reversal using a python built-in function. In this method, the built-in function ‘np.fliplr()’ is used to perform a time reversal operation. The python code, which performs this task, is shown in Fig. 3.37, and the corresponding output is shown in Fig. 3.38.

Fig. 3.37
A Python code to perform a time reversal operation includes import numpy as n p, import matplotlib dot pyplot as p l t, n = n p dot arange left parenthesis negative 10, 11, 1 right parenthesis, x = n, and p l t dot subplot left parenthesis 2, 1, 1 right parenthesis, p l t dot stem of n, x.

Method-2 to perform time reversal operation

Fig. 3.38
Two output graphs of amplitude versus n plot x of n and y of n. The horizontal line is drawn at an amplitude of 0. In x of n, the dots trend in an increasing pattern from (negative 10, negative 10) to (10, 10) via (0, 0). In y of n, the dots trend in a decreasing pattern from (negative 10, 10) to (10, negative 10) via (0, 0).

Result of python code shown in Fig. 3.37

Inference

This experiment confirms that the time reversal can be done using ‘np.fliplr’ built-in function.

Task

  1. 1.

    Write a python code to illustrate that flipping operation does not alter the signal’s energy.

3.3 Convolution

Convolution is an important operation in digital signal processing, because many DSP algorithms use convolution operations in one form or other. The most common application of convolution operation is filtering. It can be used for signal enhancement. The relationship between the input and output of a linear time-invariant system shown in Fig. 3.39.

Fig. 3.39
A representation of a linear time-invariant system includes input x of n, h of n, and output y of n.

Representation of the LTI system

The relationship between the input and output of the system is given by

$$ y\left[n\right]=x\left[n\right]\ast h\left[n\right] $$
(3.24)

In the above expression, ‘*’ denotes the convolution operation. The above expression can be written as

$$ y\left[n\right]=\sum \limits_{k=-\infty}^{\infty }x\left[k\right]h\left[n-k\right] $$
(3.25)

Convolution obeys commutative property; hence, the above equation can be expressed as

$$ y\left[n\right]=\sum \limits_{k=-\infty}^{\infty }h\left[k\right]x\left[n-k\right] $$
(3.26)

Experiment 3.19 Convolution of Given Signal with Unit Sample Signal

This experiment illustrates the fact that the convolution of any signal (x[n]) with unit sample signal (δ[n]) will result in the same signal x[n]. This is expressed as

$$ x\left[n\right]\ast \delta \left[n\right]=x\left[n\right] $$
(3.27)

The python code, which illustrates the above concept, is shown in Fig. 3.40, and the corresponding output is shown in Fig. 3.41.

Fig. 3.40
A Python code to perform a convolution with a unit sample sequence includes n = n p dot arange left parenthesis negative 5, 6 right parenthesis, step 1 of the generation of a triangular signal, step 2 of the generation of a unit sample signal, step 3 of performing the convolution, and step 4 of displaying the result.

Convolution of the signal x[n] with unit sample signal δ[n]

Fig. 3.41
3 output graphs of amplitude versus n plot x of n, h of n, and y of n. The horizontal line is drawn at an amplitude of 0.0. In x of n and y of n, the dots trend in an increasing pattern until 0 and start decreasing after 0. The peak lies at (0, 5). In h of n, the dots lie on the horizontal line, except for the dot at (0, 1).

Result of python code shown in Fig. 3.40

Inferences

The following inferences can be drawn from this experiment:

  1. 1.

    From Fig. 3.41, the input signal (x[n]) generated is a triangular signal.

  2. 2.

    The impulse response (h[n]) is unit sample signal (δ[n]).

  3. 3.

    The signal x[n] is convolved with unit sample signal to obtain the output signal y[n]. It can be observed that the output signal y[n] resembles the input signal x[n].

Experiment 3.20 Convolution of the Signal x[n] with Shifted Unit Sample Signal

This experiment illustrates the fact that the signal x[n] can be shifted by convolving it with δ[n ± k]. Convolving the signal x[n] with δ[n − k] results in delaying the signal x[n] by a factor of ‘k’. Convolving the signal x[n] with δ[n + k] results in advancing the signal x[n] by a factor of ‘k’. This is expressed as

$$ x\left[n\right]\ast \delta \left[n\pm k\right]=x\left[n\pm k\right] $$
(3.28)

The python code, which performs this task, is shown in Fig. 3.42, and the corresponding output is shown in Fig. 3.43.

Fig. 3.42
A Python code to perform a convolution with a shifted unit sample sequence includes n = n p dot arange left parenthesis negative 5, 6 right parenthesis, step 1 of the generation of a triangular signal, step 2 of the generation of shifted unit sample signals, step 3 of performing the convolution, and step 4 of displaying the result.

Python code to perform convolution of signal x[n] with shifted unit sample signal

Fig. 3.43
Six output graphs of amplitude versus n for x of n, h 1 of n, h 2 of n, y 1 of n, and y 2 of n. The horizontal line is drawn at an amplitude of 0. In two graphs of x and n, the dots trend in an increasing pattern until 0 and then start decreasing. In h 1 of n, the dots lie on the horizontal line from negative 5 to 4.

Result of python code shown in Fig. 3.42

Inferences

The task performed by the python program is summarized in Fig. 3.44.

Fig. 3.44
A representation of the task performed by the Python program includes an input signal x of n, h 1 of n = delta of n minus k, h 2 of n = delta of n + k, and output signals y 1 of n and y 2 of n.

Task performed by the python example

  1. 1.

    The input signal x[n] is applied to two systems with impulse responses h1[n] = δ[n − k] and h2[n] = δ[n + k] to obtain the output signals y1[n] and y2[n] respectively.

  2. 2.

    By comparing the input signal x[n] with the output signal y1[n], it is possible to observe that the output signal y1[n] is a shifted version (delayed version) of the input signal x[n].

  3. 3.

    By comparing the input signal x[n] with the output signal y2[n], it is possible to observe that the output signal y2[n] is a shifted version (advanced version) of the input signal x[n].

  4. 4.

    This experiment illustrates the fact that signal shifting can be accomplished using convolution operation.

Task

  1. 1.

    Repeat the above experiment with a rectangular pulse signal instead of a triangular one.

Experiment 3.21 Commutative Property of Convolution

The motive of this experiment is to prove the commutative property of convolution. The commutative property of convolution is expressed as

$$ x\left[n\right]\ast h\left[n\right]=h\left[n\right]\ast x\left[n\right] $$
(3.29)

The python code to illustrate the commutative property of convolution is given in Fig. 3.45, and the corresponding output is shown in Fig. 3.46.

Fig. 3.45
A Python code to perform a commutative property of convolution includes n = n p dot arange left parenthesis negative 5, 6 right parenthesis, step 1 of generating x of n, step 2 of generating h of n, h = x, step 3 of obtaining the outputs, and step 4 of plotting the results.

Python code to illustrate the commutative property of convolution

Fig. 3.46
Four output graphs of amplitude versus n plot x of n, h of n,and y 1 of n and y 2 of n = x of n times h of n. The horizontal line is drawn at an amplitude of 0.0. In x of n and h of n, the dots are plotted at an amplitude of 0.0 from negative 5 to negative 2 and 2 to 5.

Result of python code shown in Fig. 3.45

Inferences

The following inferences can be drawn from Fig. 3.46:

  1. 1.

    The input signal x[n] is a pulse signal. Similarly, the signal h[n] is a pulse signal. The signals x[n] and h[n] are the same.

  2. 2.

    The signal y1[n] is obtained by convolving x[n] with h[n], whereas the signal y2[n] is obtained by convolving h[n] with x[n]. From Fig. 3.46, the signals y1[n] and y2[n] are the same.

  3. 3.

    This experiment illustrates that convolution is commutative. Also, the convolution of two pulse signals results in a triangular signal.

Task

  1. 1.

    In the above experiment, let L1 and L2 be the length of the signals x[n] and h[n]. Then, the length of the convolved signal is L1 + L2 − 1. Write a python code to illustrate that linear convolution results in stretching the length of the signal.

Experiment 3.22 Associative Property of Convolution

The associative property of convolution is expressed as

$$ \left(x\left[n\right]\ast {h}_1\left[n\right]\right)\ast {h}_2\left[n\right]=x\left[n\right]\ast \left({h}_1\left[n\right]\ast {h}_2\left[n\right]\right) $$
(3.30)

To illustrate this property, the input signal x[n] chosen is x[n] = ejπn, which toggles between +1 and −1. The impulse response h1[n] = δ[n − k] and the impulse response h2[n] = δ[n + k]. The python code, which illustrates the associative property of the convolution operation, is given in Fig. 3.47, and the corresponding outputs are shown in Figs. 3.48 and 3.49, respectively.

Fig. 3.47
A Python code to perform an associative property of convolution includes steps 1 of generation of a triangular signal, step 2 of generation of shifted unit sample signals, k = 5, h 1 = left parenthesis, n = = k right parenthesis, step 3 of performing the convolution, and step 4 of displaying the result.

Python code to illustrate associative property of convolution

Fig. 3.48
Three output graphs of amplitude versus n plot x of n, h subscript 1 of n, and h subscript 2 of n. The horizontal line is drawn at an amplitude of 0. In h subscript 1 of n, the dots are plotted at an amplitude of 0 from negative 5 to 4. In h subscript 1 of n, the dots are plotted at an amplitude of 0 from negative 4 to 5.

Input signal and impulse response

Fig. 3.49
Two output graphs of amplitude versus n plot y 1 of n and y 2 of n = x of n times h 1 of n times h 2 of n. The horizontal line is drawn at an amplitude of 0. The dots are plotted at an amplitude of 0 from negative 15 to negative 5 and 5 to 15.

Output signal

Inferences

The following are the inferences from this experiment:

  1. 1.

    The input signal x[n] = (−1)n, −5 ≤ n ≤ 5. The impulse response h1[n] = δ[n − 5] and h2[n] = δ[n + 5], which is shown in Fig. 3.48.

  2. 2.

    The output y1[n] = (x[n]*h1[n])*h2[n], whereas the output y2[n] = x[n]*(h1[n]*h2[n]). From Fig. 3.49, it is possible to observe that the output y1[n] = y2[n], which shows that associative property of convolution is verified.

Experiment 3.23 Distributive Property of Convolution

The distributive property of convolution is expressed as

$$ x\left[n\right]\ast \left({h}_1\left[n\right]+{h}_2\left[n\right]\right)=x\left[n\right]\ast {h}_1\left[n\right]+x\left[n\right]\ast {h}_2\left[n\right] $$
(3.31)

For illustration, the signal x[n] is chosen as x[n] = δ[n + 1] + 2δ[n] + δ[n − 1], h1[n] = δ[n + 1] + δ[n] + δ[n − 1] and h2[n] =  − δ[n + 1] − δ[n − 1] such that h1[n] + h2[n] results in unit sample signal. The python code, which illustrates the distributive of convolution, is shown in Fig. 3.50, and the corresponding outputs are shown in Figs. 3.51 and 3.52, respectively.

Fig. 3.50
A Python code to illustrate the distributive property of convolution includes n = n p dot arange left parenthesis negative 5, 6 right parenthesis, step 1 of generation of input signal, step 2 of generation of h 1 and h 2, step 3 of performing the convolution, h = h 1 + h 2, and step 4 of displaying the result.

Python code to illustrate distributive property of convolution

Fig. 3.51
Three output graphs of amplitude versus n plot x of n, h subscript 1 of n, and h subscript 2 of n. The horizontal line is drawn at an amplitude of 0. The dots are plotted at an amplitude of 0 from negative 5 to negative 2 and 2 to 5.

Plot of input signal and the impulse responses

Fig. 3.52
Two output graphs of amplitude versus n plot y 1 of n and y 2 of n = x of n times h 1 of n times h 2 of n. The horizontal line is drawn at an amplitude of 0. The dots are plotted at an amplitude of 0 from negative 10.0 to negative 2.5 and 2 to 9.5.

Plot of the output signals

Inferences

  1. 1.

    From Fig. 3.51, it is possible to observe that the input signal and the impulse responses are all finite-duration signals. The input signal is expressed as x[n] = δ[n + 1] + 2δ[n] + δ[n − 1]. The impulse responses are given by h1[n] = δ[n + 1] + δ[n] + δ[n − 1] and h2[n] =  − δ[n + 1] − δ[n − 1].

  2. 2.

    The sum of the impulse responses results in a unit sample signal, which is expressed as h1[n] + h2[n] = δ[n]. Also, convolution of any input signal x[n] with unit sample signal results in the same signal, which is expressed as x[n] ∗ δ[n] = x[n]. Because of this property, the output signal y1[n] is same as the input signal x[n].

  3. 3.

    By observing the output signals y1[n] and y2[n], it is possible to infer y1[n] = y2[n], which implies that the distributive property of convolution is illustrated through this experiment.

Experiment 3.24 Convolution of a Square Wave with Lowpass Filter Coefficient

In this experiment, a square wave of fundamental frequency 5 Hz is generated. It is then passed through moving average filter with M = 5, 7, 9, and 11. The block diagram of the experiment performed is shown in Fig. 3.53.

Fig. 3.53
A block diagram of the experiment performed includes the input signal of a square wave, a low-pass filter, and the output signal.

Block diagram of problem statement

The impulse response of lowpass filter (moving average filter) is given by

$$ h\left[n\right]=\frac{1}{M}\sum \limits_{k=0}^{M-1}\delta \left[n-k\right] $$
(3.32)

In this experiment, the value of ‘M’ is chosen as 5, 7, 9 and 11.

The expression for the output signal is given by

$$ y\left[n\right]=x\left[n\right]\ast h\left[n\right] $$

The python code which accomplishes this task is shown in Fig. 3.54, and the corresponding output is shown in Figs. 3.55 and 3.56.

Fig. 3.54
A Python code to perform lowpass filtering of a square wave includes step 1 of the generation of the input signal, step 2 of the generation of low pass filter coefficient, M = left square bracket 5, 7, 9, 11, right square bracket, step 3 of obtaining the output signal, and step 4 of plotting the results.

Python code to perform lowpass filtering of square wave

Fig. 3.55
A graph of amplitude versus time plots the input signal in a square waveform. It passes through (0.0, 1.00), (0.1, negative 1.00), (0.2, 1.00), (0.4, 1.00), (0.5, negative 1.00), (0.8, 1.00), and (1.0, 1.00).

Input square waveform

Fig. 3.56
Four output graphs of amplitude versus time for the output signal for M = 5, 7, 9, and 11 plot the waveform ranges between negative 1 and 1. The triangular waveforms are plotted on the output signal for M = 9 and 11.

Lowpass filtered square waveform

Inferences

The following inferences can be drawn from Figs. 3.55 and 3.56:

  1. 1.

    The input to the system is a square wave of a fundamental frequency 5 Hz.

  2. 2.

    The system is passed through lowpass filter to obtain a triangular waveform.

  3. 3.

    By observing the input and output waveform, it is possible to observe that the system converts drastic change (square waveform) to a gradual change (sawtooth waveform). The system basically performs lowpass filtering of the input signal.

  4. 4.

    The extent of smoothing is governed by the value of ‘M’. Increasing the value of ‘M’ increases the extent of smoothing the input signal.

Task

  1. 1.

    In the above experiment, replace the square wave input with sine wave with a spike signal. That is a sine wave with an abrupt change in amplitude in a few time instants. Now pass this sine wave through the moving average filter and comment on the observed signal.

Experiment 3.25 Convolution of a Square Wave with Highpass Filter Coefficient

In this experiment, the square wave is passed through highpass filter whose impulse response is h[n] = {1/2, −1/2}. The highpass filter is basically a change detector. When a square wave is fed to highpass filter, the resultant waveform is a spike waveform. The python code, which performs this task, is shown in Fig. 3.57, and the corresponding output is shown in Fig. 3.58.

Fig. 3.57
A Python code to perform a square wave through a high-pass filter includes from scipy import signal, step 1 of the generation of the input signal, step 2 of the generation of the high pass filter coefficient, step 3 to obtain the output signal, and step 4 of plotting the input and output signals.

Python code to perform highpass filtering of square wave

Fig. 3.58
Three output graphs. 1. A graph of amplitude versus time plots the input signal in the form of square wave ranges between negative 1 and 1. 2. A graph of amplitude versus n plots h of n. The dots lie at (0.0, 0.5) and (1.0, negative 0.5). 3. A graph of amplitude versus time plots the output signal.

Spike waveform obtained by differentiating input square wave

Inferences

The following inferences can be made from this experiment:

  1. 1.

    From Fig. 3.57, it is possible to infer that the input signal is a square wave, the impulse response of highpass filter is h[n] = {1/2, −1/2}.

  2. 2.

    From Fig. 3.58, it is possible to observe that the output waveform is a spike waveform. It is due to the fact that differentiation of a constant is zero. In a square wave, major portion is constant in magnitude; hence, differentiation of a constant is zero. Highpass filter is a change detector; hence, it gives spike waveform as the output for the input square waveform.

Task

  1. 1.

    Generate sine wave of 5 Hz frequency. Add white noise, which follows normal distribution to this sine wave. Now pass this noisy sine wave through highpass filter. Plot the clean sine wave, noisy sine wave and highpass filtered signal. Write a python code to answer the query ‘Does highpass filter tend to amplify the noise?’

3.4 Correlation

Correlation is a tool to find the relative similarity between two signals. Correlation has two variants, namely: autocorrelation and cross-correlation. Autocorrelation involves the correlation of a signal with itself. Cross-correlation is performed when two different signals are correlated with one another.

The expression for autocorrelation of the sequence x[n] is given by

$$ {r}_{xx}(l)=x\left[l\right]\ast x\left[-l\right] $$
(3.33)

Equation (3.33) gives the relationship between correlation and convolution. Convolving the folded version of the sequence x[n] with the signal x[n] results in autocorrelation. Equation (3.33) can be expressed as

$$ {r}_{xx}(l)=\sum \limits_{n=-\infty}^{\infty }x\left[n\right]x\left[n+l\right] $$
(3.34)

Some of the properties of the autocorrelation function are summarized below:

  1. 1.

    Autocorrelation function is an even function. It is expressed as rxx(−l) = rxx(l).

  2. 2.

    Autocorrelation attains its maximum value at zero lag. It is expressed as rxx(0) ≥ |rxx(k)| for all ‘k’.

The cross-correlation between two signals x[n] and y[n] is expressed as

$$ {r}_{xy}(l)=x\left[l\right]\ast y\left[-l\right] $$
(3.35)

The above equation can be expressed as

$$ {r}_{xy}(l)=\sum \limits_{k=-\infty}^{\infty }x\left[k\right]y\left[l+k\right] $$
(3.36)

Experiment 3.26 Autocorrelation and Cross-correlation of Sine and Cosine Waves

In this experiment, two signals, namely, sine wave and cosine wave of frequency 5 Hz, are generated. Then, the autocorrelation between the sinewave and cosine wave and the cross-correlation between sine and cosine wave is computed. The results of autocorrelated and cross-correlated signals are plotted. The python code, which performs the above-mentioned task, is shown in Fig. 3.59, and the corresponding output is shown in Fig. 3.60.

Fig. 3.59
A Python code to perform autocorrelation and cross-correlation includes step 1 of the generation of sine and cosine wave, f = 5, N = len of x, step 2 of perform autocorrelation and cross-correlation, lag = n p dot arange left parenthesis negative N + 1, N right parenthesis, and step 3 of plot the results.

Autocorrelation and cross-correlation between signals

Fig. 3.60
Four output graphs. 1 and 2. Two graphs of r subscript x x of I and r subscript y y depict autocorrelation versus lag. 3 and 4. Two graphs of r subscript x y of I and r subscript y x depict cross correlation versus lag. In all graphs, the highest peak lies at (0, 50).

Autocorrelation and cross-correlation results

Inferences

The following observation can be made from this experiment:

  1. 1.

    The autocorrelation between the sine waves is represented by rxx(l). The autocorrelation result is observed to be even symmetric. The maximum value is obtained at zero lag.

  2. 2.

    The autocorrelation between the cosine waves is represented by ryy(l). The autocorrelation is an even symmetric function with the maximum value obtained at zero lag.

  3. 3.

    The cross correlation between sine and cosine waves is not even symmetric. Also, it is possible to observe that rxy(l) is not equal to ryx(l).

  4. 4.

    The autocorrelation and cross-correlation are used to find the relative similarity between the two signals.

Tasks

  1. 1.

    Write a python code to illustrate the fact that maximum value of autocorrelation occurs at zero lag.

  2. 2.

    Write a python code to illustrate the fact that correlation can be performed in terms of convolution. That is convolution of a signal with its folded version results in autocorrelation.

Experiment 3.27 Autocorrelation of Sine Wave to Itself and Noisy Signal

In this experiment, sine wave of 5 Hz is generated. It is stored as the variable ‘x’. The sine wave is then corrupted by random noise, which follows normal distribution to obtain the signal ‘y’. The autocorrelation of clean sine wave is obtained as rxx(l), and the cross-correlation between the clean and noisy sine wave is obtained as rxy(l). The python code, which performs this task, is shown in Fig. 3.61, and the corresponding output is shown in Fig. 3.62.

Fig. 3.61
A Python code to perform autocorrelation and cross-correlation includes step 1 of the generation of sine and cosine waves, f = 5, N = len of x, step 2 of perform autocorrelation and cross-correlation, lag = n p dot arange left parenthesis negative N + 1, N right parenthesis, and step 3 of plot the results.

Python code to perform autocorrelation of clean and noisy sine wave

Fig. 3.62
Four output graphs. 1 and 2. Two graphs of the sine wave x of t and the noisy sine wave y of t depict amplitude versus time. 3. A graph of r subscript x x of I depicts autocorrelation versus lag. 4. A graph of r subscript x y depicts cross-correlation versus lag.

Autocorrelation and cross-correlation of clean and noisy sine wave

Inferences

  1. 1.

    In Fig. 3.62, x(t) represents clean sine wave of 5 Hz frequency, and y(t) represents noisy sine wave. The noisy sine wave is obtained by adding random noise to the clean sine wave.

  2. 2.

    In Fig. 3.62, rxx(l) represents the autocorrelation of a clean sine wave. The autocorrelation function exhibits even symmetry, with the maximum value occurring at zero lag.

  3. 3.

    In Fig. 3.62, rxy(l) represents the cross-correlation between clean and noisy sine waves. The cross-correlation is not exhibiting even symmetry relation. Comparing rxx(l) and rxy(l), the maximum value is obtained in autocorrelation function. Thus, the autocorrelation reveals the relative similarity between the signals.

Experiment 3.28 Delay Estimation Using Autocorrelation

In this experiment, unit step sequence (signal ×1) is generated, it is then shifted by a factor of ‘5’ units to the right to obtain the signal ×2. The autocorrelation of the signal ×1 to itself and the correlation between the signals ×1 and ×2 are used to estimate the delay. The python code, which performs this function, is shown in Fig. 3.63, and the corresponding output is shown in Fig. 3.64.

Fig. 3.63
A Python code to perform delay estimation using correlation with 5 steps includes generation of unit step signal, a delay signal by a factor of 5 units, perform autocorrelation of signal x 1, perform the cross-correlation between x 1 and x 2, estimate the delay, and plot the signal and its delayed version.

Python code to perform delay estimation

Fig. 3.64
Two output graphs of x 1 of n and x 2 of n compare amplitude versus n. The dots are plotted at an amplitude of 0.0 from negative 20 to negative 1 and at an amplitude of 1.0 from 0 to 20. The horizontal line is drawn at 0.0. The vertical lines connect the horizontal line and the dots at an amplitude of 1.0.

Signal and its delayed version

Inference

Upon displaying the result, the answer in the variable ‘td’ is ‘5’, which is a measure of delay between the two signals x1[n] and x2[n]. Thus, autocorrelation can be used to measure or estimate the delay between the two signals.

Exercises

  1. 1.

    Generate the following sequences (a) x1[n] = δ[n + 1] + δ[n − 1] (b) x1[n] = δ[n + 1] − δ[n − 1] (c) x3[n] = δ[n] + 2δ[n − 1] + δ[n − 2] and (d) x4[n] = δ[n] − δ[n − 1] + δ[n − 2], and plot it using a subplot, which consists of two rows and two columns. The time index should vary from −5 to +5.

  2. 2.

    Write a python code to generate the finite length discrete-time signals (a) x1[n] = u[n] − u[n − 5], (b) x2[n] = δ[n], (c) x3[n] = u[n + 5] − u[n − 5] and (d) \( {x}_4\left[n\right]=\left\{\begin{array}{c}n,0\le n\le 5\\ {}0,\mathrm{otherwise}\end{array}\right. \) in the interval −10 ≤ n ≤ 10. Use subplot to plot the generated signals.

  3. 3.

    Generate a complex exponential signal \( x\left[n\right]={\mathrm{e}}^{j\frac{\pi }{4}n},-10\le n\le 10 \). Perform the following: (a) Extract the real and imaginary part of this signal. (b) Reconstruct the signal x[n] from the real and imaginary parts using the relation x[n] =  Re {x[n]} + j Im {x[n]}.

  4. 4.

    Generate a complex exponential signal of the form \( x\left[n\right]={\mathrm{e}}^{j\frac{\pi }{8}n},-10\le n\le 10 \). Obtain the signal y[n], which is expressed as y[n] = x[n] × x[n], and comment on the nature of the signal y[n].

  5. 5.

    Write a python code to generate the following sequences:

    1. (a)

      x1[n] = δ[n] + δ[n − 1] + δ[n − 2] + δ[n − 3] + δ[n − 4] + δ[n − 5] + δ[n − 6] + δ[n − 7]

    2. (b)

      x2[n] = δ[n] − δ[n − 1] + δ[n − 2] − δ[n − 3] + δ[n − 4] − δ[n − 5] + δ[n − 6] − δ[n − 7]

    3. (c)

      x3[n] = δ[n] + δ[n − 1] − δ[n − 2] − δ[n − 3] + δ[n − 4] + δ[n − 5] − δ[n − 6] − δ[n − 7]

    4. (d)

      x4[n] = δ[n] + δ[n − 1] + δ[n − 2] + δ[n − 3] − δ[n − 4] − δ[n − 5] − δ[n − 6] − δ[n − 7]

      Compute the energy of these sequences and comment on the obtained result.

  6. 6.

    Sketch the following signals in the range −5 ≤ n ≤ 5 (a) x1[n] = 2nδ[n − 2] (b) x2[n] = n[δ[n + 2] + δ[n − 2]].

  7. 7.

    Generate the signal \( x\left[n\right]=\left\{\begin{array}{c}5-\left|n\right|,\left|n\right|\le 5\;\\ {}0,\mathrm{otherwise}\end{array}\right. \) in the range −10 ≤ n ≤ 10. Extract the even and odd part of the signal. Try to reconstruct the signal from the even and odd part and comment on the observed output.

  8. 8.

    Write a python code to demonstrate the following facts:

    1. (a)

      Product to two even signals is an even signal.

    2. (b)

      Product of two odd signals is an even signal.

    3. (c)

      Product of an even and odd signal is odd signal.

  9. 9.

    Read a speech signal and perform the autocorrelation of the speech signal, and observe whether the autocorrelation function is an even function.

  10. 10.

    Read a ‘male’ and ‘female’ voice. Perform the following

    1. (a)

      Autocorrelation of the male voice (x)

    2. (b)

      Autocorrelation of the female voice (y)

    3. (c)

      Cross-correlation between male and female voice

    4. (d)

      Cross-correlation between female and male voice

Comment on the observed output.

Objective Questions

  1. 1.

    The python code segment shown below generates

    A Python code with two lines. Line 1 reads, n = n p dot arange left parenthesis negative 10, 11, 1 right parenthesis. Line 2 reads, x = left parenthesis n greater than or equal to 0 right parenthesis.
    1. A.

      Unit sample signal

    2. B.

      Unit step signal

    3. C.

      Unit ramp signal

    4. D.

      Real exponential signal

  2. 2.

    The value of the signal ‘x’ shown in the following python code is high at n =?

    A Python code with two lines. Line 1 reads, n = n p dot arange left parenthesis negative 10, 11, 1 right parenthesis. Line 2 reads, x = left parenthesis, n = = negative 2 right parenthesis.
    1. A.

      −1

    2. B.

      −2

    3. C.

      0

    4. D.

      2

  3. 3.

    If the variable ‘x’ contains the signal of interest, then the variable ‘y’ in the following python code returns

    A Python code reads, y = n p dot sum left parenthesis n p dot a b s left parenthesis x asterisk asterisk 2 double right parentheses.
    1. A.

      Maximum value of the signal

    2. B.

      Minimum value of the signal

    3. C.

      Energy of the signal

    4. D.

      Power of the signal

  4. 4.

    The signal generated in the variable ‘x’ after executing the following segment of code is

    A Python code with 2 lines. Line 1 reads, n = n p dot arange left parenthesis negative 10, 11 right parenthesis. Line 2 reads, X = left parenthesis n = = negative 1 right parenthesis vertical bar left parenthesis n = = 0 right parenthesis vertical bar left parenthesis n = = 1 right parenthesis.
    1. A.

      x[n] = δ[n] + δ[n – 1] – δ[n + 1]

    2. B.

      x[n] = δ[n + 1] + δ[n] + δ[n – 1]

    3. C.

      x[n] = δ[n + 1] + δ[n] – δ[n – 1]

    4. D.

      x[n] = δ[n + 1] + 2δ[n] + δ[n – 1]

  5. 5.

    The signal generated in the variable ‘x’ after executing the following segment of code is

    A Python code with 4 lines. Line 1 reads, n = n p dot arange left parenthesis negative 10, 11, 1 right parenthesis. Line 2 reads, x 1 = n asterisk left parenthesis n greater than or equal to 0 right parenthesis. Line 3 reads, x 2 = n + 1 asterisk n + 1 greater than or equal to 0, and x = x 2 minus x 1.
    1. A.

      Unit sample sequence

    2. B.

      Unit step sequence

    3. C.

      Unit ramp sequence

    4. D.

      Real exponential sequence

  6. 6.

    What would be the energy of the signal ‘x’ which is stored in variable ‘E’ if the following code segment is executed?

    A Python code with 3 lines. Line 1 reads, n = n p dot arange left parenthesis negative 10, 11 right parenthesis. Line 2 reads, x = left parenthesis n = = negative 1 right parenthesis vertical bar left parenthesis n = = 0 right parenthesis vertical bar left parenthesis n = = 1 right parenthesis.
    1. A.

      1J

    2. B.

      2J

    3. C.

      3J

    4. D.

      4J

  7. 7.

    What operation is performed on the input signal ‘x’ if the following segment of code is executed?

    A Python code with 2 lines. Line 1 reads, x = left square bracket 1, 2, 3 right square bracket. Line 2 reads, y = n p dot convolve left parenthesis x, x left square bracket colon colon negative 1 right square bracket, mode = single quotation full single quotation right parenthesis.
    1. A.

      Convolution of signal ‘x’ with itself

    2. B.

      Correlation of the signal ‘x’ with itself

    3. C.

      Power spectral estimation of the signal ‘x

    4. D.

      Energy density estimation of signal ‘x

  8. 8.

    A square wave is fed to a lowpass filter, the resulting signal is

    1. A.

      Sine wave

    2. B.

      Cosine wave

    3. C.

      Triangular wave

    4. D.

      Inverted square wave

  9. 9.

    The energy of the signal is unaltered by the following mathematical operation

    1. A.

      Downsampling of the signal by a factor of ‘M

    2. B.

      Upsampling the signal by a factor of ‘L

    3. C.

      Amplitude scaling

    4. D.

      Folding of the signal

  10. 10.

    The energy of the signal is unaltered by the following mathematical operation:

    1. A.

      Downsampling of the signal by a factor of ‘M

    2. B.

      Upsampling the signal by a factor of ‘L

    3. C.

      Delaying or advancing the signal by a factor of ‘k

    4. D.

      Amplitude scaling of the signal

  11. 11.

    Upsampling by a factor of ‘L’ inserts

    1. A.

      L’ zeros between successive samples

    2. B.

      L – 1’ zeros between successive samples

    3. C.

      L + 1’ zeros between successive samples

    4. D.

      L + 2’ zeros between successive samples

  12. 12.

    If a discrete-time signal x[n] obeys the relation x[−n] = x[n], then the signal is

    1. A.

      Odd signal

    2. B.

      Even signal

    3. C.

      Either even or odd signal

    4. D.

      Neither even nor odd signal

  13. 13.

    Sum of elements of finite duration discrete-time odd signal is

    1. A.

      Infinite

    2. B.

      One

    3. C.

      Zero

    4. D.

      Always negative

  14. 14.

    The python code shown below generates the following signal in the variable ‘x

    A Python code with 3 lines. Line 1 reads, n = n p dot arange left parenthesis negative 20, 21 right parenthesis. Line 2 reads, k =5. Line 3 reads, x 1 = left parenthesis n greater than or equal to k.
    1. A.

      u[n]

    2. B.

      u[−n]

    3. C.

      u[n + 5]

    4. D.

      u[n – 5]

  15. 15.

    The product of two odd signal results in

    1. A.

      Odd signal

    2. B.

      Even signal

    3. C.

      Either even or odd signal depending on the length of the signals

    4. D.

      Neither even nor odd signal

  16. 16.

    Identify the statement which is FALSE

    1. A.

      Autocorrelation is finding the relative similarity of the signal to itself.

    2. B.

      Autocorrelation is an even function.

    3. C.

      Autocorrelation attains its maximum value at zero lag.

    4. D.

      Auto correlation is an odd function.

  17. 17.

    What will be the fundamental period of the signal ‘x’ if the following python code is executed?

    A Python code with 2 lines. Line 1 reads, n = n p dot arange left parenthesis negative 10, 11, d type = single quotation float single quotation right parenthesis. Line 2 reads, x = left parenthesis negative 1 right parenthesis asterisk asterisk n.
    1. A.

      1

    2. B.

      2

    3. C.

      3

    4. D.

      4

  18. 18.

    Assertion: Highpass filter act as change detector

    Reason: Highpass filter has the ability to detect the change in the input signal

    1. A.

      Both assertion and reason are true.

    2. B.

      Assertion is true, reason is false.

    3. C.

      Assertion is false, reason may be true.

    4. D.

      Both assertion and reason are false.

  19. 19.

    What will be the length of the signal ‘y’ if the following code segment is executed?

    A Python code with 4 lines. Line 1 reads, n = n p dot arange left parenthesis negative 5, 6 right parenthesis. Line 2 reads, n p dot array left parenthesis and square bracket 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0 right square bracket and parenthesis. Line 4 reads, y = n p dot convolve of x, h, mode = full.
    1. A.

      11

    2. B.

      21

    3. C.

      31

    4. D.

      41

  20. 20.

    What will be the impulse response (h[n]) if the following code segment is executed?

    A Python code with 4 lines. Line 1 reads, n = n p dot arange left parenthesis negative 5, 6 right parenthesis. Line 2 reads, n p dot array left parenthesis and square bracket 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0 right square bracket and parenthesis. Line 4 reads, h = h 1 + h 2.
    1. A.

      h[n] = δ[n]

    2. B.

      h[n] = δ[n − 1]

    3. C.

      h[n] = u[n]

    4. D.

      h[n] = u[n − 1]

  21. 21.

    Identify the statement that is WRONG with respect to ‘folding’ or ‘time reversal’ operation

    1. A.

      Folding operation does not alter the energy of the signal.

    2. B.

      Folding increases the length of the signal.

    3. C.

      If the folded version of the signal is equal to the signal itself, then the signal is even signal.

    4. D.

      If the folded version of the signal is equal to the signal itself, then the signal is odd signal.

  22. 22.

    If x[n] is a unit step signal, then the following signal (y[n]) generated from x[n] is

    A Python code with 2 lines. Line 1 reads, n = n p dot arange left parenthesis negative 5, 6 right parenthesis. Line 2 reads, y = n power asterisk x.
    1. A.

      Unit sample signal

    2. B.

      Unit step signal

    3. C.

      Unit ramp signal

    4. D.

      Real exponential signal

  23. 23.

    The fundamental frequency of the signal generated by executing the following code is

    A Python code with 2 lines. Line 1 reads, n = n p dot arange left parenthesis negative 10, 11, d type = single quotation float single quotation right parenthesis. Line 2 reads, x = left parenthesis negative 1 right parenthesis asterisk asterisk n.
    1. A.

      ω = π/2 rad/sample

    2. B.

      ω = π rad/sample

    3. C.

      ω = π/4 rad/sample

    4. D.

      ω = π/8 rad/sample