I have fixed this problem and am now able to print the amount of samples and the maximum amplitude, however I am not sure where to start to put in some code to calculate the RMS value of all of the samples.
Code:
#include <stdio.h>
int main (void)
{
FILE *input1;
int counter = 0;
float total = 0;
int samples;
int i;
float n;
float max_amplitude = 0;
input1 = fopen("data-01.txt", "r");
if (input1 == NULL)
{
fprintf(stderr, "data-01.txt : Can't open file.\n");
}
else
{
while (fscanf(input1, "%f", &n) == 1)
{
total += n;
counter++;
}
fclose(input1);
{
for(i = 0; i < counter; i++)
{
if(n > max_amplitude)
{
max_amplitude = n;
}
}
char data01[20];
sprintf(data01, "%d samples, Amplitude = %f RMS = ", counter, max_amplitude);
printf("%s", data01);
}
}
system("pause");
return 0;
}
do you know how to calculate the RMS value of a large amount of samples?
Thanks
David