Shifting using fouriertransform

926 Views Asked by At

I'm doing a small mathematical exercise where I take a function, perform a Fourier transform on it and then multiply the result by $e^{i\alpha w}$. And then take the inverse Fourier transform of the product. The result should be the first function shifted by $\alpha$ units to the left.
$$y=f(x) \Rightarrow_{Fourier} F(y) \Rightarrow F(y)*e^{i\alpha w} \Rightarrow_{Inverse} y = f(x+\alpha)$$

The problem is, when I'm doing this in Matlab, I fail to get the right answer

a = 0;
b = 1;
n = 128;
alpha = 1; x = linspace(a,b,n);
y = asin(x);
plot(y);
z = exp(1ialphax);
Fy = fft(y);
Fyz = Fy .* z;
y_shifted = ifft(Fyz);
plot(y_shifted);

Here instead of shifted asin, I get this:
Failedshift

Can you please point me to what I'm doing wrong?

1

There are 1 best solutions below

1
On BEST ANSWER

I think a few things are happening here:

One is that, if y_shifted is complex, then plot will plot imag(y_shifted) vs. real(y_shifted), so you may want to override this by using plot(x,real(y_shifted)). Even though y_shifted should be real, there are going to be precision issues, and the actual result will be complex.

Secondly, fft is an implementation of the discrete Fourier transform, and so you want to think of things in terms of "number of grid points" rather than "length of interval". In particular, the shift theorem for DFT is for multiplication by factors like $e^{2\pi i nm/N}$ where $N$ is the total number of grid points, $m$ is the number of gridpoints you want to shift, and $n$ is the independent variable. So, as you have it written, if we compare $e^{i\alpha x}$ and $e^{2\pi i nm/N}$, then $x = n/N$ ($x$ takes on the values $0/128$, $1/128$, $2/128$, etc.), you've set $\alpha = 1$, and so $m = 1/2\pi$ isn't much of a shift (and there's also the fact that it isn't an integer, the consequences of which I'm not totally clear on).

Next, you have to keep in mind that since DFT only samples the function on a finite interval, once you shift, you will be doing circular shifts - i.e. the DFT you performed only ever knew about the values of $\arcsin(x)$ on $[0,1]$, so shifting by $1$ isn't going to magically give you the values on $[1,2]$; rather, the DFT will give you a periodic extension, and then shift that. (so, if you shift by $1$ unit (not 1 grid point), then nothing happens! since that was the period of the function)

Finally, DFT is just an approximation (you're only sampling the function at a discrete set of points), and so ifft(z.*fft(y)) is only an approximation as well. In particular, if the original function has a lot of jump discontinuities or sharp corners, you'll notice the effects on the output (try a step function, e.g. y = 1*(0.25 < x & x < 0.75)

Anyway, you'll have to play around more to get exactly what you want, but I got this code working a little better:

a = 0;
b = 1;
n = 128;
alpha = 10; x = linspace(a,b,n);
y = asin(x);
plot(y);
z = exp(2*pi*1i*alpha*x);
Fy = fft(y);    
Fyz = Fy .* z;
y_shifted = ifft(Fyz);
figure; plot(x,real(y_shifted));