I am trying to simulate the sampling of a waveform to then apply FFT Analysis to it. Here is the sample code I have now using a square wave:

frequency =50;
sampleFrec = 1000;
period =1/frequency;

f=\[Piecewise]  -1  (period/2)<=Mod[x,period]<period
                 1  True                


Plot[f,{x,0,2*period}, PlotLabel->"Fundamental",ExclusionsStyle->Dashed, PlotStyle->{Thickness[0.006], Red}]

ListLinePlot[testData,PlotRange->Full, PlotLabel->"Fundamental"]

And this are the plots I'm getting, the first one is the 50Hz square wave I want but when I use Table[] and ListLinePlot[] I am not getting the same frequency, why? I am relatively new to Wolfram Mathematica so maybe this is something very stupid. Thank you for your help!

enter image description here enter image description here

  • $\begingroup$ Hello Andres. In this case you merely need to add DataRange -> {0, 2*period} to ListPlot. $\endgroup$
    – Mr.Wizard
    Jun 25 '14 at 16:21
  • $\begingroup$ Nice! Why this happens? The same doesn't happen with Plot[] $\endgroup$
    – Andres
    Jun 25 '14 at 16:27
  • $\begingroup$ ListLinePlot has no way of knowing what range your data is supposed to cover, so it simply uses the number of data points as the range. $\endgroup$
    – Mr.Wizard
    Jun 25 '14 at 16:31
  • $\begingroup$ I closed this question because I felt it would be of limited use to future readers, and because I think the subject has already been covered on this site though I cannot find a good "duplicate" as the moment. (Don't misunderstand: this is not the same as saying it is a bad question.) I'll continue looking for a good duplicate. $\endgroup$
    – Mr.Wizard
    Jun 25 '14 at 16:37
  • $\begingroup$ Ok! Thank you very much for your help :) $\endgroup$
    – Andres
    Jun 25 '14 at 16:38