1
$\begingroup$

Let's consider the cyclic frequency transform and let's try to make it so that the transform of the function is itself.

t=linspace(-32,32,4096);
dt=t(2)-t(1);
fq=linspace( -1/(2*dt) , 1/(2*dt) , length(t) + 1 );
fq=fq(1:  length(t)  );
x=exp(-pi*t.*t);
X=fftshift(fft(x)).*exp(-1i*2*pi*fq*t(1))*dt;
plot(t,real(X));hold on;plot(t,imag(X));hold off;

Now this actually works, and believe me it was not easy for me to get these right. I basically resorted to trial and error, tried adding $\pm 1$ everywhere until I got something that looked reasonable at all. I would like to learn the method behind this madness.

  1. Is is a good idea to use something like t=linspace(-32,32,4096);
    Considering how the frequency is asymmetrical, perhaps time should be as well?

  2. What frequencies does the result of X=fftshift(fft(x)) actually correspond to?

  3. Any other suggestions, etc.?

$\endgroup$
1
$\begingroup$

The FFT calculates the spectrum at N points in the range from $[0, 2\pi)$ where due to the cyclic property the relative frequency 0 must be equal to the frequency $2\pi$. This is best shown via an example. Note that $2\pi$ corresponds to your sampling frequency.

Example: For a length 3 impulse response, say $h=[0.5, 1, 0.5]$, the FFT calculates the spectrum at the relative frequencies $[0, \frac{1}{3}2\pi, \frac{2}{3}2\pi]$, instead of the frequencies $[0, \frac{1}{2}2\pi, 2\pi]$. One way to calculate these frequencies in Matlab for an $N$ points FFT is as follows:

N = 3;
h = [0.5 1 0.5];
fq = linspace(0, 2*pi, N+1);
fq = fq(1:end-1);
H = fft(h);
figure; 
plot(fq, abs(H)); 

The function fftshift takes the right part of the spectrum and places it on the left such that you obtain the frequencies $[\frac{2}{3}2\pi, 0, \frac{1}{3}2\pi]$.

When you are not using the fftshift function and just plot the range $[0, 2\pi]$, then you can use positive time indices for t.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.