Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

preamble detection #86

Closed
Terrasfear opened this issue Nov 14, 2020 · 2 comments
Closed

preamble detection #86

Terrasfear opened this issue Nov 14, 2020 · 2 comments
Assignees

Comments

@Terrasfear
Copy link
Collaborator

Terrasfear commented Nov 14, 2020

function prototype to give a matching-score for the preamble

q15_t preamble_match(q15_t* mic_buffer)
{
	int16_t ADC_buffer_size_short
	int16_t preamble_sample_length = ADCBUFFERSIZE_SHORT;
	q15_t preamble_sample [preamble_sample_length] = {sinus ....}

	q15_t multiplication_array [ADC_buffer_size_short];
	q15_t correlation_output;
	q15_t absolute_correlation_output;
	q15_t match_score = 0;

	for( int16_t i = 0; i < 1/2 * preamble_sample_wave_length_samples; i++)
	{
		arm_mult_q15(mic_buffer, preamble_sample + i, multiplication_array, ADCBUFFERSIZE_SHORT);
		
		for( int16_t j = 0; j < ADCBUFFERSIZE_SHORT; j++)
		{
			arm_add_q15(&correlation_output, &multiplication_array, &correlation_output, 1);
		}
		
		arm_abs_q15(&correlation_output, &absolute_correlation_output, 1);
		
		if (absolute_correlation_output > match_score)
		{
		    match_score = absolute_correlation_output;
		}

		// Optimally calculate what we need to know
		if (absolute_correlation_output > match_score)
		{
		      match_score = absolute_correlation_output;
		}
		return match_score;
	}
}
@Terrasfear
Copy link
Collaborator Author

Terrasfear commented Nov 14, 2020

bool signal_preamble_detector(q15_t* mic_buffer, uint32_t* detection_history)
{
	q15_t match_score;
	uint16_t match_success;
	uint16_t succesfull_detections;
	
	match_score = preamble_match(mic_buffer);
	
	*detection_history = *detection_history >> 1; // shift history
	
	match_success = match_score >= match_threshold;
	*detection_history = *detection_history | (match_success << HISTORY_LENGTH);
	
	succesfull_detections = hamming_weight(*detection_history);
	
	return (succesfull_detections >= DETECTION_THRESHOLD);
}

uint16_t hamming_weight(uint32_t N)
{
    uint16_t result;
    while(N)
    {
        result++;
        N &=N-1;
    }
    return result;
}

@davidzwa
Copy link
Owner

Done: 3kHz carrier

#94

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants