Help Me Solve FFT Sinc Function Problem

  • Thread starter Thread starter Jmas
  • Start date Start date
  • Tags Tags
    Fft Function
Click For Summary

Discussion Overview

The discussion revolves around a physics engineering student's challenge with implementing a Fast Fourier Transform (FFT) in MATLAB to obtain a sinc function from a square function. The focus is on the technical aspects of the code, the expected output, and the interpretation of the resulting plots.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes their code and the expected output, which is a sinc function derived from a square function.
  • Another participant requests clarification on the code's intended functionality.
  • A participant questions the nature of the second plot, suggesting that it appears to be a one-dimensional power spectrum rather than a two-dimensional FFT.
  • There is a disagreement regarding the dimensionality of the FFT being performed, with one participant asserting that the FFT function only operates on the first non-singleton dimension and suggesting the use of fft2 instead.
  • A participant inquires about centering the output of the FFT.
  • Another participant proposes a method to center the output by rotating the rows and columns of the resulting matrix.

Areas of Agreement / Disagreement

Participants express differing views on the dimensionality of the FFT and the interpretation of the resulting plots. There is no consensus on the correct approach to achieve the desired output.

Contextual Notes

Some participants note potential limitations in the understanding of the FFT function's behavior in MATLAB, particularly regarding its application to two-dimensional data.

Jmas
Messages
5
Reaction score
0
Hello, I am a physics engineering student and i need a little help with fft function. I wrote the following code everything works, but when i get the fft. I was supose to obtain a sinc function and if you take a close look, it is a sinc, but in the wrong points, can anyone help me with this?

if you don't know/remember what a sinc function looks like:
https://www.google.pt/search?q=3d+s...%2Fwiki%2FFile%3AMatlab_surf_sinc.svg;561;420

x0=0;
y0=0;
dx=5;
dy=5;
px=0.05;
py=0.05;
dxx=1;
dyy=1;
n=dx/px+1;
m=dy/py+1;

xx=-dx/2:px:dx/2;
yy=-dy/2:py:dy/2;

[X,Y]=meshgrid(xx,yy);

Z=zeros(n,m);

%w=X.^2+Y.^2;

for i=1:n
for j=1:m
if X(i,j)>=x0-dxx/2 && X(i,j)<=x0+dxx/2 && Y(i,j)>=y0-dyy/2 && Y(i,j)<=y0+dyy/2
Z(i,j)=1;
end
end
end

A=fft(Z);
B=A.*conj(A);

figure(1)
surf(X,Y,Z)
colormap jet
colorbar

figure(2)
surf(X,Y,B)
colormap jet
colorbarAlso, how i make sure that Z, has always the size of the matrixs X and Y?
 
Physics news on Phys.org
It would help if you explained what your code is supposed to be doing.
 
it is suppose to plot the fft of a square function which is the sinc function. if you take a look a the photo I've just uploaded, the second one should be a sinc function.
 

Attachments

  • Sem Título.png
    Sem Título.png
    25.2 KB · Views: 519
I don't understand the second plot. You're doing a two-dimensional FFT, right? Why do you have a one-dimensional power spectrum?
 
its 2d too...
 
Really? I don't see depth in the second plot, unlike the first one.
 
and now?
 

Attachments

  • Sem Título.png
    Sem Título.png
    55 KB · Views: 496
I'm assuming this is MATLAB code. According to the documentation, the routine fft doesn't do a two-dimensional DFT. It only acts on the first non-singleton dimension.

EDIT: It looks like the function you want is fft2.
 
humm ok, and how do i center it?
 
  • #10
Probably easiest just to rotate the rows and columns by 50 positions.
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 16 ·
Replies
16
Views
15K
  • · Replies 18 ·
Replies
18
Views
4K
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 11 ·
Replies
11
Views
3K