@@ -56,6 +56,8 @@ With this in mind, we can almost directly transcribe the discrete equation into
56
56
[ import:27-46, lang:"julia"] ( code/julia/1d_convolution.jl )
57
57
{% sample lang="cs" %}
58
58
[ import:63-84, lang:"csharp"] ( code/csharp/1DConvolution.cs )
59
+ {% sample lang="py" %}
60
+ [ import:18-27, lang:"python"] ( code/python/1d_convolution.py )
59
61
{% endmethod %}
60
62
61
63
The easiest way to reason about this code is to read it as you might read a textbook.
@@ -189,6 +191,8 @@ Here it is again for clarity:
189
191
[ import:27-46, lang:"julia"] ( code/julia/1d_convolution.jl )
190
192
{% sample lang="cs" %}
191
193
[ import:63-84, lang:"csharp"] ( code/csharp/1DConvolution.cs )
194
+ {% sample lang="py" %}
195
+ [ import:18-27, lang:"python"] ( code/python/1d_convolution.py )
192
196
{% endmethod %}
193
197
194
198
Here, the main difference between the bounded and unbounded versions is that the output array size is smaller in the bounded case.
@@ -199,6 +203,8 @@ For an unbounded convolution, the function would be called with a the output arr
199
203
[ import:58-59, lang:"julia"] ( code/julia/1d_convolution.jl )
200
204
{% sample lang="cs" %}
201
205
[ import:96-97, lang:"csharp"] ( code/csharp/1DConvolution.cs )
206
+ {% sample lang="py" %}
207
+ [ import:37-38, lang:"python"] ( code/python/1d_convolution.py )
202
208
{% endmethod %}
203
209
204
210
On the other hand, the bounded call would set the output array size to simply be the length of the signal
@@ -208,6 +214,8 @@ On the other hand, the bounded call would set the output array size to simply be
208
214
[ import:61-62, lang:"julia"] ( code/julia/1d_convolution.jl )
209
215
{% sample lang="cs" %}
210
216
[ import:98-99, lang:"csharp"] ( code/csharp/1DConvolution.cs )
217
+ {% sample lang="py" %}
218
+ [ import:40-41, lang:"python"] ( code/python/1d_convolution.py )
211
219
{% endmethod %}
212
220
213
221
Finally, as we mentioned before, it is possible to center bounded convolutions by changing the location where we calculate the each point along the filter.
@@ -218,6 +226,8 @@ This can be done by modifying the following line:
218
226
[ import:35-35, lang:"julia"] ( code/julia/1d_convolution.jl )
219
227
{% sample lang="cs" %}
220
228
[ import:71-71, lang:"csharp"] ( code/csharp/1DConvolution.cs )
229
+ {% sample lang="py" %}
230
+ [ import:22-22, lang:"python"] ( code/python/1d_convolution.py )
221
231
{% endmethod %}
222
232
223
233
Here, ` j ` counts from ` i-length(filter) ` to ` i ` .
@@ -252,6 +262,8 @@ In code, this typically amounts to using some form of modulus operation, as show
252
262
[ import:4-25, lang:"julia"] ( code/julia/1d_convolution.jl )
253
263
{% sample lang="cs" %}
254
264
[ import:38-61, lang:"csharp"] ( code/csharp/1DConvolution.cs )
265
+ {% sample lang="py" %}
266
+ [ import:5-15, lang:"python"] ( code/python/1d_convolution.py )
255
267
{% endmethod %}
256
268
257
269
This is essentially the same as before, except for the modulus operations, which allow us to work on a periodic domain.
@@ -269,6 +281,8 @@ For the code associated with this chapter, we have used the convolution to gener
269
281
[ import, lang:"julia"] ( code/julia/1d_convolution.jl )
270
282
{% sample lang="cs" %}
271
283
[ import, lang:"csharp"] ( code/csharp/1DConvolution.cs )
284
+ {% sample lang="py" %}
285
+ [ import, lang:"python"] ( code/python/1d_convolution.py )
272
286
{% endmethod %}
273
287
274
288
At a test case, we have chosen to use two sawtooth functions, which should produce the following images:
0 commit comments