Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how fast fourier transform in my ocde?

Subject: how fast fourier transform in my ocde?

From: ghasem

Date: 24 Apr, 2013 06:11:10

Message: 1 of 7

Hi.
I wrote a code,that in one section from this code,I have to calculate fourier transforms .now I want to fast it's operation,as possible as.
fourier transform section in my code is as following:

for n = 1: 10000
% other sections of my code that not written.
% auxiliary quantities for fourier transfrom:
% note: dt ,li,ui,uj,jk,ik,lj are constant.Hx and Hy is pre-determined 3d arrays.

aux_A (1,:,1,:) = 0.25*(Hx(li:ui-1 , uj , lk:uk-1) + Hx(li:ui-1 , uj , lk+1:uk) ...
                        + Hx (li:ui-1 , uj-1 , lk:uk-1) + Hx (li:ui-1 , uj-1 , lk+1:uk));
aux_B(1,:,:,1) =-0.25*(Hy(li:ui-1 , lj:uj-1 , uk)+Hy(li:ui-1 , lj+1:uj , uk) ...
                         + Hy (li:ui-1 , lj:uj-1 , uk-1) + Hy (li:ui-1 , lj+1:uj , uk-1));
...
% now : fourier transform:
for i=1: 400
    exp_h = dt * exp(-j*f(i)*(n-0.5)*dt);
    A (i,:,:,:) = A (i,:,:,:) + exp_h * aux_A(1,:,:,:);
    B(i,:,:,:) = B(i,:,:,:) + exp_h * aux_B(1,:,:,:);
    .
    .
    .
% for 23 other quantity like as A,B this operation must be done.
end

So this section is very time consuming in my code.because this section in within a time-loop (n=1:0000).
how can I fast this calculations as possible as?because this section is very time consuming and therefore my total program become very slow...
please help me..
ghasem

Subject: how fast fourier transform in my ocde?

From: Nasser M. Abbasi

Date: 24 Apr, 2013 06:17:53

Message: 2 of 7

On 4/24/2013 1:11 AM, ghasem wrote:
> Hi.
> I wrote a code,that in one section from this code,I have to calculate fourier transforms
..
> please help me..


try fft, it should be faster than your code

Subject: how fast fourier transform in my ocde?

From: ghasem

Date: 24 Apr, 2013 06:52:11

Message: 3 of 7

> try fft, it should be faster than your code
==========================
i.e,I have to use from:
A = fftn(A) ?
so,how implement second terms in my code?
for example,in calculation of A(i,:,:,:) , second term in the right hand side, is changed in each time.
because array of "aux_A" and exp_h (that is a complex constant) change in new calculation of A.
fftn =(A) how work?

Subject: how fast fourier transform in my ocde?

From: Nasser M. Abbasi

Date: 24 Apr, 2013 06:58:25

Message: 4 of 7

On 4/24/2013 1:52 AM, ghasem wrote:
>> try fft, it should be faster than your code
> ==========================
> i.e,I have to use from:
> A = fftn(A) ?
> so,how implement second terms in my code?
> for example,in calculation of A(i,:,:,:) , second term in the right hand side, is changed in each time.
> because array of "aux_A" and exp_h (that is a complex constant) change in new calculation of A.
> fftn =(A) how work?
>

Your code is too advanced for me to understand, follow and recommend any
changes to it.

I can only suggest you try to use fft instead of implementing DFT yourself.
Matlab built-in function will always be faster than your m code user level
implementation.

--Nasser

Subject: how fast fourier transform in my ocde?

From: ghasem

Date: 24 Apr, 2013 07:19:09

Message: 5 of 7

thank you very much...
I will try and tell the answer,later.
ghasem

Subject: how fast fourier transform in my ocde?

From: ghasem

Date: 24 Apr, 2013 11:35:09

Message: 6 of 7

is there anyone who know that how can I use from " nfft " library in MATLAB?

Subject: how speed up my 3d fourier transform?

From: ghasem

Date: 24 Apr, 2013 17:05:09

Message: 7 of 7

please help me.
I have several 4 dimensional arrays in space-time domain (named as : aux_a,aux_b,...).
in each of them,forth dimension is time and three other dimensions are spatial coordinates.
I want to calculate their DFT for a given frequency interval .but I don't know how implement fftn or faster method in this case.
I wrote following code:
======================
n = 10000; % number of time steps.
dt = 5e-3;
freq = (50:5:300);
% aux_a,b are a predetermined 4d arrays in space-time domain
% [ you suppose aux_a,b =rand(3,4,5,n) ,...]
a = zeros(3,4,5,length(freq));
b = zeros(3,4,5,length(freq));
...
for m = 1:n
    for k = 1:length(freq)
        exp_h = exp(-1j * freq( k )* m * dt);
        a(:,:,:,f) = a(:,:,:,f) + exp_h * aux_a(:,:,:,m);
        b(:,:,:,f) = b(:,:,:,f) + exp_h * aux_b(:,:,:,m);
        ...
    end
end
======================
now suppose I have 22 other 4 dimensional arrays like as b and c in above.and I have to calculate their fourier transform like as above.
this code is very slow.I want to use from fftn or a better method.
but I don't know how implement fftn for this problem.
is there anyone who help me?
thanks...

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us