# Convolution (conv) with same size output

**URL:** https://discourse.julialang.org/t/convolution-conv-with-same-size-output/38260
**Category:** General Usage
**Tags:** dsp
**Created:** [April 26, 2020, 8:12pm UTC](https://discourse.julialang.org/t/convolution-conv-with-same-size-output/38260 "2020-04-26T20:12:05Z")
**Posts on this page:** 1
**Page:** 2

<div class="post-metadata">

### Author: ![Mouhamed](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Mouhamed](https://discourse.julialang.org/u/Mouhamed)
#### Post date: [August 14, 2024, 1:33pm UTC](https://discourse.julialang.org/t/convolution-conv-with-same-size-output/38260/21 "2024-08-14T13:33:58Z")

</div>

You can apply the following function to the result of DSP.conv() in order to mimic the behaviour of the parameter “save” from scipy.stats.fftconvolve and center the result of the convolution.

```julia
function centered(arr, input_arr_shape)
    # new_arr_shape is the size of the input array during convolution with DSP.conv(input_arr1, input_arr2)
    # Get the current shape of the array i.e. the result of DSP.conv()
    currshape = size(arr)
    
    # Calculate start and end indices for slicing
    startind = (currshape .- input_arr_shape) .÷ 2 .+ 1
    endind = startind .+ input_arr_shape .- 1
    
    # Create the slice objects
    slices = Tuple(startind[i]:endind[i] for i in 1:length(endind))
    
    # Return the centered portion of the array
    return arr[slices...]
end

```

[Previous page](https://discourse.julialang.org/t/convolution-conv-with-same-size-output/38260.md?page=1)
