Beispiel #1
0
int main ( void )
{
	// Number of samples per spike
	int n = 64;
	// Number of spikes in file
	int spike_t =507 ;
	// File with input spikes
	char *samp_filename = "spikes.csv";
	// File with output coefficients
	char *coeff_filename = "coefficients.csv";

	//Puse manualmente enumero de spikes, pero deberia calcularse o ser un input
	float *wavelets = 0;
	// Allocate memory for the array which is going to contain the samples and coefficients
	// The array has size n*spike_t. The data is going to be orderd per spike (eg. first n floats represent one spike)
	wavelets = (float*)malloc(sizeof(float)*n*spike_t);

	// Read file and load values in array
	read_spikes ( samp_filename, wavelets, n);

	// Calculate inplace haar wavelet transform spike per spike
        calculate_transform ( wavelets, n, spike_t );

	// Print the calculated coefficients
	print_spikes ( coeff_filename, wavelets, n, spike_t );

	// Free memory
	free(wavelets);

	return 0;
}
int
main(int argc, char* argv[])
{
    int err = EXIT_FAILURE;

    struct cmd_line cmd_line;

    setlocale(LC_ALL, "");

    if (parse_cmd_line(argc, argv, &cmd_line) < 0)
        goto arg_check_failed;

    const double cpu_mhz = get_cpu_mhz();
    if (cpu_mhz < 0)
        goto get_cpu_mhz_failed;

    const double cycles_per_ns = cpu_mhz / 1e3;
    const double cycles_limit = cycles_per_ns * cmd_line.limit_ns;

    size_t spikes_count = 0;

    struct spike * spikes = calloc(1000, sizeof(struct spike));
    if (! spikes) {
        fprintf(stderr, "Failed to allocate spikes %s\n",
                strerror(errno));
        goto calloc_failed;
    }

    struct timestamp initial_timestamp;
    read_timestamp_counter(&initial_timestamp);

    struct timestamp t[2];
    read_timestamp_counter(&t[0]);

    size_t i;
    for (i = 1; i < cmd_line.iteration_count; ++ i)
    {
        read_timestamp_counter(&t[i % 2]);
        uint64_t diff = diff_timestamps(&t[(i - 1) % 2], &t[i % 2]);
        if (diff > cycles_limit)
        {
            spikes[spikes_count].cycles_delta = diff;
            memcpy(&spikes[spikes_count].timestamp,
                   &t[i % 2], sizeof(struct timestamp));
            ++ spikes_count;

            if (spikes_count == MAX_SPIKES)
            {
                print_spikes(spikes, spikes_count,
                             cycles_per_ns, &initial_timestamp);
                spikes_count = 0;
            }

            read_timestamp_counter(&t[ i % 2]);
        }
    }

    print_spikes(spikes, spikes_count,
                 cycles_per_ns, &initial_timestamp);

    const double cycles_per_ms = cpu_mhz * 1e3;

    fprintf(stdout, "Iterations count: %'zu\n"
                    "Sampling duration: %'.0lf ms\n"
                    "Detected frequency: %.0lf Mhz\n",
                    cmd_line.iteration_count,
                    cycle_since_timestamp(&initial_timestamp) / cycles_per_ms,
                    cpu_mhz);

    err = EXIT_SUCCESS;

    free(spikes);
calloc_failed:
get_cpu_mhz_failed:
arg_check_failed:
    return err;
}