Why does fsamp2 perform fftshift on output coefficients?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Sulaymon Eshkabilov
am 2 Jul. 2020
It is used to swap the right halves of your computed vector values.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!