Home › Forum Online Discussion › General › discrete fourier transform in 2D
This topic contains 9 replies, has 1 voice, and was last updated by Swedich Dragon 9 years, 3 months ago.

AuthorPosts

September 8, 2008 at 3:00 pm #29074
Hello
Propably completely wrong forum.
I do FFT on a two dimensional matrix. Matlab gives complex coefficients. I have written a program that calculate the sine and cosine coefficients.
When calculating the original discrete funnction from this coefficients I’ve got the right answer but:
On a 4×4 matrix the column 2 and four are shiftet with eachother. Strange. Otherwise I’ve got the right answer.
Perhaps check for other matrix dimensions also.
Hm.
I had no formula for the calculation of the coefficients, so I have made my own. That might be the problem.
S D
September 8, 2008 at 3:10 pm #29075%Of course you can do two dimensional fft with fft2, but the problem is that I need
%the real coefficients and not know how to convert them.clear
format short
%This is the matrix to do fft on
tal=[13 3 55 42
3 5 7 9
4 2 6 88
2 4 6 7]%This is the make the complex coefficients
koff=fft(tal’);%I want later to do the fourier transform on a and b real cofficients, they will be %aranged so that I do the FFT on the coefficients with the same frequency
koff=koff’;%formulas for calculating the real from the complex
konjkoff=conj(koff);
ak=koff+konjkoff;
bk=i*(koffkonjkoff);%found out that the discrete real coefficients should be half of what the
%continuous was, when calculating them from the complex
ak=ak/2;
bk=bk/2;%1D fourier transform over each column with real coefficients of the same frequenscy
koffa=fft(ak);
koffb=fft(bk);
konjkoffa=conj(koffa);
konjkoffb=conj(koffb);%for the one start with an a
aa=(koffa+konjkoffa)/2;
ab=(i*(koffakonjkoffa))/2;%for the one start with an b
ba=(koffb+konjkoffb)/2;
bb=(i*(koffbkonjkoffb))/2;%summa=zeros(4,4);
%n and m are the place in the matrix for reconstructing tal from the real
%coefficinets
for n=1:4
for m=1:4%m=1
%n=3
summa=0;
%k and p are the different frequencies
for k=1:4
for p=1:4
summa=summa+aa(p,k)*cos((2*pi*(k1)*(n1))/4)*cos((2*pi*(p1)*(m1))/4)…
+ab(p,k)*cos((2*pi*(k1)*(n1))/4)*sin((2*pi*(p1)*(m1))/4)…
+ba(p,k)*sin((2*pi*(k1)*(n1))/4)*cos((2*pi*(p1)*(m1))/4)…
+bb(p,k)*sin((2*pi*(k1)*(n1))/4)*sin((2*pi*(p1)*(m1))/4);end
endsvar(m,n)=summa/16;
end
end
svarSeptember 8, 2008 at 3:11 pm #29077Besy should be the formulas for convertion but I haven´t found them.
September 8, 2008 at 3:29 pm #29079Hello
The matrix is just for me to see if I did it right, the real matrixes in my project are huge!
S D
September 8, 2008 at 3:31 pm #29081Hello
Is that a more reliable program than matlab?
S D
September 8, 2008 at 3:37 pm #29083Hello
Perhaps I do not need the FFT. But I need the real coefficients from discrete fourier transform in 2D anyway!
S D
September 8, 2008 at 4:24 pm #29085I was out walking to buy some milk for tomorrow. Found two ideas. One was to change the m1 or the n1 to m respectively n. Beacase the answer was wery close but had the following look.
Firs column right. column two=equal to the last and the rest was in reversed order.
SO
the picture was
1 5 4 3 2 if 5×5 matrix
1 4 3 2 if 4×4
So i realised that I was close to the solution.
I got the idea to change the rows with the columns in the fft, had tried it before but now I did want to do it on two places at the same time. this wery intuitive idea turned out the be rigth. Have not realised why jet. That is the work for tommorrow.
Today I travelled in to the university and looked for books on this at several places, but couldn´t find any. So during the luch brake I got the basic idea in my head. sketched it on the bus and programmed it this evening. Found the error made beacase I didn´t have the full theory just new that 2d discrtet could be done in two steps first as a a 1d at each row and then a new to the result.
I´m happy to have solved it, but without any rigourous theory, bad.
S D
The changes are marked with many !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
clear
format short
%This is the matrix to do fft on
tal=[13 3 55 42
3 5 7 9
4 2 6 88
2 4 6 7]%This is the make the complex coefficients
koff=fft(tal’);%I want later to do the fourier transform on a and b real cofficients, they will be %aranged so that I do the FFT on the coefficients with the same frequency
koff=koff; TAKEEN AWAY THE TRANSPOSE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ACTION ONE OF TWO%formulas for calculating the real from the complex
konjkoff=conj(koff);
ak=koff+konjkoff;
bk=i*(koffkonjkoff);%found out that the discrete real coefficients should be half of what the
%continuous was, when calculating them from the complex
ak=ak/2;
bk=bk/2;%1D fourier transform over each column with real coefficients of the same frequenscy
koffa=fft(ak’);!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!I put in the transpose here. The difference is that now the fft is ower different frequencies. I think. havent analysed it jet.koffb=fft(bk’);
konjkoffa=conj(koffa);
konjkoffb=conj(koffb);%for the one start with an a
aa=(koffa+konjkoffa)/2;
ab=(i*(koffakonjkoffa))/2;%for the one start with an b
ba=(koffb+konjkoffb)/2;
bb=(i*(koffbkonjkoffb))/2;%summa=zeros(4,4);
%n and m are the place in the matrix for reconstructing tal from the real
%coefficinets
for n=1:4
for m=1:4%m=1
%n=3
summa=0;
%k and p are the different frequencies
for k=1:4
for p=1:4
summa=summa+aa(p,k)*cos((2*pi*(k1)*(n1))/4)*cos((2*pi*(p1)*(m1))/4)…
+ab(p,k)*cos((2*pi*(k1)*(n1))/4)*sin((2*pi*(p1)*(m1))/4)…
+ba(p,k)*sin((2*pi*(k1)*(n1))/4)*cos((2*pi*(p1)*(m1))/4)…
+bb(p,k)*sin((2*pi*(k1)*(n1))/4)*sin((2*pi*(p1)*(m1))/4);end
endsvar(m,n)=summa/16;
end
end
svarSeptember 8, 2008 at 4:27 pm #29087Hello
I´m glad that you have showed me the program, but I don´t think I want to change it for this work.
The reason is that I know matlab quite alright. Another reason is that I have dyslexia, (perhaps it is another name in english, when you have dificulties with spelling reading and such things. For me it is spelling and to remember new words that is my dyslexia)
And with this in mind there is quite huge problems involved with changing programming languages.
Thanks anyway, perhaps for the future.
S D
September 9, 2008 at 9:49 am #29089Hello
The error was actually that the transpose with a complex matrix is another thing than the transpose of a real one.
And the second fourier transform work over equal frequencies.
S D
September 9, 2008 at 9:49 am #29091Hello
The error was actually that the transpose with a complex matrix is another thing than the transpose of a real one.
And the second fourier transform work over equal frequencies.
S D

AuthorPosts
You must be logged in to reply to this topic.