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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!