Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mutalibcs committed Jul 26, 2023
0 parents commit 04f9906
Show file tree
Hide file tree
Showing 7 changed files with 1,323 additions and 0 deletions.
149 changes: 149 additions & 0 deletions 1-DSP(15_5_23).ipynb

Large diffs are not rendered by default.

409 changes: 409 additions & 0 deletions 2-DSP-DFT(18_5_23).ipynb

Large diffs are not rendered by default.

180 changes: 180 additions & 0 deletions 3-ConvByDFTs(25_5_23).ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "fxLfsY4tTvRQ"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 2 4 7 13 19 13 17 15]\n"
]
}
],
"source": [
"x = [1,2,3,4,5]\n",
"h = [2,0,1,3]\n",
"N = len(x)+len(h)-1\n",
"y = np.convolve(x,h,'full')\n",
"print(y)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"id": "gsj-v0wAVjny"
},
"outputs": [],
"source": [
"# DFT\n",
"def DFT(x,N):\n",
" X = np.zeros(N,dtype = 'complex_')\n",
" for k in range(N):\n",
" for n in range(N):\n",
" X[k] = X[k] + x[n]*np.exp(-1j*2*np.pi*k*n/N)\n",
" return X"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# DFT\n",
"def DFT(x,N):\n",
" X = np.zeros(N, dtype='complex_')\n",
" for k in range(N):\n",
" for n in range(N):\n",
" X[k] = X[k]+ x[n]*np.exp(-1j*2*np.pi*k*n/N)\n",
" return X"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"id": "lWSyGo2mShqY"
},
"outputs": [],
"source": [
"# IDFT\n",
"def IDFT(X, N):\n",
" y = np.zeros(N,dtype = 'complex_')\n",
" for n in range(N):\n",
" for k in range(N):\n",
" y[n] = y[n] + X[k]*np.exp(1j*2*np.pi*k*n/N)\n",
" \n",
" return y/N"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# IDFT\n",
"def IDFT(X,N):\n",
" y = np.zeros(N, dtype='complex_')\n",
" for n in range(N):\n",
" for k in range(N):\n",
" y[n] = y[n]+X[k]*np.exp(1j*2*np.pi*k*n/N)\n",
" return y/N"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "yooDiI98VsRf",
"outputId": "f6893dba-4ac7-4294-d9f6-cf2f0341f4c1"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 2. 4. 7. 13. 19. 13. 17. 15.]\n",
"[ 9.00000000e+01+0.00000000e+00j -2.19497475e+01+1.77781746e+01j\n",
" -3.00000000e+00+1.10000000e+01j -1.20502525e+01-2.22182541e+00j\n",
" 1.25979822e-30-2.57175828e-15j -1.20502525e+01+2.22182541e+00j\n",
" -3.00000000e+00-1.10000000e+01j -2.19497475e+01-1.77781746e+01j]\n"
]
}
],
"source": [
"x = np.pad(x, (0, N-len(x)), 'constant')\n",
"h = np.pad(h, (0, N-len(h)), 'constant')\n",
"X = DFT(x,N)\n",
"H = DFT(h,N)\n",
"Y = X*H\n",
"y = np.real(IDFT(Y,N))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 2. 4. 7. 13. 19. 13. 17. 15.]\n"
]
}
],
"source": [
"x = np.pad(x,(0,N-len(x)),'constant')\n",
"h = np.pad(h, (0,N-len(h)),'constant')\n",
"X = DFT(x,N)\n",
"H = DFT(h,N)\n",
"Y = X*H\n",
"y = np.real(IDFT(Y,N))\n",
"print(y)"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
240 changes: 240 additions & 0 deletions 3-Overlap_add(25_5_23).ipynb

Large diffs are not rendered by default.

195 changes: 195 additions & 0 deletions 4-DSPL_Divide _ Conquer(1_6_23).ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "6a749398",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f8f59a71",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[4 2 3]\n",
" [2 4 8]\n",
" [0 9 0]\n",
" [5 1 2]\n",
" [7 2 3]]\n"
]
}
],
"source": [
"N = 15\n",
"L = 5\n",
"M = 3\n",
"x = np.array([4,2,0,5,7,2,4,9,1,2,3,8,0,2,3])\n",
"np.shape(x)\n",
"y = x.reshape(L,M, order='F')\n",
"print(y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7fb2cb10",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"id": "222ce56e",
"metadata": {},
"outputs": [],
"source": [
"# DFT\n",
"def DFT(x,N):\n",
" X = np.zeros(N,dtype = 'complex_')\n",
" for k in range(N):\n",
" for n in range(N):\n",
" X[k] = X[k] + x[n]*np.exp(-1j*2*np.pi*k*n/N)\n",
" return X"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "4bf3e133",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(5, 3)\n",
"[9. +0.j 1.5+0.8660254j 1.5-0.8660254j]\n",
"[14.+0.j -4.+3.46410162j -4.-3.46410162j]\n",
"[ 9. +0.j -4.5-7.79422863j -4.5+7.79422863j]\n",
"[8. +0.j 3.5+0.8660254j 3.5-0.8660254j]\n",
"[12. +0.j 4.5+0.8660254j 4.5-0.8660254j]\n"
]
}
],
"source": [
"F = np.zeros((L,M),dtype = 'complex_')\n",
"print(np.shape(F))\n",
"for l in range(L):\n",
" F[l] = DFT(y[l,:],M) #row\n",
" #np.shape(F)\n",
" print(F[l])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "37f26696",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 9. +0.j 1.5 +0.8660254j 1.5 -0.8660254j ]\n",
" [14. +0.j -2.24520477+4.79156087j -5.25085162+0.65464289j]\n",
" [ 9. +0.j -8.80332841-1.87120522j 8.22190912+3.66062979j]\n",
" [ 8. +0.j 1.90519858-3.06108124j -3.34059644-1.35661911j]\n",
" [12. +0.j 0.39090314-4.56587283j -4.2216074 +1.78270328j]]\n"
]
}
],
"source": [
"G = np.zeros((L,M),dtype = 'complex_')\n",
"for l in range(L):\n",
" for q in range(M):\n",
" G[l,q] = F[l,q] * np.exp(-1j*2*np.pi*l*q/N)\n",
"print(G)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "971059df",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[52. 8.20656829 4.95715437 4.11892682 21.16279549 8.54400375\n",
" 6.7848686 10.82658508 10.82658508 6.7848686 8.54400375 21.16279549\n",
" 4.11892682 4.95715437 8.20656829]\n"
]
}
],
"source": [
"X = np.zeros((L,M),dtype = 'complex_')\n",
"for m in range(M):\n",
" X[:,m] = DFT(G[:,m],L) #column\n",
"#print(abs(X))\n",
"Y = X.reshape(N,)\n",
"print(abs(Y))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "b563a847",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[52. 8.20656829 4.95715437 4.11892682 21.16279549 8.54400375\n",
" 6.7848686 10.82658508 10.82658508 6.7848686 8.54400375 21.16279549\n",
" 4.11892682 4.95715437 8.20656829]\n"
]
}
],
"source": [
"print(abs(np.fft.fft(x,N)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "53bef6ec",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 04f9906

Please sign in to comment.