Why does fsamp2 perform fftshift on output coefficients?

조회 수: 4 (최근 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개)

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by