fft - how to find the peak(r,theta) from DFT spectrum in matlab? -
fft - how to find the peak(r,theta) from DFT spectrum in matlab? -
suppose have matrix m apply dft on , shift centre
img_fft = fft2(double(m)); img_spec = abs(img_fft); img_shift = fftshift(img_spec);
then according question, how find peak of spectrum ,i.e. (u,v) of peak? lot!
use find
determine in image maximum value occurs. however, question says ignore dc value, largest component in spectrum far. such, should find maximum value, should dc value currently, , set nan
. 1 time this, next maximum value you're searching reply question.
as such, first:
idx = find(img_shift == max(img_shift(:))); img_shift(idx) = nan;
if set maximum value here nan
, next time phone call find
, disregard location , skip location when searching maximum value. now, phone call find
again:
[u,v] = find(img_shift == max(img_shift(:)));
here, u
horizontal location of image while v
vertical position. should homecoming maximum peak not dc value. however, isn't respect centre have shifted image, 1 time you're done above, need do:
[rows, cols] = size(img_fft); u = u - floor(rows/2); v = v - floor(cols/2);
this shift origin centre of image should find maximum peak respect centre of image.
you can utilize u
, v
determine r
, theta
according question. in other words:
r = sqrt(u^2 + v^2); theta = atan2(v, u);
a little note according comment encountering 2 values share maximum. because spectrum symmetric. after find
, 2 answers. such, either reply give right result. can either take 1 of r,theta
pairs, or can modify find
statement returns one answer. in other words, this:
[u,v] = find(img_shift == max(img_shift(:)), 1);
note sec parameter of 1
@ end. means homecoming 1 result.
matlab fft spectrum
Comments
Post a Comment