Question

/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/ /*    */ /* */ /* This program computes average power, average magnitude */ /*...

/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/*    */
/* */
/* This program computes average power, average magnitude */
/* and zero crossings from a speech signal. */

#include <stdio.h>
#include <math.h>
#define MAXIMUM 50

int main(void)
{
/* Declare variables */
int k=0, npts=30;
double speech[MAXIMUM]={0.000000,-0.023438,-0.031250,-0.031250,-0.039063,-0.039063,-0.023438,0.000000,0.023438,0.070313,-0.039063,-0.039063,0.046875,0.101563,0.117188,0.101563,0.070313,0.054688,0.023438,0.000000,-0.031250,-0.039063,-0.070313,-0.070313,-0.070313,-0.070313,-0.062500,-0.046875,-0.039063,-0.031250};
/* Declare the function prototypes */

  

/* Compute and print statistics. */
printf("\n SPEECH DATA ");
print(,,);//complete the statement
printf("\n");
printf(" SPEECH STATISTICS : \n");
printf(" average power: %f \n",);//complete the statement
printf(" average magnitude: %f \n",);//complete the statement
printf(" zero crossings: %d \n",);//complete the statement


/* Exit program. */
return 0;
}

/* This function prints the data in the number of desired */
/* column numcols */
void print(double x[], int npts, int numcols)
{
int i,j;
printf("\n ");
for(j=0;j<numcols;j++)
   printf("-----------");
printf("\n");
for(j=0;j<numcols;j++)
{
   printf(" %2d to %2d",((npts/numcols)*j)+1,((npts/numcols)*j)+(npts/numcols));
}
printf("\n ");
for(j=0;j<numcols;j++)
   printf("-----------");
printf("\n");
for(i=0;i<npts/numcols;i++)
{
   for(j=0;j<numcols;j++)
       printf("%11.6lf",x[((npts/numcols)*j)+i]);
   printf("\n");
}
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This function returns the average power of an array x */
/* with npts elements. */

double ave_power(double x[],int npts)
{
/* Declare and initialize variables. */
int k;
double sum=0;

/* Determine average power. */
for (k=0; k<=npts-1; k++)
sum += x[k]*x[k];

/* Return average power. */
return sum/npts;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This function returns the average magnitude of an array x */
/* with npts elements. */

double ave_magn(double x[],int npts)
{
/* Declare and initialize variables. */
int k;
double sum=0;

/* Determine average power. */
for (k=0; k<=npts-1; k++)
sum += fabs(x[k]);

/* Return average magnitude. */
return sum/npts;
}


/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This function returns a count of the number of zero */
/* crossings in an array x with npts values. */

int crossings(double x[],int npts)
{
/* Declare and initialize variables. */
int count=0, k;

/* Determine number of zero crossings. */
for (k=0; k<=npts-2; k++)
if (x[k]*x[k+1] < 0)
count++;

/* Return number of zero crossings. */
return count;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <math.h>
#define MAXIMUM 50
void print(double x[], int npts, int numcols);
double ave_power(double x[],int npts);
double ave_magn(double x[],int npts);
int crossings(double x[],int npts);

int main(void)
{
  
   /* Declare variables */
   int k=0, npts=30;
   int i=0;
   double speech[MAXIMUM]={0.000000,-0.023438,-0.031250,-0.031250,-0.039063,-0.039063,-0.023438,0.000000,0.023438,0.070313,-0.039063,-0.039063,0.046875,0.101563,0.117188,0.101563,0.070313,0.054688,0.023438,0.000000,-0.031250,-0.039063,-0.070313,-0.070313,-0.070313,-0.070313,-0.062500,-0.046875,-0.039063,-0.031250};
   /* Declare the function prototypes */


   /* Compute and print statistics. */
   printf("\n SPEECH DATA ");
   print(speech,npts,5);
   printf("\n");
  
  
   printf(" SPEECH STATISTICS : \n");
   printf(" average power: %f \n",ave_power(speech,npts));//complete the statement
   printf(" average magnitude: %f \n",ave_magn(speech,npts));//complete the statement
   printf(" zero crossings: %d \n",crossings(speech,npts));//complete the statement


   /* Exit program. */
   return 0;
}

/* This function prints the data in the number of desired */
/* column numcols */
void print(double x[], int npts, int numcols){  
   int i,j;
   printf("\n ");
   for(j=0;j<numcols;j++)
        printf("-----------");
   printf("\n");
  
   for(j=0;j<numcols;j++){
        printf(" %2d to %2d",((npts/numcols)*j)+1,((npts/numcols)*j)+(npts/numcols));
   }
   printf("\n ");
   for(j=0;j<numcols;j++)
        printf("-----------");
   printf("\n");
   for(i=0;i<npts/numcols;i++){
       for(j=0;j<numcols;j++)
           printf("%11.6lf",x[((npts/numcols)*j)+i]);
        printf("\n");
   }
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This function returns the average power of an array x */
/* with npts elements. */

double ave_power(double x[],int npts)
{
   /* Declare and initialize variables. */
   int k;
   double sum=0;

   /* Determine average power. */
   for (k=0; k<=npts-1; k++)
       sum += x[k]*x[k];

   /* Return average power. */
   return sum/npts;
}
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This function returns the average magnitude of an array x */
/* with npts elements. */

double ave_magn(double x[],int npts)
{
   /* Declare and initialize variables. */
   int k;
   double sum=0;

   /* Determine average power. */
   for (k=0; k<=npts-1; k++)
       sum += fabs(x[k]);

   /* Return average magnitude. */
   return sum/npts;
}


/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
/* This function returns a count of the number of zero */
/* crossings in an array x with npts values. */

int crossings(double x[],int npts)
{
   /* Declare and initialize variables. */
   int count=0, k;

   /* Determine number of zero crossings. */
   for (k=0; k<=npts-2; k++){
       if ((x[k]*x[k+1]) < 0)
           count++;
   }
  

   /* Return number of zero crossings. */
   return count;
}

//###############################################################################

OUTPUT
###########
CAUsersUijinAW Documents)DevC++_WorkspacelSpeech.exe еес SPEECH DATA 1 to 6 7 to 12 13 to 18 19 to 24 25 to 30 SPEECH STATIST

Add a comment
Know the answer?
Add Answer to:
/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/ /*    */ /* */ /* This program computes average power, average magnitude */ /*...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1- Correct the syntax errors in the following program, and rewrite the program so that it...

    1- Correct the syntax errors in the following program, and rewrite the program so that it follows the proper style conventions. What does the program do? (Write it out as a comment). (10 pts) #include <stdio.h> int main() {/* * Calculate and display the difference of two values *) int X, /* first input value */ x, /* second input value */ sum; /* sum of inputs */ X=9, x=7.5 X + x = sum; printf("%d + %d = %d\n";...

  • Please change this 2 thread program to a 4 thread program. /*compile as "gcc thread.c -pthread"...

    Please change this 2 thread program to a 4 thread program. /*compile as "gcc thread.c -pthread" */ #include <pthread.h> #include <stdio.h> #include <time.h> #define SIZE 100000000 //100 M //#define SIZE 10000 #define NUMBER_OF_TIMES 100 float a[SIZE]; typedef struct {        int start;        int end;        double sum;        int pid;    } range; void *thread_function(void *arg) //define a function that will be executed from //within a thread {    range *incoming = (range *) arg;...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

  • Please I need help in C language, I am trying to modify the code per the...

    Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions:                  1.      First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....

  • Modify the program pls so it then asks the user for another input making the program ask for a ye...

    modify the program pls so it then asks the user for another input making the program ask for a yes or no question looping it codeblocks #include <stdio.h> #include <ctype.h> #define NEWLINE '\n' int main(void) {    /* Declare variables and function prototypes. */    int k=0, formula[20], n, current=0, done=0, d1, d2;    double error=0, weight, total=0;    double atomic_wt(int atom);    /* Read chemical formula from keyboard. */    printf("Enter chemical formula for amino acid: \n");    while ((formula[k]=getchar()) != NEWLINE)       k++;    n = k;   ...

  • I'm having trouble sorting this square matrix (a 2d array that has number of rows and...

    I'm having trouble sorting this square matrix (a 2d array that has number of rows and same number of column n x n) using row-wise approach in C programming. Please help me program this in C to sort it using row-wise approach, here is the code: #include <stdio.h> #define MAX 100 int main() { int mat[MAX][MAX]; int i, j, m, n; int rowsum, columnsum, diagonalsum; int k; int magic = 0; int transpose[MAX][MAX]; printf("Enter the # of rows and columns...

  • I need the pseudocode for this c program source code. #include<stdio.h> void printarray(int array[], int asize){...

    I need the pseudocode for this c program source code. #include<stdio.h> void printarray(int array[], int asize){ int i; for(i = 0; i < asize;i++) printf("%d", array[i]); printf("\n"); } int sum(int array[], int asize){ int result = 0; int i = 0; for(i=0;i < asize;i++){ result = result + array[i]; } return result; } int swap( int* pA,int*pB){ int result = 0; if(*pA > pB){ int tamp = *pA; *pA = *pB; *pB = tamp; result = 1; } return result;...

  • C Programming: Write a program that inputs two strings that represent floating-point values, convert the strings...

    C Programming: Write a program that inputs two strings that represent floating-point values, convert the strings to double values. Calculate the sum,difference,and product of these values and print them. int main(){    // character string value array for user    char stringValue[10];       double sum=0.0;// initialize sum to store the results from 2 double values       double difference=0.0; // initialize difference to store the results from 2 double values       double product = 0.0; // intitialzie product...

  • this program is in C. Write a program that computes the number of elements in an...

    this program is in C. Write a program that computes the number of elements in an array divisible by a user specified number. Declare an integer array of size 7 and read the array elements from the user. Then, read a number k from the user and compute the number of elements in the array divisible by k. Consider the following example. 3 elements in this array are divisible by 2 ({2,2,4}). Sample execution of the program for this array...

  • C program. Using do-while loop for this question. Question: write a program to calculate the average...

    C program. Using do-while loop for this question. Question: write a program to calculate the average of first n numbers. output: Enter the value of n : 18 The sum of first 18 numbers =171 The average of first 18 numbers = 9.00 my code couldn't give me the right avg and sum. Please help. #include<stdio.h> int main() {     int num;     int count =0;     int sum=0;     float avg;      printf("Enter the value of n: ");    ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT