µSpeech  4.1.2
Speech recognition library
 All Classes Functions Variables Pages
signal.cpp
1 #include "uspeech.h"
2 
3 
7 signal::signal(int port){
8  pin = port;
9  fconstant = F_CONSTANT;
10  econstant = 2;
11  aconstant = 4;
12  vconstant = 6;
13  shconstant = 10;
15  micPowerThreshold = 50;
16  scale = 1;
17 }
22 #ifdef ARDUINO_ENVIRONMENT
23  calib = 0;
24  uint32_t samp=0;
25  for (uint16_t ind=0; ind<10000; ind++) {
26  //acquire background noise
27  samp += analogRead(pin) * scale;
28  }
29  calib = samp/10000;
30 #endif
31 }
36  int i = 0;
37  while ( i < 32){
38 #ifdef ARDUINO_ENVIRONMENT
39  arr[i] = (analogRead(pin)*scale-calib);
40 #endif
41  i++;
42  }
43 
44 }
48 unsigned int signal::power(){
49  unsigned int j = 0;
50  uint8_t i = 0;
51  while(i<32){
52  j+=abs(arr[i]);
53  i++;
54  }
55  return j;
56 }
60 unsigned int signal::complexity(int power){
61  unsigned int j = 0;
62  uint8_t i = 1;
63  while(i<32){
64  j+=abs(arr[i]-arr[i-1]);
65  i++;
66  }
67  //Serial.println(j);
68  return (j*amplificationFactor)/power;
69 }
70 
71 
75 unsigned int signal::maxPower()
76 {
77  int i =0;
78  unsigned int max = 0;
79  while (i<32){
80  if(max<abs(arr[i])){
81  max = abs(arr[i]);
82  maxPos = i;
83  }
84  i++;
85  avgPower+=arr[i];
86  }
87  avgPower /= 32;
88  return max;
89 }
90 int signal::snr(int power){
91  uint8_t i=0,j=0;
92  int mean =power/32;
93  while(i <32){
94  j+=sq(arr[i]-mean);
95  i++;
96  }
97  return sqrt(j/mean)/power;
98 }
int vconstant
Definition: uspeech.h:35
unsigned int power()
Definition: signal.cpp:48
int arr[32]
Definition: uspeech.h:28
unsigned int maxPower()
Definition: signal.cpp:75
int econstant
Definition: uspeech.h:33
void calibrate()
Definition: signal.cpp:21
int amplificationFactor
Definition: uspeech.h:38
int aconstant
Definition: uspeech.h:34
int micPowerThreshold
Definition: uspeech.h:39
int shconstant
Definition: uspeech.h:36
signal(int port)
Definition: signal.cpp:7
int fconstant
Definition: uspeech.h:32
void sample()
Definition: signal.cpp:35