Why does fsamp2 perform fftshift on output coefficients?

1 回表示 (過去 30 日間)
skykeithtr
skykeithtr 2020 年 7 月 2 日
編集済み: skykeithtr 2020 年 7 月 2 日
Why does matlab internal function fsamp2 perform fftshift on the output filter coefficients? After swapped, the output cannot be a direct input to filter2 function, right?
Following are an example and the concerned part of codes in fsamp2.m.
% For example, to create a low-pass filter LPF with frequency response Hd
[f1,f2] = freqspace(25,'meshgrid');
Hd = zeros(25,25); d = sqrt(f1.^2 + f2.^2) < 0.5; % (cutoff at 0.5)
Hd(d) = 1;
% Here's my thought of creating a filter:
LPF = fftshift(Hd); % convolution kernel
LPF = rot90(LPF,2); % correlationn kernel
signal_filtered = filter2(LPF,signal);
% But if I use fsamp2:
h = fsamp2(Hd);
% According to the fsamp2 function below (mainly the line commented with "QUESTION"),
% h is not the same with LPF and cannot be a direct input to filter2 function.
% However, h can be used with freqz2(h) directly because freqz2 swaps h back.
function h = fsamp2(f1,f2,hd,siz)
if nargin==1, % Uniform spacing case (fast)
hd = f1;
hd = rot90(fftshift(rot90(hd,2)),2); % Inverse fftshift
h = fftshift(ifft2(hd)); % QUESTION: ifft2(hd) already outputs the desired coefficients, why use fftshift then?
elseif nargin==2 || nargin==3,
% etc...
else
% etc...
end
% etc
h = rot90(h,2); % Rotate for use with filter2
end % end function
  2 件のコメント
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020 年 7 月 2 日
It is used to swap the right halves of your computed vector values.
skykeithtr
skykeithtr 2020 年 7 月 2 日
Yes, but I just can't see why it needs to be swapped. I have edited the question to discuss whether it would be an appropriate input to other functions like filter2 and imfilter.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by