DirectConvolution

Documentation for DirectConvolution.

This package allows efficient computation of

\[\gamma[k] = \sum\limits_{i\in\Omega_\alpha}\alpha[i]\beta[k+\lambda i]\]

where $\alpha$ is a filter of support $\Omega_\alpha$ defined as follows (see filter of support):

\[\Omega_\alpha = \llbracket -\text{offset}(\alpha), -\text{offset}(\alpha) +\text{length}(\alpha)-1 \rrbracket\]

.

For $\lambda=-1$ you get a convolution, for $\lambda=+1$ a wiki:cross-correlation whereas using $\lambda=\pm 2^n$ is useful to implement the undecimated wavelet transform (the so called wiki:algorithme à trous).

Use cases

These demos use data stored in the data/ folder.

julia> dataDir"/juliateam/.julia/packages/DirectConvolution/tQ2NZ/src/../data"

There are one 1D signal and one 2D signal:

data_1D = readdlm(joinpath(dataDir,"signal_1.csv"),',');
data_1D_x = @view data_1D[:,1]
data_1D_y = @view data_1D[:,2]
plot(data_1D_x,data_1D_y,label="signal")
data_2D=readdlm(joinpath(dataDir,"surface.data"));
surface(data_2D,label="2D signal")

Savitzky-Golay filters

This example shows how to compute and use wiki: Savitzky-Golay filters.

Filter creation

Creates a set of Savitzky-Golay filters using polynomial of degree $3$ with a window width of $11=2\times 5+1$.

sg = SG_Filter(Float64,halfWidth=5,degree=3);
SG_Filter{Float64, 11}(DirectConvolution.LinearFilter_DefaultCentered{Float64, 11}[Filter(r=-5:5,c=[-0.08392, 0.02098, 0.1026, 0.1608, 0.1958, 0.2075, 0.1958, 0.1608, 0.1026, 0.02098, -0.08392])
, Filter(r=-5:5,c=[0.05828, -0.05711, -0.1033, -0.09771, -0.0575, -2.864e-18, 0.0575, 0.09771, 0.1033, 0.05711, -0.05828])
, Filter(r=-5:5,c=[0.03497, 0.01399, -0.002331, -0.01399, -0.02098, -0.02331, -0.02098, -0.01399, -0.002331, 0.01399, 0.03497])
, Filter(r=-5:5,c=[-0.03497, 0.006993, 0.02564, 0.02681, 0.01632, 2.404e-18, -0.01632, -0.02681, -0.02564, -0.006993, 0.03497])
])

This can be checked with

julia> length(sg)11
julia> polynomialOrder(sg)3

1D signal smoothing

Apply this filter on an unidimensional signal:

data_1D_y_smoothed = apply_SG_filter(data_1D_y,sg,derivativeOrder=0)

plot(data_1D_x,data_1D_y_smoothed,linewidth=3,label="smoothed signal")
plot!(data_1D_x,data_1D_y,label="signal")

2D signal smoothing

Create two filters, one for the I direction, the other for the J direction. Then, apply these filters on a two dimensional signal.

sg_I = SG_Filter(Float64,halfWidth=5,degree=3);
sg_J = SG_Filter(Float64,halfWidth=3,degree=3);

data_2D_smoothed = apply_SG_filter2D(data_2D,
                               sg_I,
                               sg_J,
                               derivativeOrder_I=0,
                               derivativeOrder_J=0)

surface(data_2D_smoothed,label="Smoothed 2D signal");