low-pass exponential filter - fourier space

Hello,
I am a beginner in Matlab and I have to understand a code. The part I don't understand is to calculate filter for displacement datas (in Fourier space) (low-pass exponential filter).
qmax=nr2/(pi*min_feature_size); %min_feature_size: spatial resolution of the stress measurement in units of the grid spacing.
%nr2=number of rows and columns across field (must be square)
% Get distance from of a grid point from the centre of the array
y=repmat((1:nr2)'-nr2/2,1,nr2);
x=y';
q=sqrt(x.^2+y.^2);
% Make the filter
qmsk=exp(-(q./qmax).^2);
qmsk=ifftshift(qmsk)
I have difficutlies understanding what he is doing exactly...what is the iffshift for? and what is this filter doing excalty
Thank you for your help Aude

 Accepted Answer

Hi Aude, To construct a filter in this situation it's convenient to use a frequency array with zero frequency in the center. In one dimension the lowpass filter might look like
f = -50:49; y = exp(-f.^2/100); plot(f,y)
(it's more properly called a gaussian than an exponential). But to do an fft or an ifft, Matlab wants zero frequency at the beginning of the array, not the middle. The ifftshift function swaps halves of the y array to put zero frequency at the beginning. So
ff = 0:99; plot(ff,ifftshift(y))
puts the center of the gaussian down at zero frequency, and the negative frequency part of the gaussian into the upper half of the frequency array. Your code does the same in two dimensions.

6 Comments

Thank you David for your reply!! I helped me a lot.
I read about gaussian filter that they are defined by : h(x,y)=(1/sqrt(2*pi)*σ) * exp(-(x2+y2)^2/2*(σ)^2
Why in my case I don't have the part : (1/sqrt(2*pi)*σ) before the exponential? and what is σ exaclty? Is it, like in the example you give for 1D, the number of frequencies values (100)?
In the case of my code, is it qmax=nr2/(pi*min_feature_size) ? I am not sure of what qmax represents, the number of rows and columns across field divided by (pi*the spatial resolution of the stress measurement)
Thank you again
Hi Aude, Since these questions are not really about Matlab per se I will have to keep this comment fairly short. For more information on fourier transforms in general, there are signal processing discussion groups such as dsp.stackexchange, and of course Mathworks is still the site for Matlab questions. [1] Sigma sets the width of the gaussian function. Try plotting the gaussian with some different values of sigma to see what happens. The fact that 2*sigma^2 = 100 was in the gaussian example I used, and the fact that there were 100 frequencies is a coincidence. [2] The factor before the exponential is a normalizing factor so that if you integrate the gaussian from minus infinity to infinity, you get 1. I don't know why they did not include that factor. [3] Your last comment is related to fourier transform behavior. As the amount of required detail (min_feature_size) in the spacial image gets smaller, the "spacial frequencies" q <= qmax you need to describe it get larger, in inverse proportion. qmax is the highest q value you will see after you do the transform (or possibly qmax times some factor not far from 1, depending on how they do the transform).
Ok David thank you very much for your answer, it is clearer now.
Hi Aude, looking at my previous comment, I didn't mean to imply that the Mathworks site is strictly for 100% Matlab procedural questions. Sometimes good questions come up about what Matlab is doing in a piece of code. It's just a case of striking the right balance of what is related to Matlab and what is independent of it.
Aude Rapet
Aude Rapet on 4 Nov 2016
Edited: Aude Rapet on 4 Nov 2016
Yes I understand.
I just have another question, are you sure is it a gaussian low-pass filter? As there isn't the normalizing factor (1/sqrt(2*pi)*σ), and neither the Sigma which set the width of the gaussian function...?
As they just do : qmsk=exp(-(q./qmax).^2)
Is is possible to "create" a filter like this? I mean without using a known one like Gaussian, Butterworth,...
I do understand that the goal of a low-pass filter but I am confused with the one of my code... Thank you!
It is a gaussian filter, because you can write it as exp( -(q.^2) / (qmax^2) ). Then if you define sigma in terms of qmax with the expression 2*sigma^2 = qmax^2, you get same formula for a gaussian as in one of your earlier comments. Except for the normalizing factor in front. Again, I don't know why the are not using that.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!