From: fisico32 on
Hello Forum,

I run the code below for the detection of 2D sinusoids. I am calculating
the FFT of Z=1*cos(6*X+10*Y)+ 1*cos(3*X);

I get a correct amplitude for the cos(6*X+10*Y) part but the 1*cos(3*X) has
a smaller peak (and it shouldn't since it has the same magnitude 1)....

Why? I do I get around that simple problem? Is it a sampling issue?

Here my brief code:

clc
clear
[X,Y] = meshgrid(-10:.1:10, -10:.1:10);
N=length(X);
dx=.1;
dy=dx;
df=(2*pi/(N*dx));

Z =1*cos(6*X+10*Y)+ 1*cos(3*X);

D=fftshift(fft2(Z));
tt=abs(D);
mesh(tt)

maxValue = max( max(tt) ) ;

[qq rr] = find(tt==maxValue);
[qq rr] = find(tt>14000);

px=floor((rr-(N/2))*df)
py=floor((qq-(N/2))*df)


From: Clay on
On Jun 22, 9:54 am, "fisico32" <marcoscipioni1(a)n_o_s_p_a_m.gmail.com>
wrote:
> Hello Forum,
>
> I run the code below for the detection of 2D sinusoids. I am calculating
> the FFT of Z=1*cos(6*X+10*Y)+ 1*cos(3*X);
>
> I get a correct amplitude for the cos(6*X+10*Y) part but the 1*cos(3*X) has
> a smaller peak (and it shouldn't since it has the same magnitude 1)....
>
> Why? I do I get around that simple problem? Is it a sampling issue?
>
> Here my brief code:
>
> clc
> clear
> [X,Y] = meshgrid(-10:.1:10, -10:.1:10);
> N=length(X);
> dx=.1;
> dy=dx;
> df=(2*pi/(N*dx));
>
> Z =1*cos(6*X+10*Y)+ 1*cos(3*X);
>
> D=fftshift(fft2(Z));
> tt=abs(D);
> mesh(tt)
>
> maxValue = max( max(tt) )  ;
>
> [qq rr] = find(tt==maxValue);
> [qq rr] = find(tt>14000);
>
> px=floor((rr-(N/2))*df)
> py=floor((qq-(N/2))*df)

Leakage! Try setting up your data so you have a whole number of cycles
of each frequency in your domain.