Fortran FFTW with strides ''Matlab-like'' - fortran

I am a newbie in fortran, and trying to transform my matlab code efficiently to .f
I am using the fftw3 package and need ffts with strides complex to complex. e.g. 2 dimensions out of 3d array should be transformed.
What I do in matlab is
fft(fft(u,[],2),[],3)
where u(Nx,Ny,Nz) is 3d matrix.
I can do this in fortran via looping but this is much slower than matlabs ffts as in below;
call dfftw_plan_dft_2d(planf,Nx,Nz,inf,outf,FFTW_FORWARD,FFTW_MEASURE)
do l=1,Nx;
call dfftw_execute_dft_(planf,f(l,:,:),fh(l,:,:));
end do
fft_many is a solution to my problem where strides can be used, however I couldn't get it to work somehow. Could anyone help?
This link is actually the 'C' help of fftw's advanced complex ffts;

Related

Proper way to do a 2D deconvolution, assuming no noise (just a convolution has been applied to the input)

I would like to be able to do a convolution on an matrix, save the kernel, and then be able to use the output of the convolution to do a deconvolution with the output of the convolution and the kernel to get the original matrix. I am stuck on the deconvolution function, as most of the cases I have found on the internet have either been for matlab or python, and I am using c++. In addition, the cases online are for bigger images, where I am not even going to have images at all, just matrices. Also, most of those cases, because they are for image processing, are assuming noise will be builtin to the original image. As I am using matrices and just a convolution (not adding noise), this won't apply. I have found the correct formula for a deconvolution, but it is kind of over my head as I am not that skilled in advanced math. I would appreciate any help, even just basic pseudocode.
I have tried looking at libraries on the internet, and what I have found is either in matlab, using a lot of libraries (which I don't have in c++), or python, again, using libraries I don't have in c++. They also apply to larger images, whereas in my case the matrices will be smaller. This means a more brute force approach will be ok because the inputs will never be more than 10x10 integers.

Exact condition number of sparse matrix from Eigen

I have a really large sparse matrix encoded in Eigen in C++ and I need the exact condition number.
Eigen does not have functionality for this.
Someone I know said I should export the matrix and read it with matlab, except I don;t have a matlab license and I would not know how to export it.
I am thinking of using octave or julia instead. All I really need is the condition number somehow with the minimum amount of custom code possible.

Equivalent fftw code in C++ with fft(A,[],1) of Matlab

I have a two dimensional matrix in both C++ and MATLAB. I want to apply just the one dimensional fft, along to one direction like in the following picture.
This is trivial in MATLAB and it can be done by the following format. I was wondering if it is possible to do the same fft transform in C++ with the fftw library.
I know that it can be done with a for loop, along the desired direction, but if it can be done with one command it would be great.
Thanks for your help.

reproducing a tensor matrix with eigen library

I'm facing a little problem. I'm translating a program from matlab/octave to C++. This progam is dealing with some matrix manipulation. I want to reproduce this : in matlab/octave we can define a matrix like :
matrix = zeros(10,25,360);
and I get a matrix with 10 rows, 25 columns and a "depth" of 360. I want to reproduce the same thing in C++ using Eigen.
Thank you in advance for your help.
There are unsupported Modules for Eigen which let you define tensors. With those modules you can translate your problem into C++.
The current Eigen tensor module is extremely limited feature wise. You can't even add the coefficients of 2 tensors together! I have been using the tensor code in this fork of Eigen instead. It adds support for coefficient wise operations, convolutions, contractions, and recently morphing primitives such as slicing. Moreover it can take advantage of GPUs to speed things up which was the big selling point for me.
There is a pending pull request so hopefully it will make its way into the main Eigen code base soon.

C++ library for signal processing

I wrote a research project in matlab that uses quite a few functions which I do not want to re-implement in C++, so I'm looking for libraries to handle these for me. The functions I need are: (by order of importance)
Hilbert transform
Matrix functions(determinant, inverse, multiplication...)
Finding roots of polynomials(for degrees greater than 5)
FFT
Convolutions
correlation(xcorr in matlab)
I don't know about most of those, but FFTW is the 'fastest Fourier transform in the West'. It is used in the MATLAB implementation of fft().
Once you've got an FFT you can knock off everything save for numbers 2. and 3.
The linear algebra requirement can be met with PETSc www.mcs.anl.gov/petsc/ which supports fftw.
I don't know how you're going to go about the root finding. You'll probably have to code that yourself (bisection, Newton's method etc etc.) but it's the easiest thing on the list to implement by far.
I am not sure about the libraries that are available for use, but if you already have the functions written in matlab there is another option.
If you compile the matlab functions to a dll they can be called by a c++ program. This would allow you to access the matlab functions that you already have without rewriting.