Using ifft to get the Fourier Coefficient

What exactly does the ifft() gives me?
I have a real data in 'x' where,
f=summation over -N to N-1 [C(n)exp(2*pi*1i*x/L)]
So, here f is known at every point (2N points in total). fftshift(ifft(f)) also gives an array of 2N size. So, does it gives me the coefficients C(n). If so, then can you please check the following code.
N=256;
X=2*N;
L=2*pi;
x=linspace(-pi,pi,X);
c=0;
for n=1:2*N
k(n)=2*pi*(n-N-1)/L;
end
y=x;
z=fftshift(ifft(y));
for i=1:2*N
c=c+z(i)*exp(1i*k(i)*x);
end
plot(x,y);hold on;plot(x,c);
Here, if ifft() gave the coefficients, then shouldn't the plots have matched?

3 Kommentare

What is this and where is c?
y=x/pi;
...
plot(x,y);hold on;plot(x,c);
Why/How do you use loop here? i? n?
for i=1:2*N
F=F+z(n)*exp(1i*k(n)*x);
end
Why like that?
z=fftshift(ifft(y));
Raunak Raj
Raunak Raj am 27 Jun. 2016
Bearbeitet: Raunak Raj am 27 Jun. 2016
Hi, I am sorry, that wasn't the intended code. I have edited the code correctly. fftshift is just to shift the values from 0 to 2N to -N to N-1 frequencies (actually wave numbers). Moreover, the code works as intended for y=sin(x) but for other functions there appears a shift in the graphs.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan Orwat
Jan Orwat am 27 Jun. 2016

0 Stimmen

N=256;
X=2*N;
L=2*pi;
x=linspace(-pi,pi,X);
c=0;
k = 2*pi*((1:2*N)-N-1)/L; % vectorised
y = sin(x); % don't understand why it is here, why not defined earlier
z = ifftshift(ifft(y)); % would be more logical to use fft here
for i=1:2*N
c=c+z(i)*exp(1i*k(i)*(pi-x));
end
plot(x,y);hold on;plot(x,real(c));

1 Kommentar

Jan Orwat
Jan Orwat am 27 Jun. 2016
Bearbeitet: Jan Orwat am 27 Jun. 2016
I'm still not sure why you calculate ifft of signal, then dft of ifft and compare with original signal. From mathematical point of view it makes no difference, because y, ifft(fft(y)) and fft(ifft(y)) are equal (within numerical precision), but it's logically weak.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 26 Jun. 2016

Bearbeitet:

am 27 Jun. 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by