# Reconstruct signal using InverseFourier [closed]

I start from a signal, I do discrete Fourier transform of the signal, and I want to get back this same signal doing a discrete inverse Fourier transform. However, when I do so, I do not obtain the same signal back. What am I missing?

Here I give the code of a simple example:

signal[i_] :=
UnitStep[(i*samplingPeriode) + 0.5] -
UnitStep[(i*samplingPeriode) - 0.5]

initialTime = -5;
finalTime = 5;
signalDuration = finalTime - initialTime;

bandwidth = 50;
nyquistRate = 2*bandwidth;
nyquistSamplingPeriode = 1/nyquistRate;

samplingFrequency = 50*nyquistRate;
samplingPeriode = 1/samplingFrequency;
numberOfSamples = signalDuration/samplingPeriode;

yValuesSampledSignal =
Table[signal[i], {i, initialTime/samplingPeriode,
finalTime/samplingPeriode}];
xValuesSampledSignal =
Table[i*samplingPeriode, {i, initialTime/samplingPeriode,
finalTime/samplingPeriode}];
sampledSignal =
Partition[Riffle[xValuesSampledSignal, yValuesSampledSignal], 2];

yValuesDiscreteFourierTransform =
samplingPeriode*
Chop[Fourier[yValuesSampledSignal, FourierParameters -> {1, -1}]];
xValuesDiscreteFourierTransform =
Table[i*(1/signalDuration), {i, 0, numberOfSamples}];
discreteFourierTransform =
Partition[
Riffle[xValuesDiscreteFourierTransform,
yValuesDiscreteFourierTransform], 2];

absYValuesDiscreteFourierTransform =
Abs[samplingPeriode*
Fourier[yValuesSampledSignal, FourierParameters -> {1, -1}]];
absDiscreteFourierTransform =
Partition[
Riffle[xValuesDiscreteFourierTransform,
absYValuesDiscreteFourierTransform], 2];

argYValuesDiscreteFourierTransform =
Arg[samplingPeriode*
Fourier[yValuesSampledSignal, FourierParameters -> {1, -1}]];
argDiscreteFourierTransform =
Partition[
Riffle[xValuesDiscreteFourierTransform,
argYValuesDiscreteFourierTransform], 2];

yValuesRecontructedSignal =
InverseFourier[yValuesSampledSignal, FourierParameters -> {1, -1}];
xValuesRecontructedSignal = xValuesSampledSignal;
reconstructedSignal =
Partition[
Riffle[xValuesRecontructedSignal, yValuesRecontructedSignal], 2];

ListLinePlot[sampledSignal, PlotRange -> All]
ListPlot[Take[absDiscreteFourierTransform, 50], Filling -> Axis,
PlotRange -> All]
ListPlot[Take[argDiscreteFourierTransform, 50], Filling -> Axis,
PlotRange -> All]
ListLinePlot[Abs[reconstructedSignal], PlotRange -> All]


## closed as off-topic by Daniel Lichtblau, user9660, Yves Klett, Öskå, dr.blochwaveDec 21 '15 at 18:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Daniel Lichtblau, Community, Yves Klett, Öskå, dr.blochwave
If this question can be reworded to fit the rules in the help center, please edit the question.

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Dec 21 '15 at 2:55
• You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful – Michael E2 Dec 21 '15 at 2:55
• As I remember, the reconstructed signal have to be created from Fourier image of initial one: recsig=InverseFourier@Fourier@sig but in your sample of code I've seen the recsig=InverseFourier[sig] which is wrong. – Rom38 Dec 21 '15 at 7:08
• This is nicely set up for a first question to the forum, but, as it seems to arise from a small programming error, I'm voting to close. – Daniel Lichtblau Dec 21 '15 at 16:28

Rom38 is correct, you did have a typo where you were applying the inverse transform on the original data, not on the transformed data. Just change that line to read

yValuesRecontructedSignal = (1/samplingPeriode) InverseFourier[
yValuesDiscreteFourierTransform, FourierParameters -> {1, -1}];


Also, I find it easier and more clear to use Transpose, as in

Partition[Riffle[ list1, list2], 2] = Transpose @ {list1, list2}


But really, you don't have to keep the data as a 2D list of {x, y} values. You run into trouble when you run your last plotting command, ListLinePlot[Abs[reconstructedSignal]] - since it takes the absolute values of both axes (meaning your negative time values are turned into positive time values).

I find it easier to just specify the DataRange of the ListLinePlot, as in

ListLinePlot[yValuesSampledSignal,
DataRange -> {initialTime, finalTime}]
ListLinePlot[Chop@InverseFourier@Fourier@yValuesSampledSignal,
DataRange -> {initialTime, finalTime}]


where I'm using the shorthand notation, f[ g[ x] ] = f @ g @ x

• Hi, Thank you all for your replies! It helped a lot! Sorry for the mistake... – Gabriel Dec 21 '15 at 23:33