[an error occurred while processing this directive]
Вариант с экономией памяти. Да и вообще проще получается.
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено Yuriy 21 августа 2002 г. 06:51
В ответ на: Подскажите плиз алгоритм детектирования 1000гц в реальном времени? отправлено Эсперыч 20 августа 2002 г. 15:49

Ниже изложена общая идея. Есть реализация для AVR на ассемблере, но не думаю, что это поможет.


//-------------------------------------------------------------------
// timer2.c
//
// This is just an example.
//
// search for single frequency: 1000 Hz
//
// sampling frequency = 8000 Hz
//
//-------------------------------------------------------------------
#define CORR_LENGTH 200
#define CORR_THRESHOLD 65
//-------------------------------------------------------------------
volatile U8 corr_counter;
volatile U8 corr_complete = 0; // 1 - correlation complete
volatile U8 sin, cos;
//-------------------------------------------------------------------
//
//
interrupt timer_interrupt(void)
{
U8 temp_sin, temp_cos, input;

if(tst_bit(INPUT_BIT)) input = 1;
else input = 0;

temp_sin = corr_counter >> 2; // calculate sin table
temp_cos = (corr_counter >> 2) ^ (corr_counter >> 1); // calculate cos table

sin += (temp_sin ^ input) & 1;
cos += (temp_cos ^ input) & 1;

if (corr_counter >= (CORR_LENGTH)) // get all samples
{
disable_timer_interrupt();
corr_complete = 1; // Set end of single correlation flag
}
corr_counter++;
}
//-------------------------------------------------------------------
U8 search_freq (void)
{
corr_counter = 0;
corr_complete = 0;

start_timer_interrupt(8000);

while (!corr_complete) // wait for end of correlation cycle
;

if (sin > CORR_LENGTH/2) res = sin - CORR_LENGTH/2;
else res = CORR_LENGTH/2 - sin;
pcorr++; // pcorr = sin

if (cos > CORR_LENGTH/2) res += cos - CORR_LENGTH/2;
else res += CORR_LENGTH/2 - cos;
pcorr++; // pcorr = sin + cos

if (res > CORR_THRESHOLD) return 1;

return 0;
}
//-------------------------------------------------------------------



Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru