Inverse Fourier Transform of δ(t) but octave computes it wrong - fft

I want to inverse fourier transform of Dirac Delta function, δ(t).
So i do these:
>> syms F w t
>> F(w)=dirac(w)
F(w) = (symfun) DiracDelta(w)
>> ifourier(F(w))
ans = (sym)
1
----
2*pi
Although the right result should be like this:
Any explanation why does it compute wrong?

There are different conventions for the fourier transform This page describes some of the common ones, see also wikipedia
The convention octave is using for the Fourier transform is the standard one. In this convention the fourier transform has no constant factor in front of the integral, so requires a factor of 1 / 2π in front of the inverse (so that F ⚬ f = Id).
There are several reasons to prefer the convention you are using where the standard definition is multiplied by a constant of 1 / √2π. It's more symmetric because the inverse will have the same constant factor out the front. It also "normalizes" the fourier transform which is useful in certain contexts. But it's not the convention octave is using.

Related

Write two vectors as convolution

How to write two column vectors as an analytic convolution so that the discrete FFT may be used. MATLAB syntax is used.
Consider:
a set of vectors which, when sorted into a step function appears as any of the following:
[1,1,1,1,0,0,0,0], or [1,1,1,1,1,0,0,0], or [1,1,1,1,1,1,0,0]
(...the location at which the function "steps up" varies over members of this set)
The other is random vec=[1,0,1,0,1,1,1,0], and obviously both contain only 0s and 1s.
Is it possible to write these vectors as an analytic convolution? I would like the 1st, 2nd, 3rd, 4th... entries of the convolution to have values of:
sum(vec.*[1,0,0,0,0,0,0,0])
sum(vec.*[1,1,0,0,0,0,0,0])
sum(vec.*[1,1,1,0,0,0,0,0])
sum(vec.*[1,1,1,1,0,0,0,0])
...
sum(vec.*[1,1,1,1,1,1,1,1])
For speed, I am trying to avoid use of a for-loop. I cannot vectorize because this requires terabytes of RAM. (I work with vectors that are not of length 8, but rather length nearly a million).
The convolution theorem gives the function R from the convolution of functions L and 1/w from the Fourier transform F and its inverse F-1 as,
Clearly, the function 1/(w-w') in the convolution is from 1/w under F; it's as if you just set w'=0. But if I use analogous reasoning in my [1,1,1,1,0,0,0,0], I get either [1,1,1,1,1,1,1,1], the identity under .* in MATLAB or [0,0,0,0,0,0,0,0](a very boring result).
What is the mistake in reasoning I've made?

FFTW non-symetric inverse transform c2r

Suppose I have a real 2D matrix A(MxN), by using the FFTW3 r2c transform I take the matrix into Fourier space where B is the complex array B=fft(A(Mx(N/2+1))).
I know that B has Hermetian redundancy, so I perform some operations (left-right, up-down flips and complex conjugates) to recover the Hermetian symmetry to obtain the full complex matrix B'.
Now I perform some operations on the full complex matrix B' (such that it is no longer symmetric and want to take the inverse using c2r, how do I do this since the c2r transform is now expecting a symmetric half matrix?
Since B' is not symmetric, its inverse transform is not real. You cannot use c2r meaningfully on this matrix. Use the regular complex-to-complex inverse transform.

DM Script, why does the fourier transform of gaussian-kenel needs modulus

Recently I learn DM_Script for TEM image processing
I needed Gaussian blur process and I found one whose name is 'Gaussian Blur' in http://www.dmscripting.com/recent_updates.html
This code implements Gaussian blur algorithm by multiplying the fast fourier transform(FFT) of source image by the FFT of Gaussian-kernel image and finally doing inverse fourier transform of it.
Here is the part of the code,
// Carry out the convolution in Fourier space
compleximage fftkernelimg:=realFFT(kernelimg) (-> FFT of Gaussian-kernel image)
compleximage FFTSource:=realfft(warpimg) (-> FFT of source image)
compleximage FFTProduct:=FFTSource*fftkernelimg.modulus().sqrt()
realimage invFFT:=realIFFT(FFTProduct)
The point I want to ask is this
compleximage FFTProduct:=FFTSource*fftkernelimg.modulus().sqrt()
Why does the FFT of Gaussian-kernel need '.modulus().sqrt()' for the convolution?
It is related to the fact that the fourier transform of a Gaussian function becomes another Gaussian function?
Or It is related to a sort of limitation of discrete fourier transform?
Please answer me
Thanks
This is related to the general precision limitation of any floating point numeric computing. (see f.e. here, or more in depth here)
A rotational (real-valued) Gaussian of stand.dev. sigma should be transformed into a 100% real-values rotational Gaussioan of 1/sigma. However, doing this numerically will show you deviations: Just try the following:
number sigma = 30
number A0 = 1
realimage first := RealImage( "First", 8, 256, 256 )
first = A0 * exp( - (iradius**2/(2*sigma*sigma) ))
first.showimage()
complexImage second := FFT(first)
second.Showimage()
image nonZeroImaginaryMask = ( 0 != second.Imaginary() )
nonZeroImaginaryMask.Showimage()
nonZeroImaginaryMask.SetLimits(0,1)
When you then multiply these complex images (before back-transferring) you are introducing even more errors. By using modulus, one ensures that the forward transformed kernel is purely real and hence a better "damping" curve.
A better implementation of a FFT filtering code would actually create the FFT(Gaussian) directly with a std.dev of 1/sigma, as this is the analytically correct result. Doing a FFT of the kernel only makes sense if the kernel (or its FFT) is not analytically known.
In general: When implementing any "maths" into a program code, it can pay hugely to think it through with numerical computation limits in the back of your head. Reduce actual computation whenever possible (i.e. compute analytically and use the result instead of relying on brute force numerical computation) and try to "reshape" equations when possible, f.e. avoid large sums over many small numbers, be careful about checks against exact numeric values, try to avoid expressions which are very sensitive on small numerica errors etc.

How to find a function that fits a given set of data points in Julia?

So, I have a vector that corresponds to a given feature (same dimensionality). Is there a package in Julia that would provide a mathematical function that fits these data points, in relation to the original feature? In other words, I have x and y (both vectors) and need to find a decent mapping between the two, even if it's a highly complex one. The output of this process should be a symbolic formula that connects x and y, e.g. (:x)^3 + log(:x) - 4.2454. It's fine if it's just a polynomial approximation.
I imagine this is a walk in the park if you employ Genetic Programming, but I'd rather opt for a simpler (and faster) approach, if it's available. Thanks
Turns out the Polynomials.jl package includes the function polyfit which does Lagrange interpolation. A usage example would go:
using Polynomials # install with Pkg.add("Polynomials")
x = [1,2,3] # demo x
y = [10,12,4] # demo y
polyfit(x,y)
The last line returns:
Poly(-2.0 + 17.0x - 5.0x^2)`
which evaluates to the correct values.
The polyfit function accepts a maximal degree for the output polynomial, but defaults to using the length of the input vectors x and y minus 1. This is the same degree as the polynomial from the Lagrange formula, and since polynomials of such degree agree on the inputs only if they are identical (this is a basic theorem) - it can be certain this is the same Lagrange polynomial and in fact the only one of such a degree to have this property.
Thanks to the developers of Polynomial.jl for leaving me just to google my way to an Answer.
Take a look to MARS regression. Multi adaptive regression splines.

Calculating an integral of two numerical solutions of an ode

I would like to calculate an integral, which is determined by two functions: I(T) = ∫0T i( f(t), g(t)) dt where f and g solves ordinary differential equations and i is known.
The obvious approach would be to derive a differential equation for I and the solve it alongside f and g (which can be done, but is numerically expensive in my case). In my case, however, f solves an equation with an initial condition f(0) and g and equation with a final condition g(T).
My best guess at the moment would be to solve f and g on a grid using a standard ODE solver and then use a standard method for numerical integration with equally spaced t-coordinates or some kind of quadrature rule (basically anything described by Numerical Recipes).
Does anyone have a better solution? That is, a method that takes the specific type of ode solver and its accuracy into account.
Many advanced ODE solvers come with a feature called "dense output". The ODE solver gives you not only the values of f and g on a grid (as specified beforehand), but allows you to use its result to find the values at any time. Combining this with an adaptive quadrature rule should give you an answer to whatever precision you need.