# Why I am not getting the same frequency when sampling a waveform? [duplicate]

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

testData=Table[N@f,{x,0,2*period,1/sampleFrec}];

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!  • Hello Andres. In this case you merely need to add DataRange -> {0, 2*period} to ListPlot. – Mr.Wizard Jun 25 '14 at 16:21
• Nice! Why this happens? The same doesn't happen with Plot[] – Andres Jun 25 '14 at 16:27
• 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. – Mr.Wizard Jun 25 '14 at 16:31
• 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. – Mr.Wizard Jun 25 '14 at 16:37
• Ok! Thank you very much for your help :) – Andres Jun 25 '14 at 16:38