int main() { double array[8] = {0,5,5,0,0,5,0,0}; struct signal* p_signal = NULL; int size = sizeof(array)/sizeof(array[0]); p_signal = (struct signal*)malloc(sizeof(struct complex_number)*size + sizeof(p_signal->size)); if(!p_signal) { printf("malloc failed!\n"); return 0; } init_signal(p_signal,array,size); show_signal(p_signal); struct signal* p_output = NULL; p_output = fft(p_signal); show_signal(p_output); free(p_signal); free(p_output); return 0; }
static void show_signals(dbc_t *dbc) { message_list_t *ml; signal_list_t *sl; show_message_header(); show_signal_header(); for(ml = dbc->message_list; ml != NULL; ml = ml->next) { for(sl = ml->message->signal_list; sl != NULL; sl = sl->next) { show_message(ml); putchar(';'); show_signal(sl); putchar('\n'); } } }
/* A signal handler to allow us to output a backtrace. */ void backtrace_handler (int signum) { /* Since this handler is established for more than one kind of signal, it might still get invoked recursively by delivery of some other kind of signal. Use a static variable to keep track of that. */ if (fatal_error_in_progress) raise (signum); fatal_error_in_progress = 1; show_signal (signum); estr_write ("\nBacktrace for this error:\n"); show_backtrace (1); /* Now reraise the signal. We reactivate the signal's default handling, which is to terminate the process. We could just call exit or abort, but reraising the signal sets the return status from the process correctly. */ signal (signum, SIG_DFL); raise (signum); }
struct signal* fft(struct signal* p_signal) { struct signal* p_input_signal = \ (struct signal*) malloc(sizeof(struct complex_number)*(p_signal->size) + sizeof(p_signal->size)); struct signal* p_out_put_signal = \ (struct signal*)malloc(sizeof(struct complex_number)*(p_signal->size) + sizeof(p_signal->size)); *p_input_signal = *p_signal; *p_out_put_signal = *p_signal; int tmp = 0; int index = 0; int bits = 0; int layyer= 0; int selected_point = 0; int pre_half = 0; int r = 0; double x = 0; struct complex_number W_rN ; struct complex_number complex_tmp ; /* ** We caculate how many bits should be used to ** represent the size of the number of input signal. */ for(tmp = p_signal->size-1;tmp > 0;tmp>>=1) { bits++; } /* ** We should re-sequence the input signal ** by bit-reverse. */ for(tmp = 0;tmp < p_signal->size;tmp++) { index = reverse_bits(tmp,bits); p_input_signal->points[tmp] = p_signal->points[index]; #ifdef DEBUG printf(" tmp:%5d index:%5d ",tmp,index); show_complex_number(&p_signal->points[index]); #endif } for(layyer = 1;layyer <= bits;layyer++) { #ifdef DEBUG printf("layyer %d input\n",layyer); show_signal(p_input_signal); #endif for(selected_point = 0;selected_point < p_signal->size;selected_point += 1<<(layyer)) { for(pre_half = selected_point,r = 0,x = 0; pre_half < (selected_point + (1<<(layyer-1))); pre_half++) { r = get_r_in_Wn(pre_half,layyer,bits); #ifdef DEBUG printf("r: %d\n",r); #endif x = -2*PI*r/((double)(p_input_signal->size)); W_rN.real = cos(x); W_rN.imagine = sin(x); complex_tmp = complex_mul(&W_rN , &(p_input_signal->points[pre_half + (1<<(layyer-1))]) ); #ifdef DEBUG show_complex_number(&complex_tmp); #endif p_out_put_signal->points[pre_half] = \ complex_add(&p_input_signal->points[pre_half],&complex_tmp); p_out_put_signal->points[pre_half + (1<<(layyer-1))] = \ complex_sub(&p_input_signal->points[pre_half],&complex_tmp); } } #ifdef DEBUG printf("layyer%d output\n",layyer); show_signal(p_out_put_signal); #endif for(tmp = 0;tmp < p_out_put_signal->size;tmp++) { p_input_signal->points[tmp] = p_out_put_signal->points[tmp]; } } free(p_input_signal); return p_out_put_signal; }
static int show_scope(ivl_scope_t net, void*x) { unsigned idx; const char *is_auto; fprintf(out, "scope: %s (%u parameters, %u signals, %u logic)", ivl_scope_name(net), ivl_scope_params(net), ivl_scope_sigs(net), ivl_scope_logs(net)); is_auto = ivl_scope_is_auto(net) ? "automatic " : ""; switch (ivl_scope_type(net)) { case IVL_SCT_MODULE: fprintf(out, " module %s%s", ivl_scope_tname(net), ivl_scope_is_cell(net) ? " (cell)" : ""); break; case IVL_SCT_FUNCTION: fprintf(out, " function %s%s", is_auto, ivl_scope_tname(net)); break; case IVL_SCT_BEGIN: fprintf(out, " begin : %s", ivl_scope_tname(net)); break; case IVL_SCT_FORK: fprintf(out, " fork : %s", ivl_scope_tname(net)); break; case IVL_SCT_TASK: fprintf(out, " task %s%s", is_auto, ivl_scope_tname(net)); break; default: fprintf(out, " type(%u) %s", ivl_scope_type(net), ivl_scope_tname(net)); break; } fprintf(out, " time units = 1e%d\n", ivl_scope_time_units(net)); fprintf(out, " time precision = 1e%d\n", ivl_scope_time_precision(net)); for (idx = 0 ; idx < ivl_scope_attr_cnt(net) ; idx += 1) { ivl_attribute_t attr = ivl_scope_attr_val(net, idx); switch (attr->type) { case IVL_ATT_VOID: fprintf(out, " (* %s *)\n", attr->key); break; case IVL_ATT_STR: fprintf(out, " (* %s = \"%s\" *)\n", attr->key, attr->val.str); break; case IVL_ATT_NUM: fprintf(out, " (* %s = %ld *)\n", attr->key, attr->val.num); break; } } for (idx = 0 ; idx < ivl_scope_params(net) ; idx += 1) show_parameter(ivl_scope_param(net, idx)); for (idx = 0 ; idx < ivl_scope_enumerates(net) ; idx += 1) show_enumerate(ivl_scope_enumerate(net, idx)); for (idx = 0 ; idx < ivl_scope_sigs(net) ; idx += 1) show_signal(ivl_scope_sig(net, idx)); for (idx = 0 ; idx < ivl_scope_events(net) ; idx += 1) show_event(ivl_scope_event(net, idx)); for (idx = 0 ; idx < ivl_scope_logs(net) ; idx += 1) show_logic(ivl_scope_log(net, idx)); for (idx = 0 ; idx < ivl_scope_lpms(net) ; idx += 1) show_lpm(ivl_scope_lpm(net, idx)); for (idx = 0 ; idx < ivl_scope_switches(net) ; idx += 1) show_switch(ivl_scope_switch(net, idx)); switch (ivl_scope_type(net)) { case IVL_SCT_FUNCTION: case IVL_SCT_TASK: fprintf(out, " scope function/task definition\n"); if (ivl_scope_def(net) == 0) { fprintf(out, " ERROR: scope missing required task definition\n"); stub_errors += 1; } else { show_statement(ivl_scope_def(net), 6); } break; default: if (ivl_scope_def(net)) { fprintf(out, " ERROR: scope has an attached task definition:\n"); show_statement(ivl_scope_def(net), 6); stub_errors += 1; } break; } fprintf(out, "end scope %s\n", ivl_scope_name(net)); return ivl_scope_children(net, show_scope, 0); }