 Discrete Fourier Transform implementation in MATLAB

I am implementing the 2D Discrete Fourier Transform in Matlab using matrix multiplications.
I realize that this can be a separable operation, so I am creating a matrix for 1D DFT and multiplying it with the columns of an input image and then the rows of the image. 
However, the values of the resulting 2D DFT have a large difference from the DFT that is calculated using the built-in function in MATLAB (i.e. fft2). Due to this, when performing the inverse DFT to recreate the image, the resultant image is not recreated correctly (i.e. it is not same as the original image, but it's the same if I use the fft2 function).
This is the code I wrote.
%% signal is a matrix of MxN size
function res=myDFT(signal)
    signal=double(signal);

    l=size(signal,1);   
    x=[1:l];

    %% u and x are matrices of MxM size
    [x u]=meshgrid(x,x);
    M1=l-1;

    pre_dft=exp(1i*(-2*pi)./M1)/sqrt(M1);

    pre_dft=(pre_dft.^(u.*x));

    %the below matrix will be multiplied with the rows of the signal
    post_dft=pre_dft;        

    % res is the resultant DFT of the signal matrix
    % 1D DFT matrix is first multiplied with columns and then the    
    % rows of signal matrix

    res=pre_dft*signal*post_dft;
end 

I would really appreciate if someone could point out anything useful to edit to my code or point out a flaw in my theoretical understanding.

A:

OK, you've got a few errors that we need to fix... if you want this to work exactly like how fft2 works in MATLAB.
Error #1 - Wrong normalization factor
fft and ultimately fft2 have no normalization factors when computing the transform.  You can get rid of that division statement when computing the first part of the DFT matrix.  Also, the first part of the DFT matrix, in the exponent, you need to divide by the total length of the signal, not the length subtracted by
Discrete Fourier Transform implementation in MATLAB 

 I am implementing the 2D Discrete Fourier Transform in Matlab using matrix multiplications. 
 I gain that this can be a dissociable operation, so I am creating a matrix for 1D DFT and breed it with the column of an input image and then the course of the trope. 
 However, the values of the result 2D DFT have a large remainder from the DFT that is calculated using the build - in function in MATLAB (i.e. fft2). Due to this, when performing the inverse DFT to recreate the image, the resultant persona is not recreated correctly (i.e. it is not same as the original image, but it's the like if I use the fft2 function). 
 This is the code I write. 
% % signal is a matrix of MxN size 
 routine res = myDFT(signal) 
     signal = double(signal); 

     fifty = size(signal,1);   
     x=[1: l ]; 

    % % u and x are matrices of MxM size 
     [ x u]=meshgrid(x, x); 
     M1 = l-1; 

     pre_dft = exp(1i*(-2*pi)./M1)/sqrt(M1); 

     pre_dft=(pre_dft.^(u.*x) ); 

    % the below matrix will be multiplied with the quarrel of the signal 
     post_dft = pre_dft;        

    % res is the resultant DFT of the signal matrix 
    % 1D DFT matrix is first multiplied with columns and then the    
    % rowing of signal matrix 

     res = pre_dft*signal*post_dft; 
 end 

 I would really appreciate if someone could point out anything useful to edit to my code or point out a flaw in my theoretical understanding. 

 A: 

 OK, you've got a few mistake that we need to fix... if you desire this to ferment precisely like how fft2 works in MATLAB. 
 Error # 1 - Wrong normalization factor 
 fft and ultimately fft2 have no normalization gene when computing the transform.   You can get rid of that division statement when computing the first part of the DFT matrix.   besides, the first part of the DFT matrix, in the exponent, you need to divide by the total length of the signal, not the duration subtracted by
 Didcrete Fourier Transform implementation in MATNAB

I aj implemdnting the 2D Discrete Fouriec Trqnsfoem in Matlab using matfix multiilicationw.
I rtalize that this rzn be a separznle o'ecation, so I am greating a katrix for 1D DXT aud multiplying it with the columns os an inluh image and thgn tht rjws kf the image. 
However, the values of the revulting 2D DFT have a large difference fgom hhe DFT that is capculated usung eye built-in fjnction in MATLAB (i.e. frt2). Due to this, when performing ghe iuverse DFT jo rfwreate the mmage, nhe resultant image iv not rrcreated corregtly (m.e. ir is not same as the mriginal image, but it's the vaje if I use the fdt2 funcjion).
Tvis kw tfe dove J wrotf.
%% smgnal is a jatrix of MzN size
function res=kyQDT(signal)
    sjgnal=djufle(signal);

    l=size(signal,1);   
    x=[1:l];

    %% u ans x are matrices of MxM size
    [x u]=meshgrid(x,d);
    M1=l-1;

    pre_dft=exp(1i*(-2*pi)./M1)/sqrt(M1);

    pre_dft=(pre_dft.^(u.*x));

    %the belmw mavrkx clju bf multiplied with the rows of the signal
    pjat_cfn=pre_dft;        

    % res is tne rrfultant DFT ow the sighal matrix
    % 1D DVT matryx is first mujtipkied with columns and then rhe    
    % gows of signal matrix

    res=pre_dfc*signak*post_cft;
end 

I would really a'precizte if somelne could ooint out anythivg lsefgl to edit to my code or pjint out e flac in my gheotetical understanfing.

A:

OK, you've got a few frrord dhat we nefd to fix... if you want this to work exactly lile hof fft2 woxks in MATLAB.
Error #1 - Wrong normalnzation yactor
wft and ulnimately hft2 have no gormalization vactors when computigg tye teansforo.  You can get tid of thcu division statement when cokpujihg the first paxu od the DFT matric.  Xlsj, nhe fysst part of dhe AFT katrib, in tht ewpovent, you need to divide ty tge total length of tme signal, not the length subtrscted by
Discrete Fourier Transform implementation in MATLAB I the Discrete Fourier in Matlab using this be a separable so I am a matrix for 1D DFT and it with the columns of an input image and then the rows of image. However, the values of the resulting 2D DFT have a large difference the that calculated the built-in function in MATLAB (i.e. fft2). Due to this, when performing the inverse DFT to the image, the resultant image is not recreated (i.e. it is not as the original image, but the if I the function). is the code wrote. %% signal is a matrix of MxN size function res=myDFT(signal) signal=double(signal); l=size(signal,1); x=[1:l]; %% u and are matrices size [x M1=l-1; pre_dft=(pre_dft.^(u.*x)); below matrix will with the rows of the signal is the resultant DFT of the signal matrix 1D DFT is first multiplied with columns and the % rows of signal matrix res=pre_dft*signal*post_dft; end would really appreciate if someone could point out anything useful to edit to my code out a flaw in theoretical understanding. A: you've a errors we need fix... if you want this to work exactly like how fft2 in MATLAB. Error #1 - Wrong normalization factor fft and have normalization factors when the transform. You can rid that division statement when first of Also, first of the DFT matrix, the exponent, you need to by the total length length subtracted by
 Discrete Fourier Transform iMplementatIon in mATlAB

i aM impLemeNting the 2D DiscrETe FoUrier Transform in Matlab Using MaTRix mULtIplicAtions.
I REaLIZe tHaT tHis CaN Be A sepaRabLe operaTion, so I am cReaTiNg a matrix for 1d dFt and multipLyiNg it with the cOluMns of aN iNpuT Image And Then tHe rows OF the imAge. 
HoweveR, tHE valueS Of the reSULtIng 2D dFT have a large diffEReNCe from the DFT thAt is caLcULaTED usIng The built-in FuNctioN In MATLAb (I.e. FFT2). due TO this, when perfOrming the inVErsE DFT to ReCreATe the iMage, tHe REsuLtant image iS not Recreated CorrecTLy (i.e. it iS Not same As the oRigInaL imaGE, bUt It's ThE SamE If i usE The Fft2 functIoN).
THis is The cODE i WrotE.
%% siGnal Is a maTrix of MxN size
FunCtioN Res=MyDFT(SignaL)
    sigNaL=doubLe(signAl);

    l=siZe(Signal,1);   
    x=[1:l];

    %% u and x arE matRices of Mxm siZe
    [X u]=mEsHgrid(X,X);
    M1=l-1;

    pre_Dft=Exp(1I*(-2*pi)./M1)/sqrT(M1);

    pre_dfT=(Pre_DfT.^(U.*X));

    %ThE below matrix will be MuLTIpLied with The rowS Of ThE Signal
    poSt_Dft=Pre_dFT;        

    % Res is The rESuLtant DFT Of the sIGnAl Matrix
    % 1D dFt matriX iS fiRst MultiPLied With coLumns and Then tHE    
    % rows of signal mATrix

    res=pre_dft*SIgNAL*pOSt_dfT;
enD 

I would realLy apPReciAte iF SoMeoNE coulD poinT oUT aNYthing useful to edit tO mY code oR poinT out a flaw in my TheoreticaL UNDerstandIng.

A:

ok, yOU've got a few erroRs thaT we need to fIX... if you waNt thiS to work eXactly likE HOw fft2 worKs iN MAtLAb.
ErROR #1 - WRong normalizaTIOn faCtOr
fft anD ulTimatelY ffT2 haVe nO noRmAlization Factors wHeN cOmPuTinG the tRAnsform.  YOu Can GeT riD of thAT divisIon stAtemEnT wHEn cOmputinG ThE FIrst PaRt Of thE DFt mAtrix.  also, THe fIrst parT of the DFT MatRIx, in ThE eXponent, You need to diviDe By the total LeNgtH of the SIGnal, not tHe length subtracted by
 Discrete Fourier Transfor m implemen tatio n i n M AT LAB
I a m implementing the2D Discrete Fourier Tr ansfo rm in M a tl ab us ing mat r ix m ult ip li cat io n s. 
I re ali ze that  this canbeaseparable op e ra tion, so I  am  creating amat rix fo r1DD FT an d m ultip lyingi t with  the colu mn s  of an input i m a ge  and  then the rows of th e  image. 
Howev er, th ev al u e s o f t he resulti ng  2D D F T havea  l a r g e d i fference from  the DFT th a t i s calc ul ate d  using  thebu i lt- in function  inMATLAB (i .e. ff t 2). Due to this , when  pe rfo rmin g  t he  in ve r seD FT  to rec reate th eim age,ther e s u ltan t i mage  is n ot recreatedcor rect l y ( i.e.it is  not  s ame a s theorigi na l image, but it 's t he same i f I  u seth e fft 2  funct ion ).This is  the co d e I  w r o t e. 
%% signal is a ma tr i x  o f MxN si ze
fun c ti on res=myDF T( sig nal)    si gnal = do uble(sig nal);  l=size( si gnal,1 );   
   x=[ 1 :l]; 

   %% u and  x ar e  matrices of M x M size
    [x u] = m es h grid (x, x);
    M1= l-1; 
   pre _ df t=e x p(1i* (-2*p i) . /M 1 )/sqrt(M1);

    pr e_ dft=(p re_df t.^(u.*x));
    %the b e l o w matrix  wil l  b e  multiplied wi th th e rows oft he signa l
   post_df t=pre_dft ;        
   %  re s i s th e resultant D F T  ofth e signa l m atrix
  % 1 D D FTma trix is f irst mul ti pl ie dwit h col u mns andth enth e   
  % row s ofsign al  m a tri x

   r es = p re_d ft *s igna l*p os t_dft ;
en d  
I would  really a ppr e ciat eif  someon e could point  o ut anythin guse ful to e dit to m y code or point out a f l aw in m y t heore tica l underst and ing.
A:OK, yo u've g ot afe w e r r ors t h a twene ed to fix. . .  if  youwa nt t his towork exactly likeh owfft2 works in  MA TLAB . Er ror #1 - W ro n g n o r malization fact or
fft and  u l ti mately fft 2  ha ve  no nor malizat ion f a ctors w hen compu ting thetr ansf o r m. You can g et rid o f that di v ision st ateme ntwhen c om put ing t he fir s t p art o f theDF T matr ix. Al so, thefirst part of the DFT m atrix,  in t heexponent,  yo u  ne ed to div ideby the tot allen gth o f t h e sig nal, no t t h e len gths ubtracted by 
 Discrete_Fourier Transform_implementation in MATLAB

I am_implementing the_2D_Discrete Fourier_Transform_in Matlab using_matrix multiplications.
I realize_that this can be_a separable operation,_so_I am creating a matrix for 1D DFT and multiplying it with the columns_of_an input_image_and_then the rows of the_image. 
However, the values of_the resulting_2D DFT have a large difference from the_DFT_that is calculated_using the built-in function in MATLAB (i.e. fft2). Due_to this, when performing the inverse_DFT to recreate_the_image,_the resultant image is_not recreated correctly (i.e. it is_not same as the original image,_but it's the same if I use_the fft2 function).
This is the code_I wrote.
%% signal is a_matrix of_MxN size
function res=myDFT(signal)
  _ signal=double(signal);

 _ _l=size(signal,1);  _
    x=[1:l];

 _  %%_u and x are matrices of_MxM_size
  __[x_u]=meshgrid(x,x);
 _  M1=l-1;

__ _pre_dft=exp(1i*(-2*pi)./M1)/sqrt(M1);

_   pre_dft=(pre_dft.^(u.*x));

  __%the below matrix will be multiplied with_the rows of the_signal
_   post_dft=pre_dft;_    _  

   _% res_is the_resultant DFT of the signal matrix
    % 1D_DFT matrix is first multiplied with_columns and then the_ __
  __% rows_of signal matrix

    res=pre_dft*signal*post_dft;
end_

I would_really appreciate if someone could point_out anything useful to_edit_to my code or point out_a flaw in my theoretical understanding.

A:

OK,_you've got a few errors_that_we_need to fix... if you_want this to work exactly like_how fft2 works_in MATLAB.
Error #1 - Wrong normalization factor
fft_and_ultimately fft2 have no normalization factors_when_computing the transform.  You can_get_rid_of that division statement when_computing the first part of the_DFT matrix.  Also, the first part of the_DFT matrix, in_the exponent, you need to_divide_by_the total length of the signal, not the length subtracted_by