action recognizer with theremin

Dependencies:   mbed

Committer:
peccu
Date:
Wed Sep 14 13:42:46 2011 +0000
Revision:
0:b9ac53c439ed

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
peccu 0:b9ac53c439ed 1 /*
peccu 0:b9ac53c439ed 2 * lib.cpp
peccu 0:b9ac53c439ed 3 * Theremi
peccu 0:b9ac53c439ed 4 *
peccu 0:b9ac53c439ed 5 * Created by peccu on 11/09/12.
peccu 0:b9ac53c439ed 6 * Copyright 2011 __MyCompanyName__. All rights reserved.
peccu 0:b9ac53c439ed 7 *
peccu 0:b9ac53c439ed 8 */
peccu 0:b9ac53c439ed 9
peccu 0:b9ac53c439ed 10 #include "main.h"
peccu 0:b9ac53c439ed 11 #include "lib.h"
peccu 0:b9ac53c439ed 12
peccu 0:b9ac53c439ed 13 // 配列とかの演算用
peccu 0:b9ac53c439ed 14
peccu 0:b9ac53c439ed 15 // for output
peccu 0:b9ac53c439ed 16 // 配列もどきの操作
peccu 0:b9ac53c439ed 17 int *pushCount(int *count,int size,int newcount){
peccu 0:b9ac53c439ed 18 for(int i=0;i<size-1;i++){
peccu 0:b9ac53c439ed 19 *(count+i)=*(count+i+1);
peccu 0:b9ac53c439ed 20 }
peccu 0:b9ac53c439ed 21 *(count+size-1)=newcount;
peccu 0:b9ac53c439ed 22 return count;
peccu 0:b9ac53c439ed 23 }
peccu 0:b9ac53c439ed 24
peccu 0:b9ac53c439ed 25 // 演算補助
peccu 0:b9ac53c439ed 26 int sum(int *count, int size){
peccu 0:b9ac53c439ed 27 int ret=0;
peccu 0:b9ac53c439ed 28 for(int i=0;i<size;i++){
peccu 0:b9ac53c439ed 29 ret+=(*count++);
peccu 0:b9ac53c439ed 30 }
peccu 0:b9ac53c439ed 31 return ret;
peccu 0:b9ac53c439ed 32 }
peccu 0:b9ac53c439ed 33
peccu 0:b9ac53c439ed 34 float average(int *data, int size){
peccu 0:b9ac53c439ed 35 float ret=0.0;
peccu 0:b9ac53c439ed 36 ret = sum(data,size) / size;
peccu 0:b9ac53c439ed 37 return ret;
peccu 0:b9ac53c439ed 38 }
peccu 0:b9ac53c439ed 39
peccu 0:b9ac53c439ed 40 // 平均がわかってるときの分散
peccu 0:b9ac53c439ed 41 float variance(int *data, float average, int size){
peccu 0:b9ac53c439ed 42 float ret=0.0;
peccu 0:b9ac53c439ed 43 for(int i=0;i<size-1;i++){
peccu 0:b9ac53c439ed 44 ret += (*(data+i)-average) * (*(data+i)-average);
peccu 0:b9ac53c439ed 45 }
peccu 0:b9ac53c439ed 46 ret /= size -1;
peccu 0:b9ac53c439ed 47 return ret;
peccu 0:b9ac53c439ed 48 }
peccu 0:b9ac53c439ed 49
peccu 0:b9ac53c439ed 50 // 平均の計算もする分散
peccu 0:b9ac53c439ed 51 float variance(int *data, int size){
peccu 0:b9ac53c439ed 52 float ret=0.0;
peccu 0:b9ac53c439ed 53 float ave=average(data, size);
peccu 0:b9ac53c439ed 54 for(int i=0;i<size-1;i++){
peccu 0:b9ac53c439ed 55 ret += (*(data+i)-ave) * (*(data+i)-ave);
peccu 0:b9ac53c439ed 56 }
peccu 0:b9ac53c439ed 57 ret /= size -1;
peccu 0:b9ac53c439ed 58 return ret;
peccu 0:b9ac53c439ed 59 }