16

$Version (* "8.0 for Microsoft Windows (64-bit) (October 7, 2011)" *) Direct attack fails: Timing[Convolve[Sinc[x], Exp[-x^2], x, y]] (* Out[218]= {59.296, Convolve[Sinc[x], E^-x^2, x, y]} *) or, equivalently, Timing[Integrate[Sinc[x] Exp[-(x - y)^2], {x, -∞, ∞}] ] $\left\{49.92,\int_{-\infty }^{\infty } e^{-(x-y)^2} \text{Sinc}[x] \, dx\right\}$ ...


14

Here I implemented three different versions of Gaussian filtering (for periodic data). It took me a while to adjust the constants and still some of them might be wrong. Prepare the Gaussian kernel n = 200000; σ = .1; t = Subdivide[-1. Pi, 1. Pi, n - 1]; ker = 1/Sqrt[2 Pi]/ σ Exp[-(t/σ)^2/2]; ker = Join[ker[[Quotient[n,2] + 1 ;;]], ker[[;; Quotient[n,2]]]]; ...


12

As mentioned in a comment by ciao, blind deconvolution is no easy task. However, here are some pointers for estimating the kernel parameters. These can equally be applied to denoising an image rather than deblurring. I am assuming that the form of the kernel is known here, rather than blind deconvolution (Wikipedia) methods such as Maximum A Posteriori (...


12

While it's tempting to attribute the errors you're observing to floating-point errors due to zeros in the DFT of the window, this is actually not the case here: Window[width_, x_] := UnitStep[x + width/2] UnitStep[width/2 - x]; Test[x_] := UnitStep[x] UnitStep[count - x] Sin[1/10 x]^2; tempWindow = Table[Window[20, x], {x, -count/2, count/2}]; {Min[Abs[...


10

In this case, the following works just fine: LeastSquares[ Transpose@Through[{RotateLeft, Identity, RotateRight}[data1]], conv ] {0.333333, 0.333333, 0.333333} More general with kernel length 2 k + 1: a = RandomReal[{-1, 1}, 100]; k = 20; ker = RandomReal[{-1, 1}, 2 k + 1]; b = ListConvolve[ker, a, k + 1]; ker1 = LeastSquares[ Transpose[...


9

Unfortunately, MXNet does not support 3D convolutions with dilations yet. This can be seen in the MXNet source for convolution.


9

Consider the following code f[n_, p_] := n^p g[n_, p_] := n*p DirichletConvolve[f[n, p], g[n, p], n, 4] First, we define two functions f and g. Then we compute their Dirichlet convolution. The third argument in the Dirichlet convolution tells us that n is the function argument for which we want to do the convolution. p on the other hand is a parameter ...


8

I think you are trying to do the following: Clear[h]; h[n_] /; n >= 1 := -((I^-n (-1 + I^n)^2)/(n^2 Pi^2)) h[0] = 1/4; Clear[y]; y[m_] := DiscreteConvolve[h[n], DiscreteDelta[n], n, m] y[0] (* ==> 1/4 *) Here corrected your definition of y so it uses m as the function argument, but the important part is to understand why even with this ...


8

That does not explain why your solution does not work (I'm pretty sure it is because of your definition of stripe), but if you replace stripe with: stripe[x_, d_] := HeavisidePi[Mod[x/(2 d), 1]] you get: conv[x_] = Convolve[UnitStep[tau + 5] stripe[tau, 1] UnitStep[5 - tau], gaussian[tau, 0, 0.5], tau, x] (* -0.5 (1. Erf[2.82843 - 1.41421 x] + 1. ...


8

Not sure if I've guessed definition of conv2 accurately, but the following does reproduce the output of MATLAB. (Tested in Octave. ) conv2[A_?NumericQ, B_] := conv2[{{A}}, B] conv2[A_?VectorQ, B_] := conv2[{A}, B] conv2[A_, B_] := ListConvolve[A, B, {1, -1}, 0] filter = 1; F = conv2[{1, 2, 1}, List /@ {1, 2, 1}]/16.; Nest[conv2[#, F] &, filter, 3] For ...


8

The answer is that you are asking too much of deconvolution. The following code shows images blurred and refocused with different degrees of blurring. Do[blur = ImageConvolve[im, GaussianMatrix[n]]; focused = ImageDeconvolve[blur, GaussianMatrix[n]]; CellPrint[{blur, focused}], {n, 2, 6, 2}] Radius 2 blurred Radius 2 refocused Radius 4 blurred ...


7

I wasn't sure how to set it up with the standard fit functions, so I just rolled my own least squares. (It probably can be done, but I had an inkling I might want to have greater control over the computation. I hope it helps.) I start by defining m1 and m2 on your data: Clear[m1, m2]; (m1[t_] /; t == First@# = Last@#) & /@ m1data; (m2[t_] /; t == ...


7

We consider h = Exp[g]. The main idea is to calculate the Fourier transform of h, expand it into a series in powers of v, and then transform back Here we go. The normal distribution is explicitly f = 1/(v Sqrt[2 \[Pi]]) Exp[-(x - z)^2/(2 v^2)]; Now the Fourier transformation of h acts only on f, with the result ft = FourierTransform[f, x, t, ...


7

Related to your question: If you wish to do general cross-correlation (not with a fixed lag of 1), you can use the following functions: xcorrlag[dat1_, dat2_] := Position[#, Max@#] &[xcorr[dat1, dat2]] - Length[dat1] xcorr[dat1_, dat2_] := ListCorrelate[dat1, dat2, {-1, 1}, 0] xcorr[dat_] := xcorr[dat, dat] Here, xcorr called with a single Listas an ...


7

It seems, that MMA can't do that integral analytically (working with Version 8.0). Also Convolvedidn't do the job. Do it numerically. By the way, don't use v', because it is interpreted as Derivative and regard, the correct definition is gl[v - vs, v0, Lw], not vs-v. gd[v_, v0_, Dw_] = Sqrt[(4*Log[2]/Pi)]*(1/Dw)*Exp[-4*Log[2]*((v - v0)/Dw)^2]; gl[v_, ...


7

Let's focus on the part that is giving you trouble: the term $\sum_{k=0}^{m-1}k^t(m-k)^t$, which is written in code as: Sum[k^t (m - k)^t, {k, 0, m - 1}] For example, with m=30, you get: Your stated goal is to express this in term of a discrete convolution. Here's one way to do that. Let kt = Range[0, 30]^t; be one of the signals. Then the sum is ...


7

It's hard to know for sure, but one way to test for caching is to apply a single command to lots of data sets, or to apply the command separately to each set. For instance: n = 5000; data = RandomReal[{-1, 1}, {n, 10000}]; GaussianFilter[#, 100] & /@ data; // AbsoluteTiming Do[GaussianFilter[data[[i]], 100], {i, n}] // AbsoluteTiming Do[GaussianFilter[...


7

(*Defining Tent Funtion*) Tri[x_, wT_] := Piecewise[{ {(1/wT^2)*x + (1/wT), 0 > x > -wT}, {-(1/wT^2)*x + (1/wT), 0 < x < wT}}]; (*Defining Top Hat Funtion*) Hat[x_, wH_] := Piecewise[{ {(1/(2*wH)), 0 > x > -wH}, {(1/(2*wH)), 0 < x < wH}}]; (*Plotting& Manipulate Function*) Manipulate[ s1 = Switch[fx, "Tent ...


6

You can do the cross-correlation between two sequences using ListCorrelate a = {1, 2, 3, 4, 5}; b = {5, 4, 3, 2, 1}; ListCorrelate[a, b, 1] This does circular correlation, so you may want to look at the options to get the exact calculation you are looking for.


6

(1) Convolution with Plus and Times can be done via FFT. (2) The overall speed complexity cannot be less than the size-of-result complexity. Point (1) might help to explain why the standard ListConvolve is fast under most circumstances. Point (2) on the examples in this post should help to explain why LC2 is likely to be slow. To make this clear we can ...


6

Automatic is not the same as "Varying". Example 1 This works: conv1 = NetInitialize@ConvolutionLayer[3, 2, "Input" -> {3, Automatic, Automatic}]; conv1@NetEncoder[{"Image", {128, 128}}]@RandomImage[1, {128, 128}, ColorSpace -> "RGB"] This doesn't work at the stage of layer creation: conv2 = NetInitialize@ConvolutionLayer[3, 2, "Input" -> {3, "...


6

First, you need to define the convolution of the two functions. Then plot it: con[y_] := Convolve[HeavisidePi[x], HeavisidePi[x], x, y]; Manipulate[Show[Plot[HeavisidePi[y], {y, -3, 3}, Exclusions -> None, Filling -> Bottom], Plot[HeavisidePi[x - t], {x, -3, 3}, Exclusions -> None, PlotStyle -> Green, Filling -> Bottom], Plot[...


5

... 3 years later at least for 2D problems: ImageCorrelate[pData//Image, krData, CosineDistance]//ImageData


5

This is a bug in DiscreteConvolve[]. The bug is caused by a missing condition (m>=0) in one term of the answer returned by DiscreteConvolve[] for your example. A workaround for the problem is to apply PiecewiseExpand[] to the first two arguments of DiscreteConvolve[] as shown below. h = (1/2)^n UnitStep[n] - 3*(1/2)^(n - 1) UnitStep[n - 1]; g = 3^n ...


5

As Michael notes, deleting the stray brackets will make it work. A better method, however, would be to use SolveAlways[]: F[n_, x_] := Sum[f[n, j]x^j, {j, 0, n}]/n! SolveAlways[Table[Series[F[n, x + y], {x, 0, n}, {y, 0, n}] == Series[Sum[F[k, x]F[n - k, y], {k, 0, n}], {x, 0, n}, {y, 0, n}], {n, 0, 4}], {x, y}][[1]] {...


5

With x and d not numeric: If[EvenQ[Quotient[x, d]], 1, 0] (* 0 *) The essential difficulty is using programming constructs If and EvenQ to formulate a symbolic analysis problem.


5

This is a bit roundabout but one can treat this as a polynomial algebra problem. First pad both ends of data and convolution result with zeros so that the convolution emulates polynomial multiplication. Then do a division to get the kernel as a polynomial. data1 = {0., 0., 1., 2., 1., 2., 1., 0., 0., 0.}; ker = {1/3, 1/3, 1/3}; conv = ListConvolve[ker, ...


5

Define a Gaussian kernel. The width is specified by s kernel = #2 Exp[-(t - #1)^2/(2 s^2)] &; Define a function to compute the correlation in terms of the convolution correlate[x_, y_, t, T_] := Convolve[x, y /. t -> -t, t, T] Test this by correlating two kernels at different times correlate[kernel[t1, 1], kernel[t2, 1], t, T] (* (E^(-((T - t1 + t2)...


4

Here is another way that allows you to directly use Convolve: Convolve[TrigToExp@FunctionExpand[Sinc[x]], Exp[-x^2], x, X] (* ==> -(1/2) E^-X^2 Pi Erfc[1/2 - I X] - 1/2 E^-X^2 Pi Erfc[1/2 + I X] *) In order to get a successful evaluation, I just had to break up the Sinc function into its complex exponential terms.


Only top voted, non community-wiki answers of a minimum length are eligible