This is the input This is the output Please show me the resu

This is the input

This is the output
Please show me the result of compiling, thank you.
14:57 cs.unh.edu oo AT&T; 61% Purpose The parpose of this assignment is to give you practice with single dimensional arrays as well as modularizing your program with more functions Scenario An acoustical signal can be converted into an electrical signal by a microphone and the electrical signal can then be converted into a series of numbers representing the value of the electrical signal at discrete time intervals. These values have been stored in a data file. We are interested in analyzing this data to measure various aspects of the acoustical signal. Problem Read in a file containing a noise signal and print out several picces of information on the signal. Input The input files consist of a series of a series of floating point numbers representing the acoustical signal You should read these values into an array until end of file or until the array is full, use an array of data type double, of size 1500. Output The output should consist of a neat well labeled message with the following information in this order I. 2 3· 4. 5. 6. 7, 8. Number of sample points The variance The standard deviation Average power Average magnitude Positive count Number of zcro crossings Maximum change index Details leading to computation of each output 1. The number of data points in the sample

Solution

Dear Asker,

Following is the complete code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double mean(double* arr, int num)
{
double result =0;

for(int i =0;i<num;i++)
{
result +=arr[i];
}

return result/num;
}

double variance(double* arr, int num)
{
double result =0;
double m = mean(arr,num);
for(int i =0;i<num;i++)
{
result +=pow(arr[i]-m,2);
}

return result/(num-1);
}

double average_magnitude(double* arr, int num)
{
double result =0;
for(int i =0;i<num;i++)
{
result +=fabs(arr[i]);
}

return result/num;
}

double standard_deviation(double* arr, int num)
{

return sqrt(variance(arr, num));
}


double average_power(double* arr, int num)
{
double result =0;
for(int i =0;i<num;i++)
{
result +=pow(arr[i],2);
}

return result/num;
}


int posive_count(double* arr, int num)
{
int result =0;
for(int i =0;i<num;i++)
{
if(arr[i]>0)
{
result++;
}
}

return result;
}

int zero_crossings(double* arr, int num)
{
int result =0;
for(int i =0;i<num-1;i++)
{
if((arr[i]>=0 && arr[i+1]<0) || (arr[i]<0 && arr[i+1]>=0))
{
result++;
}
}

return result;
}

int max_change_index(double* arr, int num)
{
int result =-1;
double maxDiff = 0;
for(int i =0;i<num-1;i++)
{
if(maxDiff < fabs(arr[i] - arr[i+1]))
{
maxDiff = fabs(arr[i] - arr[i+1]);
result=i;
}
}

return result;
}

int main()
{
double signalArray[1500];
int signalCount=0;
//read the file from
FILE *signalFile = fopen(\"signal.txt\",\"r\");

char line[1000];
  
while(fgets(line, sizeof(line), signalFile) && signalCount <=1500)
{
//printf(\"%d\ \",atof(line));
printf(\"%f\ \",atof(line));
signalArray[signalCount]=(double)atof(line);
signalCount++;
}

//display output
printf(\"Noise Statistics\ \");
printf(\"****************\ \");
printf(\"number of sample points: %d\ \",signalCount);
printf(\"variance :%f\ \",variance(signalArray,signalCount));
printf(\"standard deviation :%f\ \",standard_deviation(signalArray,signalCount));
printf(\"average power :%f\ \",average_power(signalArray,signalCount));
printf(\"average magnitude :%f\ \",average_magnitude(signalArray,signalCount));
printf(\"positive count :%d\ \",posive_count(signalArray,signalCount));
printf(\"zero crossings :%d\ \",zero_crossings(signalArray,signalCount));
printf(\"max change index :%d\ \",max_change_index(signalArray,signalCount));
}

------------------------------------------------------------------------------------------------------------------------------------------------

Following is the complete compilation message:

sh-4.3$ gcc main.c -o main -lm -v

GNU C11 (GCC) version 5.3.1 20151207 (Red Hat 5.3.1-2) (x86_64-redhat-linux)                                                                           

        compiled by GNU C version 5.3.1 20151207 (Red Hat 5.3.1-2), GMP version 6.0.0, MPFR version 3.1.3, MPC version 1.0.2                           

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072                                                                             

ignoring nonexistent directory \"/usr/lib/gcc/x86_64-redhat-linux/5.3.1/include-fixed\"                                                                  

ignoring nonexistent directory \"/usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../../../x86_64-redhat-linux/include\"                                        

#include \"...\" search starts here:                                                                                                                     

#include <...> search starts here:                                                                                                                     

/usr/lib/gcc/x86_64-redhat-linux/5.3.1/include                                                                                                        

/usr/local/include                                                                                                                                    

/usr/include                                                                                                                                          

End of search list.                                                                                                                                    

GNU C11 (GCC) version 5.3.1 20151207 (Red Hat 5.3.1-2) (x86_64-redhat-linux)                                                                           

        compiled by GNU C version 5.3.1 20151207 (Red Hat 5.3.1-2), GMP version 6.0.0, MPFR version 3.1.3, MPC version 1.0.2                           

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072                                                                             

Compiler executable checksum: 571ff51f6ea967378b4ac86e2597003f                                                                                         

COLLECT_GCC_OPTIONS=\'-o\' \'exe\' \'-v\' \'-mtune=generic\' \'-march=x86-64\'                                                                                   

as -v --64 -o /tmp/ccvawnGF.o /tmp/cczkDww4.s                                                                                                         

GNU assembler version 2.25 (x86_64-redhat-linux) using BFD version version 2.25-15.fc23                                                                

COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/5.3.1/:/usr/libexec/gcc/x86_64-redhat-linux/5.3.1/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gc

c/x86_64-redhat-linux/5.3.1/:/usr/lib/gcc/x86_64-redhat-linux/                                                                                         

LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/5.3.1/:/usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/l

ib/gcc/x86_64-redhat-linux/5.3.1/../../../:/lib/:/usr/lib/                                                                                             

COLLECT_GCC_OPTIONS=\'-o\' \'exe\' \'-v\' \'-mtune=generic\' \'-march=x86-64\'                                                                                   

/usr/libexec/gcc/x86_64-redhat-linux/5.3.1/collect2 -plugin /usr/libexec/gcc/x86_64-redhat-linux/5.3.1/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x

86_64-redhat-linux/5.3.1/lto-wrapper -plugin-opt=-fresolution=/tmp/ccBPuqWg.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plug

in-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -

m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o exe /usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-red

hat-linux/5.3.1/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/5.3.1/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/5.3.1 -L/usr/lib/gcc/x86_

64-redhat-linux/5.3.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../.. /tmp/ccvawnGF.o -lm -lgcc

--as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/5.3.1/crtend.o /usr/lib/gcc/x86_64-re

dhat-linux/5.3.1/../../../../lib64/crtn.o

This is the input This is the output Please show me the result of compiling, thank you. 14:57 cs.unh.edu oo AT&T; 61% Purpose The parpose of this assignment
This is the input This is the output Please show me the result of compiling, thank you. 14:57 cs.unh.edu oo AT&T; 61% Purpose The parpose of this assignment
This is the input This is the output Please show me the result of compiling, thank you. 14:57 cs.unh.edu oo AT&T; 61% Purpose The parpose of this assignment
This is the input This is the output Please show me the result of compiling, thank you. 14:57 cs.unh.edu oo AT&T; 61% Purpose The parpose of this assignment

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site