You can use ARRAYFUNC to speedup a loop execution on GPU. Referring to the following link might be of some use to you:
gfor function with matlab 2013b
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I was using jacket with matlab but the old system was upgraded to win7 and new matlab 2013b is installed.
However, jacket is now discontinued but I don't see the same functionality "gfor" with matlab 2013b which is quite disappointing.
I was using gfor for windowed Fourier transform (wft) computation as attached below, can anyone give me some hind on how to get the "gfor" functionality back? Thank you very much!
function g=gwft(type,f,sigmax,wxl,wxi,wxh,thr)
%the purpose is to make the wff faster by choosing smaller window size
%which does not affect its accuracy.
if strcmp(type,'wff')
%half window size along x, by default 2*sigmax; window size: 2*sx+1
sx=round(2*sigmax);
elseif strcmp(type,'wfr')
%half window size along x, by default 3*sigmax; window size: 2*sx+1
sx=round(3*sigmax);
end
%array size
m =length(f);
%expanded size:
mm=m+2*sx;
%pre-compute the spectrum of f to size [mm] on GPU;
%--- f is assumed gdouble ---%
Ff=fft(f,mm);
%1D index for window on GPU
x=gdouble((-sx:sx)');
%generate a window w0 on GPU
w0=gdouble(exp(-x.*x/2/sigmax/sigmax));
%normalization of window w0 on GPU
w0=w0/sqrt(sum(w0));
%config WFT basis on GPU
wxt=gdouble(wxl:wxi:wxh);
if strcmp(type,'wff')
thr=gdouble(thr);
g.filtered=gzeros(m,length(wxt));
gfor k=1:length(wxt)
%WFT basis
w=w0.*exp(1i*wxt(k)*x);
%spectrum of w to size [mm]
Fw=fft(w,mm);
%implement of WFT: conv2(f,w)=ifft2(Ff.*Fw);
sf=ifft(Ff.*Fw);
%cut to get desired data size
sf=sf(1+sx:m+sx);
%threshold the spectrum
sf=sf.*(abs(sf)>=thr);
%implement of IWFT to size [mm]: conv2(sf,w);
gtemp=ifft(fft(sf,mm).*Fw);
%update
g.filtered(:,k)=g.filtered(:,k)+gtemp(1+sx:m+sx);
gend
%summation along the length of wxt so convert to 1D
g.filtered=sum(g.filtered,2);
%scale the data
g.filtered=g.filtered/2/pi*wxi;
% return to Matlab workspace
g.filtered=double(g.filtered);
elseif strcmp(type,'wfr')
g.wx=zeros(m,1); g.phase=zeros(m,1); g.r=zeros(m,1);
gfor wxt=wxl:wxi:wxh
%WFT basis
w=w0.*exp(1i*wxt*x);
%spectrum of w to size mm
Fw=fft(w,mm);
%implement of WFT: conv2(f,w)=ifft2(Ff*Fw);
sf=ifft(Ff.*Fw);
%cut to get desired data size
sf=sf(1+sx:m+sx);
%indicate where to update
t=(abs(sf)>g.r);
%update r
g.r=g.r.*(1-t)+abs(sf).*t;
%update wx
g.wx=g.wx.*(1-t)+wxt*t;
%update phase
g.phase=g.phase.*(1-t)+angle(sf).*t;
gend
g.phase=double(g.phase);
end
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!