Discussion:
inverse fft without ifft
(too old to reply)
Fabian Braennstroem
2005-02-09 20:18:05 UTC
Permalink
Hi,

I am doing some more steps with matlab. I want to get a
little bit into fft and do some small calculations.
Doing a fft on a cosinus-function I get a lot of complex
numbers and I am a bit confused howto make the inverse fft
from these values without using 'ifft'. I just want to test
the 'fft'-results by doing the inverse.
Does anybody have a small example or hint?

Greetings, Fabian
Sarah
2005-02-09 21:41:57 UTC
Permalink
In this code I have generated a cosine signal; taken its fft and then
taken its ifft to get the cosine signal back. Remember the
reconstructed signal was zeropadded so I had to get rid of the same.
~ Sarah

P.S - "Digital Signal Processing: A computer based approach" S.K. Mitra

k = 0:15;
x = cos(2*pi*k*3/16);
X = fft(x,512);
Xo = fft(x,16);
L= 0:511;
plot(L/512, abs(X), k/16, abs(Xo), 'ro');

Xi = ifft(X);
Xoi = ifft(Xo);
figure;
plot(k, Xi(1:16), 'b');
hold;
plot(k, Xoi, 'r--');
spasmous
2005-02-10 00:09:29 UTC
Permalink
...how to make the inverse fft ... without using 'ifft'...
n = 8;
q=fft(1:n);

fft(q')/n
spasmous
2005-02-10 01:46:50 UTC
Permalink
Post by spasmous
...how to make the inverse fft ... without using 'ifft'...
n = 8;
q=fft(1:n);
fft(q')/n
Of course you knew the important part of ' that I meant was that it
performs compex conjugate ;) So actually fft(conj(q))/n is better.
Fabian Braennstroem
2005-02-10 06:32:31 UTC
Permalink
Hi to both,

thanks for the answers! I should go more in detail...

I actually want to do the inverse 'step by step'. So I want
to use the complex c_n numbers, which I got from the 'fft'. With an
equation like:

f(t)= A_0 / 2 + sum_1^infinity A_n cos(n * omega * t + phi_n)


using:

A_0 / 2 = c_0

A_n = 2 |c_n|

phi_n = atan(imag(c_n) / real(c_n)


I think I should get back my original function.

For my problem I read in 111 different values and do a simple 'fft' with
ploting the read-in values and the fft-values using:

,------[]
| filenamestruct=dir('/home/fab/HOME/Dissertation/Simulation/13/DNS-INP/Data/uvwnut_11*.dat');
| for ii=1:length(filenamestruct)
| storedname=filenamestruct(ii).name;
| data=load(storedname);%only use if
| value(ii)=data(10,1);
| end
|
| % the length of filenamestruct is 111
|
| figure(1);
| plot(1:length(filenamestruct),value(1:length(filenamestruct)));
|
| value_fft=fft(value);
|
| figure(2);
| plot(1:length(value_fft),value_fft);
`------[]



This works fine for me.
Now I want to test the calculated c_n (here: value_fft) and transform
them back to the 'original' function by using the function mentioned
above:

,------[]
| test_value0 = 0.0;
| test_value(1)= test_value0 + value_fft(1)/2;
| omega= 2/pi*1000;
|
| for t=2:1:length(value) % length(value)=111
| for jj=2:length(value_fft) % length(value_fft)=111
| test_value(t)= test_value(t-1) + 2*abs(value_fft(jj))*
| cos(jj*omega*t+atan(imag(value_fft(jj))/real(value_fft(jj))));
| end
| end
|
| figure(3);
| plot(2:1:length(value),test_value(2:1:length(value)))
|
`------[]

This does not at all look like my 'original'-plot. I think my problem is
that I don't know how to define the 'omega'; it should be:

omega = 2*pi / T

with T:= period

But what is my period for those values?


Greetings, Fabian
Dave Robinson
2005-02-10 11:56:00 UTC
Permalink
Post by Fabian Braennstroem
Hi to both,
thanks for the answers! I should go more in detail...
I actually want to do the inverse 'step by step'. So I want
to use the complex c_n numbers, which I got from the 'fft'. With an
f(t)= A_0 / 2 + sum_1^infinity A_n cos(n * omega * t + phi_n)
A_0 / 2 = c_0
A_n = 2 |c_n|
phi_n = atan(imag(c_n) / real(c_n)
I think I should get back my original function.
For my problem I read in 111 different values and do a simple 'fft' with
,------[]
|
filenamestruct=dir('/home/fab/HOME/Dissertation/Simulation/13/DNS-IN
Post by Fabian Braennstroem
P/Data/uvwnut_11*.dat');
| for ii=1:length(filenamestruct)
| storedname=filenamestruct(ii).name;
| data=load(storedname);%only use if
| value(ii)=data(10,1);
| end
|
| % the length of filenamestruct is 111
|
| figure(1);
| plot(1:length(filenamestruct),value(1:length(filenamestruct)));
|
| value_fft=fft(value);
|
| figure(2);
| plot(1:length(value_fft),value_fft);
`------[]
This works fine for me.
Now I want to test the calculated c_n (here: value_fft) and
transform
them back to the 'original' function by using the function
mentioned
,------[]
| test_value0 = 0.0;
| test_value(1)= test_value0 + value_fft(1)/2;
| omega= 2/pi*1000;
|
| for t=2:1:length(value) % length(value)=111
| for jj=2:length(value_fft) % length(value_fft)=111
| test_value(t)= test_value(t-1) + 2*abs(value_fft(jj))*
| cos(jj*omega*t+atan(imag(value_fft(jj))/real(value_fft(jj))));
| end
| end
|
| figure(3);
| plot(2:1:length(value),test_value(2:1:length(value)))
|
`------[]
This does not at all look like my 'original'-plot. I think my
problem is
omega = 2*pi / T
with T:= period
But what is my period for those values?
Greetings, Fabian
I haven't got time to look through your code in detail, but first
glance suggests that you might need to take into account that half of
your spectral detail represents negative frequency components. If you
use the "fftshift()" function after your fourier transform it will
allow you to specify your frequency range from the minus frequency to
the plus frequency in one step.

Rather than trying to add in your phase that way, why not simply use
the "cos()" function for the Real component of the transform, and a
"sin()" function for the Imaginary components.

Regards

Dave Robinson
Fabian Braennstroem
2005-02-14 12:02:29 UTC
Permalink
[...]
Post by Dave Robinson
I haven't got time to look through your code in detail, but first
glance suggests that you might need to take into account that half of
your spectral detail represents negative frequency components. If you
use the "fftshift()" function after your fourier transform it will
allow you to specify your frequency range from the minus frequency to
the plus frequency in one step.
Thanks! I will take a look at 'fftshift'.
Post by Dave Robinson
Rather than trying to add in your phase that way, why not simply use
the "cos()" function for the Real component of the transform, and a
"sin()" function for the Imaginary components.
I will try both ways, then I hopefully understand 'fft' a
little bit better.

Greetings, Fabian
Greg Heath
2005-02-16 17:37:37 UTC
Permalink
function X=dft(t,x,f)
% function X=dft(t,x,f)
% Compute DFT (Discrete Fourier Transform) at frequencies given
% in f, given samples x taken at times t:
% X(f) = sum(k=1,N) { x(k) * exp(-2*pi*j*t(k)*f) }
%
t = t(:); % Format 't' into a column vector
x = x(:); % Format 'x' into a column vector
f = f(:); % Format 'f' into a column vector
W = exp(-2*pi*j * f*t');
X = W * x;

Continue reading on narkive:
Loading...