Architectures and Algorithms For DSP Systems (Crl702) : Centre For Applied Research in Electronics Iit Delhi
Architectures and Algorithms For DSP Systems (Crl702) : Centre For Applied Research in Electronics Iit Delhi
IIT DELHI
NumPy Library
In this question we use NumPy library of python. NumPy stands for Numerical Python. NumPy has
functions related to data manipulation related to array, matrices. It also has functions for arrays, linear
algebra, Fourier transform, and matrices. NumPy was created in 2005 by Travis Oliphant. It is an open-
source project, and we can use it freely.
NumPy provides array objects which is different from traditional Lists. Arrays are very faster then Lists.
Because NumPy uses continuous memory locations to store the data. SO NumPy is very famous in field
of data science because of its speed and resources.
Array object in NumPy is called ‘ndarray’.
Code
import numpy as np
a=a[:c:1]
print("reversed array is: ", a)
ALGORITHM
1. import numpy as np
here we firstly import NumPy library as NP and use the NP for NumPy reference.
2. a=np.array([1,2,3,4,5])
print("original array is: ", a)
c=np.size(a)
here we enter a array. We use np.array so it use array object of NumPy library . And then we print
the original array by using print function. Here we using size function of the NumPy library to get
the size of the array.
3. a=np.append(a,a)
here we use the append function to make the a matrix size double. Now the ‘a’ matrix became
double the size of previous array.
here we use the for loop and assign the right half elements to the reverse order. Using this
operation the right half element get reversed and assign to the left half elements.
5. a=a[:c:1]
print("reversed array is: ", a)
here we first assign the first half elements to the a array. Rest right half elements gets discarded.
Then we print this matrix ‘a’.
Results
After execution, this program into “Pycharm” software. We get the following results.
Enter number of elements of array : 4
Enter the values of input array :
1
2
3
4
Original Array is : [1 2 3 4]
reversed array is: [4 3 2 1]
we can see that these results are correct. And the python program is working fine.
OBJECTIVE :- 2
Input two NumPy arrays of arbitrary length and compute their cross-correlation. Also find auto-
correlation of those two input arrays. Your code should work for any arbitrary length of array. Also,
implement correlation using matrix multiplication method.
Correlation
In signal processing, cross-correlation is a measure of similarity of two series as a function of the
displacement of one relative to the other. This is also known as a sliding dot product or sliding inner-
product. It is commonly used for searching a long signal for a shorter, known feature. The cross-
correlation is similar in nature to the correlation of two functions.
In an autocorrelation, which is the cross-correlation of a signal with itself, there will always be a peak at
a lag of zero, and its size will be the signal energy.
Code
import numpy as np
# creating an empty list
arr_1 = []
arr_2 = []
return matrix_mul
Algorithm
We used 3 method to calculate the cross correlation and auto correlation of two arrays ,these methods are-
1. Using built in command “np.correlate” of Numpy library
2. Using Shift and Multiplication method
3. Using Matrix Multiplication Method