# Why ups and downs of amplitude?

Ladies, Gentlemen, Please let me again employee you with my problems. In following program there is only one sinusoid with frequency 256 Hz amplitude 100,000 and phase 0.67 pi rad. Testing frequencies grid is of 1 Hz step, from 0 Hz to 1000 Hz. Output has maximum amplitude 99,221 and phase 0.670561 pi rad at 256 Hz. I regard it okay given errors in accuracy.

But there are ups and downs in pseudo-frequencies amplitude while my understanding about DFT is that they should going upward till 256 Hz and then downward. Why these ups and downs? I remain with regards.

// Grid is created by variables lowTestFreq and testFreqStep
// both of double type, and integer type M.
// In comments are units of variables.

#include <iostream>
#include "math.h"

int main()
{
//Unchanged variables.
double pi = 3.141592653589793; //pure number.
int n = 0; // sample.
double xn = 0; //pure number.
double Re = 0; //pure number.
double Im = 0; //pure number.
double xn_cos = 0; //pure number.
double xn_sin = 0; //pure number.
double testAmpl = 0; // pure number.

//Sampling frequency and samples of segment.
int samplFreq = 50000; // sample/second.
int N = 3000; //sample.

// Existing sinusoid.
double ampl_1 = 100000; //pure number.
double existFreq_1 = 256; // Hz.
double phase_1 = 0.67 * pi; // rad.
double unitAngle_1 = (existFreq_1 / samplFreq) * (2 * pi); // rad/sample.

// Testing grid.
double testFreq = 0; // Hz.
double testUnitAngle = 0; // rad.
double testAngle = 0; //
double lowTestFreq = 0; //Hz.
double testFreqStep = 1; // Hz.
int M = 1000; // pure number.
int m = 0; // pure number.

for (m = 0; m <= M; ++m)
{
testFreq = lowTestFreq + (m * testFreqStep); // Hz.
testUnitAngle = (testFreq / samplFreq) * (2 * pi); // rad/sample.

Re = 0; Im = 0;

for (n = 1; n <= N; ++n)
{
xn = ampl_1 * sin(n * unitAngle_1 + phase_1);

testAngle = n * testUnitAngle;
xn_cos = xn *  cos(testAngle);
xn_sin = xn * -sin(testAngle);

Re += xn_cos;
Im += xn_sin;
}
std::cout << "Test Freq " << testFreq; // Hz.
testAmpl = sqrt(Re * Re + Im * Im) / N * 2; //pure number.
std::cout << "       Test Freq's Ampl: " << testAmpl;
testPhase = atan2 (Im, Re); // rad.
testPhase = testPhase / pi; // pirad.
testPhase = testPhase + 0.5; // pirad. Corrected phase.
std::cout << ",    and its phase: " << testPhase
}
return 0;
}


• Hi! I took the output of your program and plotted it. Hope you like the plots, and I hope they help the question! Mar 4, 2017 at 16:57
• en.m.wikipedia.org/wiki/Spectral_leakage Mar 5, 2017 at 1:16
• @ Marcus Müller. Please accept mu many thanks for your plots. I like them very much. Now I understand ups and downs are expected DFT leakage. I have not read yet about leakage in the book of my dear Teacher Mr Lyons. He teaches me by his book though does not respond my messages. So I address my questions here. Regards. Mar 6, 2017 at 12:18
• @ Jason R. Please accept my many thanks for the helpful address. Plot there is same as Mr. Marcus Müller's. So it is clear ups and downs are leakage. Wikipedia is too rigorous for me. I hope read about and learn from my text book "understand DSP" by Mr. Richard Lyons. Regards. Mar 6, 2017 at 12:24