From: Frank on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hn3sik$5d1$1(a)fred.mathworks.com>...
> "Frank " <francesco.manni01(a)fastwebnet.it> wrote in message <hn3qim$ste$1(a)fred.mathworks.com>...
>
> > PROBLEM:
> > What I get from ifft is my time function (full of zeros at the end, that I would like to remove before plotting in the time domain)
> ======================
>
> Not sure why that's a difficult problem. Just throw away the zeros and the corresponding points on your axes.
>
>
>
> and also the ifft is not properly scaled, as I get 10 times the amplitude of my initial time signal.
> >
> > close all
> >
> > dx = 0.01;
> > xmax = 4;
> > x = 0:dx:xmax;
> > y = sin(2*pi*8*x); %+ sin(2*pi*20*x);
> >
> > N = 2^12;
> > ty = fft(y,N)/length(x);
> ======
>
> should be
>
> ty = fft(y,N)*dx;
>
>
> >
> > fs = 1/dx;
> > f = (0:(N-1)/2)/N*fs;
> >
> > aty = real(ifft(ty,N)*N);
> ==================
>
> Should be
>
> aty = abs(ifft(ty,N))/dx;

Thank you for your help guys! Let me just point out that I don't see why I should take the abs of the ifft instead of the real part... I was taking the real part of the ifft just to get rid of some small complex contribution that may come from calculation roundings or by some frequency filtering I might introduce. It doesn't make much sense to take the abs of ifft if I expect to have a sine wave from ifft for example, since I will "transform" all the negative part and make it positive in the time domain. Maybe I missing something else?

Kind regards

Frank
From: Wayne King on
"Frank " <francesco.manni01(a)fastwebnet.it> wrote in message <hn5g24$4m4$1(a)fred.mathworks.com>...
> "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hn3sik$5d1$1(a)fred.mathworks.com>...
> > "Frank " <francesco.manni01(a)fastwebnet.it> wrote in message <hn3qim$ste$1(a)fred.mathworks.com>...
> >
> > > PROBLEM:
> > > What I get from ifft is my time function (full of zeros at the end, that I would like to remove before plotting in the time domain)
> > ======================
> >
> > Not sure why that's a difficult problem. Just throw away the zeros and the corresponding points on your axes.
> >
> >
> >
> > and also the ifft is not properly scaled, as I get 10 times the amplitude of my initial time signal.
> > >
> > > close all
> > >
> > > dx = 0.01;
> > > xmax = 4;
> > > x = 0:dx:xmax;
> > > y = sin(2*pi*8*x); %+ sin(2*pi*20*x);
> > >
> > > N = 2^12;
> > > ty = fft(y,N)/length(x);
> > ======
> >
> > should be
> >
> > ty = fft(y,N)*dx;
> >
> >
> > >
> > > fs = 1/dx;
> > > f = (0:(N-1)/2)/N*fs;
> > >
> > > aty = real(ifft(ty,N)*N);
> > ==================
> >
> > Should be
> >
> > aty = abs(ifft(ty,N))/dx;
>
> Thank you for your help guys! Let me just point out that I don't see why I should take the abs of the ifft instead of the real part... I was taking the real part of the ifft just to get rid of some small complex contribution that may come from calculation roundings or by some frequency filtering I might introduce. It doesn't make much sense to take the abs of ifft if I expect to have a sine wave from ifft for example, since I will "transform" all the negative part and make it positive in the time domain. Maybe I missing something else?
>
> Kind regards
>
> Frank

Hi Frank, if you are worried about getting some small nonzero imaginary parts due to rounding error even though your Fourier transform is conjugate symmetric, then I recommend using the 'symmetric' flag in the ifft() as I have done in a previous example.

Hope that helps,
Wayne
From: Matt J on
"Frank " <francesco.manni01(a)fastwebnet.it> wrote in message <hn5g24$4m4$1(a)fred.mathworks.com>...

> Thank you for your help guys! Let me just point out that I don't see why I should take the abs of the ifft instead of the real part...
========================

Forget it. You should use real() like before or the 'symmetric' option that Wayne was talking about.


> I have indeed another associated question to ask you. When I had a dc component, let's say I take y = sin(...) + 5 and let the code run, I get an ifft that has a dc component different from 5... Why?
===================

Is there any reason to think it's more than precision error? Are we talking about

y(0)=5.00000000000000000000001
From: Frank on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hn5vsa$jgg$1(a)fred.mathworks.com>...
> "Frank " <francesco.manni01(a)fastwebnet.it> wrote in message <hn5g24$4m4$1(a)fred.mathworks.com>...
>
> > Thank you for your help guys! Let me just point out that I don't see why I should take the abs of the ifft instead of the real part...
> ========================
>
> Forget it. You should use real() like before or the 'symmetric' option that Wayne was talking about.
>
>
> > I have indeed another associated question to ask you. When I had a dc component, let's say I take y = sin(...) + 5 and let the code run, I get an ifft that has a dc component different from 5... Why?
> ===================
>
> Is there any reason to think it's more than precision error? Are we talking about
>
> y(0)=5.00000000000000000000001

Thank you all once more. Indeed I have improved and get somehow a bit more awareness of what these matlab functions are doing and now I feel I am a bit closer to what I need ;) Anyway, the problem with the dc component was in some way associated with the improper scaling I was doing. Instead of 5 I was getting 2.3 or something like that, completely out of sense! Now it works fine... About the real() issue, I will need to put the 'symmetric' flag into ifft because I am creating some custom filter (simple stuff, with erf and other shapes) to apply to my signals and so, after the filtering, which i apply only on the positive part of the spectrum of the abs(fft(vector)), I want to be sure that it comes back to the time domain properly. Hope I have been clear enough!