Home > Archive > Matlab > September 2006 > how to reverse a function?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to reverse a function?
|
|
|
| like x[n] = [1+2i, 3+4i, 5+6i], find out x[-n]
| |
| Duncan Po 2006-09-30, 7:07 pm |
| PZ wrote:
>
>
> like x[n] = [1+2i, 3+4i, 5+6i], find out x[-n]
>
>
Do you mean flip an array? If so, there is the function FLIPLR:
[color=darkred]
x =
1.0000 + 2.0000i 3.0000 + 4.0000i 5.0000 + 6.0000i
[color=darkred]
y =
5.0000 + 6.0000i 3.0000 + 4.0000i 1.0000 + 2.0000i
| |
|
| thanks. Close how to specify index 0?
I am supposed to find out fft(conj(array) = conj(fliplr (fft(array))).
basically the fft of a conjugate of one sequence equals to the
conjugate of the -k/N of the fft of the sequence, (messy, guess you
know what I wrote).
The problem is it is -k, it is supposed to start from -5, -4 -3, -2...
If I just use fliplr, it is indexing from zero, right? how to express
this?
pz
Duncan Po wrote:
> PZ wrote:
>
> Do you mean flip an array? If so, there is the function FLIPLR:
>
>
> x =
>
> 1.0000 + 2.0000i 3.0000 + 4.0000i 5.0000 + 6.0000i
>
>
> y =
>
> 5.0000 + 6.0000i 3.0000 + 4.0000i 1.0000 + 2.0000i
| |
|
| OK, i am wrong. it is supposed to be mod, N-K, not fliplr.
let's say [1+2i, 3+4i, 5+6i, 7+8i],
how to find out
[1+2i, 7+8i, 5+6i, 3+4i ]
basically, zero postion wont' chanage, the rest reversed, 1 to final
postion, the final one goes to 1 position?
PZ wrote:[color=darkred]
> thanks. Close how to specify index 0?
>
> I am supposed to find out fft(conj(array) = conj(fliplr (fft(array))).
> basically the fft of a conjugate of one sequence equals to the
> conjugate of the -k/N of the fft of the sequence, (messy, guess you
> know what I wrote).
>
> The problem is it is -k, it is supposed to start from -5, -4 -3, -2...
> If I just use fliplr, it is indexing from zero, right? how to express
> this?
>
>
> pz
> Duncan Po wrote:
| |
| Greg Heath 2006-09-30, 7:07 pm |
| CORRECTED FOR TOPPOSTING
PZ wrote:
> Duncan Po wrote:
>
> thanks. Close how to specify index 0?
>
> I am supposed to find out fft(conj(array) = conj(fliplr (fft(array))).
> basically the fft of a conjugate of one sequence equals to the
> conjugate of the -k/N of the fft of the sequence, (messy, guess you
> know what I wrote).
>
> The problem is it is -k, it is supposed to start from -5, -4 -3, -2...
> If I just use fliplr, it is indexing from zero, right? how to express
> this?
MATLAB only uses positive indices. Negative frequency fft
components are moved to the beginning of the array using
FFTSHIFT. However, the zero frequency component at
index = 1 is only moved to the exact middle of the array when
N is odd. For example
fftshift( [1 2 3 4 5] ) = [4 5 1 2 3]
whereas
fftshift( [1 2 3 4 5 6] ) = [4 5 6 1 2 3]
similarly, when FLIPLR is used next, the zero frequency
component only remains in the exact middle if N is odd.
fliplr( [4 5 1 2 3] ) = [3 2 1 5 4]
whereas
fliplr( [4 5 6 1 2 3]) = [ 3 2 1 6 5 4]
Therefore (FLIPUD used for columns):
Y1 = fft(conj(x))
Y2 = conj(fft(x))
Y3 = fftshift(Y1)
y4 = fftshift(Y2)
%For arbitrary N
Y1 = [ Y2(1); flipud(Y2(2:end)) ]
%For odd N
Y3 = flipud(Y4);
%For even N
Y3 = f[Y4(1); flipud(Y4(2:end))]
Running the following code may help:
clear all, clc
for N = 5:6
N=N
x = randn(N,1)+i*randn(N,1)
Y1 = fft(conj(x));
Y2 = conj(fft(x));
Y1Y2 = [Y1 Y2]
E12 = Y1-[Y2(1);flipud(Y2(2:end))];
E21 = Y2-[Y1(1);flipud(Y1(2:end))];
E12E21 = [E12 E21]'
Y3 = fftshift(Y1);
Y4 = fftshift(Y2);
Y34 =[ Y3 Y4 ]
if floor(N/2) < N/2 % N odd
E34 = Y3-flipud(Y4);
E43 = Y4-flipud(Y3);
else % N even
E34 = Y3-[Y4(1); flipud(Y4(2:end))];
E43 = Y4-[Y3(1); flipud(Y3(2:end))];
end
E34E43 = [E34 E43]'
end
Hope this helps.
Greg
|
|
|
|
|