Merge branch 'master' of https://gitea.sharpe6.com/Adog64/Rowan-Classes
This commit is contained in:
BIN
6th-Semester-Spring-2024/DSP/Quizzes/FinalExam/answer_sheet.docx
Normal file
BIN
6th-Semester-Spring-2024/DSP/Quizzes/FinalExam/answer_sheet.docx
Normal file
Binary file not shown.
@ -0,0 +1,38 @@
|
||||
import numpy as np
|
||||
import scipy.signal
|
||||
|
||||
def shifter(matrix):
|
||||
last = matrix[len(matrix)-1]
|
||||
x = len(matrix)
|
||||
result = [0] * x
|
||||
for i in range(1,len(matrix)):
|
||||
result[i] = matrix[i-1]
|
||||
result[0] = last
|
||||
return result
|
||||
|
||||
def circular_convolve(x,h,n,m):
|
||||
primary_matrix = np.zeros((max(n,m),max(n,m)))
|
||||
for i in range(0,len(primary_matrix[0])):
|
||||
primary_matrix[0][i] = x[i]
|
||||
for i in range(1,max(n,m)):
|
||||
primary_matrix[i] = shifter(primary_matrix[i-1])
|
||||
ultimate_matrix = np.transpose(primary_matrix)
|
||||
difference_in_length = abs(n-m)
|
||||
for i in range(m,m+difference_in_length):
|
||||
h.append(0)
|
||||
resultant = np.dot(ultimate_matrix,h)
|
||||
return resultant
|
||||
|
||||
X = np.ones(10)
|
||||
X[0] += 2
|
||||
H = np.zeros(10)
|
||||
H[0] += 1
|
||||
|
||||
y = np.fft.ifft(H*X)
|
||||
print(np.sum(y))
|
||||
|
||||
#lin_conv = scipy.signal.fftconvolve(x,h,"full")
|
||||
#circ_conv = circular_convolve(x, h, len(x), len(x))
|
||||
#
|
||||
#print(f"Linear convolution: {lin_conv}")
|
||||
#print(f"Circular convolution: {circ_conv}")
|
Reference in New Issue
Block a user