time interval between fft1 and fft2

조회 수: 6 (최근 30일)
john
john 2011년 3월 23일
Hello to everyone,
In my program I have created two different functions to compute the 1-D and 2-D fft (Fast Fourier Transform) of an array A(4x4).Now, I want to compute the time interval regarding the time difference between the 2 routines.Does anybody knows how it must be done?
Thamks in advance
%%%%%%%%%%%Program%%%%%%%%%%%%%%%%%% % Read & plot & find spectrum of *.dat image function []=Program_3(); clc;echo off;close all; A=[30,31,12, 9, 17,12,25,10, 12, 8,17, 9, 31,12,26,22];
A=double(A);B=A; disp(A); image_depth=31;tones=8;
value =1;
switch value
case 1
B=ampl_fft(A);
case 2
B=ampl_fft2(A);
end;
max_B=max(max(B));min_B=0;B=(B-min_B)*(image_depth/(max_B-min_B));%back to image_depth
disp(round(B));
%==================================================================function [C]=ampl_fft(A) x=size(A,1);y=size(A,2); %/*-------- 2D - FFT ---------*/ %/*---------- do rows first ----------*/ C=A; for i=1:x, for j=1:y, if ( rem((i+j),2) == 1) C(i,j) = -C(i,j); else C(i,j) = C(i,j); end;%if end;%j end;%i
for i=1:x for j=1:y, Cy(j)=C(i,j); end;%j Cy=fft(Cy,y); for j=1:y, C(i,j) = Cy(j); end;%j end;%of i %/*------ do columns next---*/ for j=1:y %for each column for i=1:x Cx(i)=C(i,j); end;%i Cx=fft(Cx,x); %/*----- Compute Log Amplitude -----*/ for i=1:x C(i,j) = round(10.0 * log(1+ abs(Cx(i)) )); end;%i end;%j
%================================================================ function [C]=ampl_fft2(A) x=size(A,1);y=size(A,2);
%/*-------- 2D - FFT ---------*/ for i=1:x; for j=1:y; if ( rem((i+j),2) == 1) A(i,j) = -A(i,j); else A(i,j) =A(i,j); end;%if end;%j end;%i C=fft2(A); C=round(10.0 * log(abs(C)+1)); %==========================================

채택된 답변

Rob Graessle
Rob Graessle 2011년 3월 25일
When you say "time difference", do you mean the difference in execution time between the two routines?
tic
B=ampl_fft(A);
time1=toc;
tic
B=ampl_fft2(A);
time2=toc;
timeDifference=time2-time1; % Difference in execution time in seconds

추가 답변 (1개)

john
john 2011년 3월 25일
Now I want to form my own routine DFT employing the following formula: F(k)=sumA(k),(from 0 to N-1) where A(k)=x(n)*exp(-j*2*pi*k*n/N). I want to use it in function ampl_fft, istead of fft
I would appreciate if someone could help Thanks

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by