Why does fsamp2 perform fftshift on output coefficients?

1 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by