0

Following program outputs sum of samples of signal's period. Values in program are:

Sample rate 96 ksamples/sec.
First frequency (fundamental, 1st harmonic) 96 Hz.
Second frequency (2nd harmonic) 192 Hz.
n = 1 to 1000, representing one (the first) period of the signal.

Output (sum of period's samples) should be zero. Actually is 18.4062, apparently due to round off errors. In general, when samples are multiple of fundamental's (in this example: 2000, 3000, ... samples), sum is least. Other sums are much greater. So first harmonic is represented by the first least sum. I have some question about, but first of all, I have to ask whether this process belongs to DSP domain.

// Outputs sum of input values.

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

int main()
{
//Unchanged variables.
float pi = 3.141592653589793; //pure number.
int n = 0; // sample.
float xn = 0; //pure number.
float xn_cos = 0; //pure number.
float xn_sin = 0; //pure number.
float sum = 0;

//Sampling frequency and samples of segment.
int samplFreq = 96000; // sample/second.

// 1st existing sinusoidal.
float ampl_1 = 70000; //pure number.
float existFreq_1 = 96; // Hz.
float phase_1 = 0.67 * pi; // rad.
float unitAngle_1 = (existFreq_1 / samplFreq) * (2 * pi); // rad/sample.

// 2nd existing sinusoidal.
float ampl_2 = 600000; // pure number.
float existFreq_2 = 192; // Hz.
float phase_2 = -0.37 * pi; // rad.
float unitAngle_2 = (existFreq_2 / samplFreq) * (2 * pi); // rad/sample.

for (n = 1; n <= 1000; ++n)
{
xn = ampl_1 * sin(n * unitAngle_1 + phase_1)
   + ampl_2 * sin(n * unitAngle_2 + phase_2);
sum += xn;
}
 std::cout << sum;
return 0;
}
  • Do you get a more precise result if you reduce the sampling frequency to a smaller value, such as (for example) 960 Hz (10 times the fundamental)? – MBaz May 06 '17 at 15:41
  • @ MBaz: As I point out in my answer accuracy is higher when ratio sample rate/fundFreq is higher. Regards. – George Theodosiou May 08 '17 at 07:22

1 Answers1

1

Ladies, Gentlemen,

Please let me say that my answer is wrong on that lower (first) frequency is represented by first least sum. By trial and error I found that lowest frequency is represented by the fourth (absolutely) least sum, indeed given that existing frequencies are two. I apologize. However, I have solved my problem and do not need any other question. My answer to my question is that this process is DSP, but I ask Messrs Administrators view so that if I have any other question about this method, ask it here.

Following C++ program outputs sums of input values (xn) and you can see that 4th least sum represents first (fundamental) existing frequency. You can change values on the condition second existing frequency be double the first. Example values are: sample rate 96000 ksamples/sec, 1st existing freq = 100 Hz, represented by 960 samples, 2nd = 200 Hz, represented by 480 samples, n = 1 to 1970 with step 11. Fourth least sum (138131) represents 1O1.373 Hz. Next frequency, 100.209 Hz, with sum -357858, is the nearest to 100 Hz. Obviously there is accuracy error. However for step n = 1, fourth absolutely least sum is -7.40625 representing 100 Hz. Eighth least sum represents half the 1st frequency, 50 Hz. I point out that in detecting fundamental frequency of periodic signal by this method, precise is high when ratio sample rate/fundFreq is high, in opposite to method by DFT where results are bad when ratio samplFreq/existFreq is too high.

With regards and friendsip.

// Outputs sum of input values.

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

int main()
{
//Unchanged variables.
float pi = 3.141592653589793; //pure number.
float n = 0; // sample.
float xn = 0; //pure number.
float xn_cos = 0; //pure number.
float xn_sin = 0; //pure number.
float sum = 0;

//Sampling frequency and samples of segment.
int samplFreq = 96000; // sample/second.

// 1st existing sinusoidal.
float ampl_1 = 70000; //pure number.
float existFreq_1 = 100; // Hz.
float phase_1 = 0.67 * pi; // rad.
float unitAngle_1 = (existFreq_1 / samplFreq) * (2 * pi); // rad/sample.

// 2nd existing sinusoidal.
float ampl_2 = 600000; // pure number.
float existFreq_2 = 200; // Hz.
float phase_2 = -0.37 * pi; // rad.
float unitAngle_2 = (existFreq_2 / samplFreq) * (2 * pi); // rad/sample.

for (n = 1; n <= 1970; n)
{
xn = ampl_1 * sin(n * unitAngle_1 + phase_1)
   + ampl_2 * sin(n * unitAngle_2 + phase_2);
sum += xn;
std::cout << samplFreq/n << "       " << sum << "\n";
n += 11;
}
return 0;
}