/************************************************************************/ /* recog.c 4/10/95 */ /* */ /************************************************************************/ /* This program does all aspects of speech recognition, including */ /* training for the recognition of a finite number of short, */ /* isolated words. After models for each of the words are chosen, */ /* recognition is done by fitting the input pattern to be */ /* classified by choosing the model that produces that pattern */ /* with the highest probability. */ /* */ /* This program defines the port addressses for the */ /* particular input and output channel being used, sets up the */ /* IRQ3 to call the delta-modulation routine, and sets up */ /* an idle wait loop to conserve power while waiting for the */ /* interrupt. */ /* */ /* */ /************************************************************************/ #include <21020.h> /* For the idle() command */ #include /* For the interrupt command */ #include /* For the segment function */ #include #include #include volatile int in_port segment(hip_reg0); /* hip_reg0, hip_reg2, hip_reg3 are */ volatile int out_port segment(hip_reg2);/* used in architecture file */ volatile int out_port2 segment(hip_reg3); static float power[5][10]; static int num_samples = 0; static float samples, sig_pow; static float R_vec[11]; /* autocorrelation vector */ static float R2_vec[10][1]; static float Rmat[10][10]; /* autocorrelation matrix */ static float inv_Rmat[10][10]; static float finalR[10]; /* final autocorrelation vector of a frame */ static float a_vec[10]; /* vector of predictor coefficients */ static float nu; /* learning coefficient for LMS algorithm */ static float sig[10][10][50]; /* where predictor coefficients are saved */ static float mean[6][10][10]; /* means for each state - Gaussian dist. */ static float mean_num[10][10]; /* numerator of eq. to compute the mean */ static float new_mean[10][10]; static float var[6][10][10]; static float var_num[10][10]; /* numerator of eq. to compute variance */ static float denom[10]; /* denom. of eq. to compute mean and variance */ static float new_var[10][10]; static float alpha[10][50]; static float ct[50]; static float beta[10][50]; static float transit[6][10][10]; /* transition matrices for each word */ static float transit_num[10][10]; /* numerator of eq. to compute transitions */ static float transit_den[10]; /* denom. of eq. to comp. transitions */ static float new_transit[10][10]; static float probs[10]; /* probability of each example word */ static int length[10]; /* length of each example */ static int start_word, end_word; static float previous[20]; static int index = 0; static int frame_num = 0; static int word_num = 0; static int end_frame = 0; static int need_update; /* need to update the parameters again? */ static int button = 0; /* * void matinv(float out[][], float in[][], int n); * void matmul(float z[][], float x[][], float y[][], int r, int s, int t); */ void process_input(int); void push_button(int sig_num); void compute_alphas(int word, int example); void compute_betas(int word, int example); float compute_prob(int word, int example); float p_output(int word, int example, int state, int time); void update_params(int word); void main(void) { static int i,j,k,r,c; /* initialize LPC coeffients */ for (i = 0; i < 10; i++) a_vec[i] = 0; nu = 1.0e-11; /* initialize state transition matrices */ for (k = 0; k < 6; k++) for (r = 0; r < 10; r++) { for (c = 0; c < 10; c++) transit[k][r][c] = 0; if (r + 1 > 9) transit[k][r][r] = 1.0; else if (r + 2 > 9) { transit[k][r][r] = 0.5; transit[k][r][r+1] = 0.5; } else { transit[k][r][r] = 0.333; transit[k][r][r+1] = 0.333; transit[k][r][r+2] = 0.333; } } interrupt(SIG_IRQ3, process_input); signal(SIG_IRQ2, push_button); set_flag(SET_FLAG1, CLR_FLAG); set_flag(SET_FLAG2, CLR_FLAG); set_flag(SET_FLAG3, CLR_FLAG); for (i = 0; i < 6; i++) { for (j = 0; j < 10; j++) { /* while (!(button)) { if (end_frame) end_frame = 0; } */ poll_flag_in(READ_FLAG0, FLAG_IN_LO_TO_HI); while ( !(end_frame) ) { } length[j] = 0; /* turn on light */ set_flag(SET_FLAG1, SET_FLAG); while ( time < 50 ) { time++; start_word = 1; end_frame = 0; while ( !(end_frame) ) { } } /* turn off light */ set_flag(SET_FLAG1, CLR_FLAG); button = 0; } void process_input(int sig_number) { float input; num_samples++; input = in_port / 10000; pow = pow + input*input; if (num_samples == 160) { num_samples = 0; pow = 0; for (i = 0; i < 10; i++) { a_vec[i] = 0; } end_frame = 1; } } void push_button(int sig_num) { if (button == 0) button = 1; else button = 0; }