Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: frequency to time domain using IFFT and FFT for a real-valued function
Replies: 2   Last Post: Nov 24, 2012 6:41 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Greg Heath

Posts: 5,919
Registered: 12/7/04
Re: frequency to time domain using IFFT and FFT for a real-valued function
Posted: Nov 24, 2012 6:41 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"nerdynerd" wrote in message <k8rero$b4i$1@newscl01ah.mathworks.com>...
> Some suggest that it might be a zero-padding issue; for FFT we can pad the end of the vector with zeros. but for IFFT we should add zeros in the middle of the matrix. I tried that as well but doesn't seem to work for me..
>
> "nerdynerd" wrote in message <k8rcmc$4gc$1@newscl01ah.mathworks.com>...

> > Hi, I have a real-valued function in frequency domain and I'm trying to IFFT to get the signal in time domain and then FFT back to frequency domain. However, I'm unable to get back the original signal. The first step IFFT gives me the correct function but FFT'ing it does not give the original signal. Any ideas what I'm doing wrong?
> > here's my code:


Debugging Tips

1.When you have problems with a large data set, ALWAYS debug with a small,
but representative set.
2. Remove semicolons from statements to check the result

>fsam=-10:0.1:10; % frequency vector

3. ==> Overkill. -7:0.5:7 is good enough for this example

>est_func=exp(-fsam.^2); % test-function

>fsamp=fsam(1)-fsam(2); % \Delta_frequency

4. ==>fsamp is negative

>nfft=2^12;

5. ==>Unnecessary zeropadding

>r0=length(test_func);
>dt=1/fsamp;


6. ==>What is dt supposed to be?

>x = ifft(ifftshift(test_func),nfft); % DFT of signal
>g = (-nfft/2:nfft/2-1)*(1/(fsamp*nfft)); % Time range


7. ==> negative fsamp

8. Didn't check below here

> > q = ifftshift(x);
> >
> > dg=g(1)-g(2);
> > y = fft(fftshift((q)),nfft);
> > w = (-nfft/2:nfft/2-1)*(2*dg); %Frequency range; also tried "fsamp" instead of "2*dg"
> > s = fftshift(y);
> >
> > figure
> > subplot(2,1,1)
> > plot(fsam,testfunc) %original signal
> > hold on
> > plot(w,real(s),'r') %signal after IFFT and FFT
> > hold off
> >
> > subplot(2,1,2)
> > plot(g,real(q)) %real part of the signal after IFFT
> > hold on
> > plot(g,imag(q),'r') %imaginary part of the signal after IFFT
> > hold off


Hope this helps.

Greg



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.