I am exploring the differences between fftw in MATLAB and C/C++. I think this maybe a straightforward question but for some reason I don't see it.
Assume the following MATLAB code:
xi = ((0:Nx-1)/Nx)*(2*pi);
ygl = cos ( pi * ( 0 : Ny ) / Ny )';
ygl = (1/2)*(((yupp-ylow)*ygl) + (yupp+ylow));
u = (Y-ylow) .* (Y-yupp) .* sin( (2*pi / Lx) * X);
uhp=[uh(:,1:Nx/2) zeros(Ny,(m-Nx)) uh(:,Nx/2+1:Nx)];
u1 = real(ifft(uh,[],2));
My question above since both ``uh`` and ``uhp`` are the same values with extra zero padding, why is the inverse of fft of these two different? Meaning if ``uh`` is:
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 5.2721i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 5.2721i
-0.0000 + 0.0000i 0.0000 +18.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 -18.0000i
-0.0000 + 0.0000i 0.0000 +30.7279i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 -30.7279i
-0.0000 + 0.0000i 0.0000 +36.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 -36.0000i
-0.0000 + 0.0000i 0.0000 +30.7279i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 -30.7279i
-0.0000 + 0.0000i 0.0000 +18.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 -18.0000i
0.0000 + 0.0000i 0.0000 + 5.2721i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 5.2721i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
and ``uhp`` is:
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 5.2721i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 5.2721i
-0.0000 + 0.0000i 0.0000 +18.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 -18.0000i
-0.0000 + 0.0000i 0.0000 +30.7279i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 -30.7279i
-0.0000 + 0.0000i 0.0000 +36.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 -36.0000i
-0.0000 + 0.0000i 0.0000 +30.7279i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 -30.7279i
-0.0000 + 0.0000i 0.0000 +18.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 -18.0000i
0.0000 + 0.0000i 0.0000 + 5.2721i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 5.2721i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
Then why the `` real(ifft(uh,[],2))`` equals:
0 -0.9320 -1.3180 -0.9320 -0.0000 0.9320 1.3180 0.9320
-0.0000 -3.1820 -4.5000 -3.1820 -0.0000 3.1820 4.5000 3.1820
0 -5.4320 -7.6820 -5.4320 -0.0000 5.4320 7.6820 5.4320
-0.0000 -6.3640 -9.0000 -6.3640 -0.0000 6.3640 9.0000 6.3640
0 -5.4320 -7.6820 -5.4320 -0.0000 5.4320 7.6820 5.4320
-0.0000 -3.1820 -4.5000 -3.1820 -0.0000 3.1820 4.5000 3.1820
0 -0.9320 -1.3180 -0.9320 -0.0000 0.9320 1.3180 0.9320
and ``up=ifft(uhp,[],2); `` is:
0 -0.4393 -0.7610 -0.8787 -0.7610 -0.4393 -0.0000 0.4393 0.7610 0.8787 0.7610 0.4393
-0.0000 -1.5000 -2.5981 -3.0000 -2.5981 -1.5000 -0.0000 1.5000 2.5981 3.0000 2.5981 1.5000
0 -2.5607 -4.4352 -5.1213 -4.4352 -2.5607 -0.0000 2.5607 4.4352 5.1213 4.4352 2.5607
-0.0000 -3.0000 -5.1962 -6.0000 -5.1962 -3.0000 -0.0000 3.0000 5.1962 6.0000 5.1962 3.0000
0 -2.5607 -4.4352 -5.1213 -4.4352 -2.5607 -0.0000 2.5607 4.4352 5.1213 4.4352 2.5607
-0.0000 -1.5000 -2.5981 -3.0000 -2.5981 -1.5000 -0.0000 1.5000 2.5981 3.0000 2.5981 1.5000
0 -0.4393 -0.7610 -0.8787 -0.7610 -0.4393 -0.0000 0.4393 0.7610 0.8787 0.7610 0.4393
The reason I ask b/c in C/C++ when padding my arrays similarly and taking the ifft my code returns the same output, so ``real(ifft(uh,[],2))`` = ``real(ifft(uhp,[],2))``