# Problem with Sin and ListPlot

In order to produce a smooth sine wave (Sin) and visualize it (ListPlot), I seem to need a very high sample rate (much higher than Nyquist).

I want to know if this is a artifact of ListPlot or Sin and am using Fourier (discrete Fourier Transform) to examine the outputs but am finding a feature that is even more confusing.

Sig should generate a tone (10000 hz) of variable duration.

FD should plot the signal in the Frequency domain (in this case: a peak at 10000)

The output of Sig, sampled 400 kHz is shown in the top panel.
Note that I am only plotting a small sample of time.

The output of FD is in the bottom panel. The odd thing is that the frequency appears to be sensitive to signal duration, which is both unexpected and wrong.

Sig[duration_] :=
Module[{int = N@1/400000},
Table[{t, Sin[2*\[Pi]*10000*t]}, {t, int, duration, int}]];

FD[duration_] := Module[{},
fresp = Partition[
Riffle[
Table[x, {x, 0, 21998, 2}],
Abs[Fourier[Sig[duration][[;; , 2]]]]
[[2 ;; 11000]]]
, 2]]

dur = 0.1; testSig = Sig[dur]; testFD = FD[dur];
GraphicsColumn[{ListPlot[testSig[[1000 ;; 1100, 2]], Joined -> True],
ListLogLinearPlot[testFD, Joined -> True, PlotRange -> All]}]

dur = 0.1; testSig = Sig[dur]; testFD = FD[dur];
GraphicsColumn[{ListPlot[testSig[[1000 ;; 1100, 2]], Joined -> True],
ListLogLinearPlot[testFD, Joined -> True, PlotRange -> All]}] • There is a problem : The two blocks of code beginning with dur= are exactly identical. Apr 23, 2016 at 21:01
• Apologies, I am not certain why it appears twice, but there is only one test shown (ignore the second iteration) Apr 23, 2016 at 21:14
• The same cryptic code Partition[Riffle[....],2] as in this question. Please don't propagate this style. Thanks. Apr 23, 2016 at 21:34

You haven't defined the x-Axis value for the ListLogLinearPlot and therefore the peak-position is dependent of the duration, which is proportional to the number of values.

If you define the frequencies correctly it works well:

(*Create Signal*)
freq = 10000;
sampleFreq = 400000;
maxFreq = sampleFreq/2;
dt = 1/sampleFreq;
duration = 0.1;
Sig[duration_, dt_, freq_] :=
Table[{t, Sin[2*\[Pi]*freq*t]}, {t, 0, duration-dt, dt}];
signal = Sig[duration, dt, freq];
ListLinePlot[signal, PlotRange -> {{0, 1*^-4}, All}]

(*Signal DFT*)
pointsNumber = Length@signal;
dftAmp = Abs@Fourier[signal[[All, 2]]];
dftFreq = signal[[All, 1]]/(pointsNumber*dt^2);
ListLinePlot[Transpose@{dftFreq, dftAmp},
PlotRange -> {{0, maxFreq}, All}]

• Thank you! You have answered my question! Apr 23, 2016 at 22:16