# matlab | 离散傅里叶变换一阶、二阶

◆ ◆ ◆ ◆ ◆

`For length N input vector x, the DFT is a length N vector X,%   with elements%                    N%      X(k) =       sum  x(n)*exp(-j*2*pi*(k-1)*(n-1)/N), 1 <= k <= N.%                   n=1%   The inverse DFT (computed by IFFT) is given by%                    N%      x(n) = (1/N) sum  X(k)*exp( j*2*pi*(k-1)*(n-1)/N), 1 <= n <= N.%                   k=1`

dft的直接实现

```function [F] = dft_chg(img_data)img_data=im2double(img_data);sz=size(img_data);F=zeros(sz);M=sz(1);m=0:M-1;T=1;if numel(sz)>2    T=sz(3);end
for tunnel=1:T    for column=1:sz(1)        column_data=img_data(:,column,tunnel);        part1=exp(-1i*2*pi/M);        ux=m'*m;        part2=part1.^ux;        F(:,column,tunnel)=column_data'*part2;    endendend```

◆ ◆ ◆ ◆ ◆

```function [F] = dft2_chg(img_data)img_data=im2double(img_data);sz=size(img_data);M=sz(1);N=sz(2);n=0:N-1;m=0:M-1;T=1;if numel(sz)>2    T=sz(3);endF=zeros(sz);new_data=zeros(sz);
for tunnel=1:T    for column=1:sz(1)        column_data=img_data(:,column,tunnel);        part1=exp(-1i*2*pi/M);        ux=m'*m;        part2=part1.^ux;        new_data(:,column,tunnel)=column_data'*part2;    endend
for tunnel=1:T    for row=1:sz(2)        row_data=new_data(row,:,tunnel);        part1=exp(-1i*2*pi/N);        vy=n'*n;        part2=part1.^vy;        F(row,:,tunnel)=row_data*part2;    endendend```

`function [] = show_in_img(F)%SHOW_IMG 此处显示有关此函数的摘要%   此处显示详细说明F=fftshift(F);f=abs(F);f=log(f);fai=angle(F);T=1;sz=size(F);if numel(sz)>2    T=sz(3);endfigure("Name","离散变换","NumberTitle","off");for zone=1:T    zone1=subplot(2,T,zone);    imshow(f(:,:,zone));    title(zone1,"幅度图");    zone2=subplot(2,T,T+zone);    imshow(fai(:,:,zone));    title(zone2,"相位图");endend`

45 篇文章27 人订阅

0 条评论