Cov txheej txheem:
- Kauj Ruam 1: Nkag Siab Cov Txheej Txheem
- Kauj ruam 2: Txoj Cai
- Kauj Ruam 3: Schematics
- Kauj ruam 4: Xaus
Video: DTMF Ntes: 4 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:27
Txheej txheem cej luam
Kuv tau tshoov siab los tsim cov cuab yeej no los ntawm kev ua haujlwm hauv tsev ntawm Digital Signal Processing online course. Nov yog DTMF tus lej txiav txim siab siv nrog Arduino UNO, nws pom tus lej nias ntawm lub xov tooj ntawm tus xov tooj hauv lub suab nrov los ntawm lub suab nws tsim tawm.
Kauj Ruam 1: Nkag Siab Cov Txheej Txheem
Hauv DTMF txhua lub cim tau cim nrog ob zaus raws li cov lus ntawm daim duab.
Lub cuab yeej ntes cov tswv yim los ntawm lub microphone thiab suav qhov dav ntawm yim zaus. Ob zaus nrog qhov siab tshaj plaws muab kab thiab kab ntawm cov cim cim.
Kev nrhiav cov ntaub ntawv
Txhawm rau ua qhov ntsuas qhov ntsuas qhov ntsuas yuav tsum raug ntes ntawm qee qhov kev kwv yees tau. Txhawm rau ua tiav qhov no kuv siv dawb-khiav ADC hom nrog qhov siab tshaj plaws (prescaler 128) nws muab tus qauv ntsuas 9615Hz. Cov cai hauv qab no qhia txog yuav teeb tsa Arduino's ADC li cas.
void initADC () {
// Pib ADC; f = (16MHz/prescaler)/13 cycles/conversion ADMUX = 0; // Channel sel, txoj cai-txuas, siv AREF tus pin ADCSRA = _BV (ADEN) | // ADC pab kom _BV (ADSC) | // ADC pib _BV (ADATE) | // Nws pib _BV (ADIE) | // cuam tshuam pab _BV (ADPS2) | _BV (ADPS1) | _BV (ADPS0); // 128: 1/13 = 9615 Hz ADCSRB = 0; // Dawb-khiav hom DIDR0 = _BV (0); // Tua tawm cov tswv yim digital rau ADC tus pin TIMSK0 = 0; // Timer0 tawm} Thiab tus cuam tshuam cuam tshuam zoo li qhov ISR (ADC_vect) {uint16_t qauv = ADC; qauv [qauvPos ++] = qauv - 400; yog (samplePos> = N) {ADCSRA & = ~ _BV (ADIE); // Tsis puv, cuam tshuam tawm}}
Spectrum tsom xam
Tom qab sau cov qauv kuv xam qhov dav ntawm 8 zaus ua cim cim cim. Kuv tsis tas yuav khiav FFT tag nrho rau qhov no, yog li kuv siv Goertzel's algorithm.
tsis muaj dab tsi goertzel (uint8_t *kuaj, ntab *spectrum) {
ntab v_0, v_1, v_2; ntab re, im, amp; rau (uint8_t k = 0; k <IX_LEN; k ++) {ntab c = pgm_read_float (& (cos_t [k]))); ntab s = pgm_read_float (& (sin_t [k])); ntab a = 2. * c; v_0 = v_1 = v_2 = 0; rau (uint16_t i = 0; i <N; i ++) {v_0 = v_1; v_1 = v_2; v_2 = (ntab) (kuaj ) + a * v_1 - v_0; } re = c * v_2 - v_1; im = s * v_2; amp = sqrt (re * re + im * im); spectrum [k] = amp; }}
Kauj ruam 2: Txoj Cai
Daim duab saum toj no qhia qhov piv txwv ntawm kev ntsuas tus lej 3 qhov siab tshaj plaws sib xws rau zaus 697Hz thiab 1477Hz.
Cov duab kos tiav zoo li hauv qab no
/** * Kev Sib Txuas: * [Mic rau Arduino] * - Tawm -> A0 * - Vcc -> 3.3V * - Gnd -> Gnd * - Arduino: AREF -> 3.3V * [Zaub rau Arduino] * - Vcc - > 5V * - Gnd -> Gnd * - DIN -> D11 * - CLK -> D13 * - CS -> D9 */ #include #include
#suav nrog
#define CS_PIN 9
#Txhais N 256
#define IX_LEN 8 #define THRESHOLD 20
LEDMatrixDriver lmd (1, CS_PIN);
uint8_t kuaj [N];
volatile uint16_t samplePos = 0;
ntab spectrum [IX_LEN];
// Zaus [697.0, 770.0, 852.0, 941.0, 1209.0, 1336.0, 1477.0, 1633.0]
// Xeem rau 9615Hz 256 qhov piv txwv yog ntab cos_t [IX_LEN] PROGMEM = {0.8932243011955153, 0.8700869911087115, 0.8448535652497071, 0.8032075314806449, 0.6895405447370669, 0.6343932841636456756,0973,0557,035,0973,0557,0973,0559,0697,0973,0559,0976,0979,0559,0976,0979,0557 const float sin_t [IX_LEN] PROGMEM = {0.44961132965460654, 0.49289819222978404, 0.5349976198870972, 0.5956993044924334, 0.7242470829514669, 0.7730104533627369, 0.8314696123025451, 0.4830, 1354, 0.35, 993, 693, 438, 0.489, 0.489, 1383, 0.489, 0.35, typedef struct {
tus lej; uint8_t qhov ntsuas; } digit_t;
digit_t kuaj pom_digit;
const char table [4] [4] PROGMEM = {
{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', ' C '}, {'*',' 0 ','#',' D '}};
const uint8_t char_indexes [4] [4] PROGMEM = {
{1, 2, 3, 10}, {4, 5, 6, 11}, {7, 8, 9, 12}, {15, 0, 14, 13} };
byte font [16] [8] = {
{0x00, 0x38, 0x44, 0x4c, 0x54, 0x64, 0x44, 0x38}, // 0 {0x04, 0x0c, 0x14, 0x14, 0x24, 0x04, 0x04, 0x04, 0x04}, // 1 {0x00, 0x30, 0x48, 0x04, 0x04, 0x38, 0x40, 0x7c}, // 2 {0x00, 0x38, 0x04, 0x04, 0x04, 0x18, 0x04, 0x44, 0x38}, // 3 {0x00, 0x04, 0x0c, 0x14, 0x24, 0x7e, 0x04, 0x04 }, // 4 {0x00, 0x7c, 0x40, 0x40, 0x78, 0x04, 0x04, 0x38}, // 5 {0x00, 0x38, 0x40, 0x40, 0x78, 0x44, 0x44, 0x38}, // 6 {0x00, 0x7c, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10}, // 7 {0x00, 0x3c, 0x44, 0x44, 0x44, 0x38, 0x44, 0x44, 0x78}, // 8 {0x00, 0x38, 0x44, 0x44, 0xx3, 0x04, 0x04, 0x78}, // 9 {0x00, 0x1c, 0x22, 0x42, 0x42, 0x7e, 0x42, 0x42}, // A {0x00, 0x78, 0x44, 0x44, 0x78, 0x44, 0x44, 0x7c}, / / B {0x00, 0x3c, 0x44, 0x40, 0x40, 0x40, 0x44, 0x7c}, // C {0x00, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x44, 0x78}, // D {0x00, 0x0a, 0x7f, 0x14, 0x28, 0xfe, 0x50, 0x00}, // # {0x00, 0x10, 0x54, 0x38, 0x10, 0x38, 0x54, 0x10} // *};
void initADC () {
// Pib ADC; f = (16MHz/prescaler)/13 cycles/conversion ADMUX = 0; // Channel sel, txoj cai-txuas, siv AREF tus pin ADCSRA = _BV (ADEN) | // ADC pab kom _BV (ADSC) | // ADC pib _BV (ADATE) | // Nws pib _BV (ADIE) | // cuam tshuam pab _BV (ADPS2) | _BV (ADPS1) | _BV (ADPS0); // 128: 1/13 = 9615 Hz ADCSRB = 0; // Dawb-khiav hom DIDR0 = _BV (0); // Tua tawm cov tswv yim digital rau ADC tus pin TIMSK0 = 0; // Timer0 tawm}
tsis muaj dab tsi goertzel (uint8_t *kuaj, ntab *spectrum) {
ntab v_0, v_1, v_2; ntab re, im, amp; rau (uint8_t k = 0; k <IX_LEN; k ++) {ntab c = pgm_read_float (& (cos_t [k]))); ntab s = pgm_read_float (& (sin_t [k])); ntab a = 2. * c; v_0 = v_1 = v_2 = 0; rau (uint16_t i = 0; i <N; i ++) {v_0 = v_1; v_1 = v_2; v_2 = (ntab) (kuaj ) + a * v_1 - v_0; } re = c * v_2 - v_1; im = s * v_2; amp = sqrt (re * re + im * im); spectrum [k] = amp; }}
ntab avg (ntab *a, uint16_t len) {
ntab tau =.0; rau (uint16_t i = 0; i <len; i ++) {result+= a ; } rov tshwm sim / len; }
int8_t get_single_index_above_threshold (ntab *a, uint16_t len, ntab threshold) {
yog (qhov pib <THRESHOLD) {rov qab -1; } int8_t ix = -1; rau (uint16_t i = 0; i threshold) {if (ix == -1) {ix = i; } lwm {xa rov qab -1; }}} rov ix; }
void detect_digit (ntab *spectrum) {
ntab avg_row = avg (spectrum, 4); ntab avg_col = avg (& spectrum [4], 4); int8_t kab = get_single_index_above_threshold (spectrum, 4, avg_row); int8_t col = get_single_index_above_threshold (& spectrum [4], 4, avg_col); yog (kab! = -1 && col! = -1 && avg_col> 200) {kuaj pom_digit.digit = pgm_read_byte (& (rooj [kab ntawv] [col]))); kuaj_digit.index = pgm_read_byte (& (char_indexes [kab] [col])); } lwm tus {kuaj_digit.digit = 0; }}
tsis muaj dabtsis drawSprite (byte* sprite) {
// Lub npog ntsej muag tau siv kom tau txais kab ntawv me ntsis los ntawm kab sib txuas ntawm kab sib tw sprite = B10000000; rau (int iy = 0; iy <8; iy ++) {rau (int ix = 0; ix <8; ix ++) {lmd.setPixel (7 - iy, ix, (bool) (sprite [iy] & daim npog ntsej muag));
// hloov daim npog ntsej muag los ntawm ib lub pixel mus rau sab xis
daim npog = daim npog >> 1; }
// rov pib dua daim npog ntsej muag
daim npog = B10000000; }}
void teeb tsa () {
cli (); initADC (); sib ();
Serial.begin (115200);
lmd.setEnabled (muaj tseeb); lmd.setIntensity (2); lmd.clear (); lmd.display ();
kuaj_digit.digit = 0;
}
unsigned ntev z = 0;
void voj () {
thaum (ADCSRA & _BV (ADIE)); // Tos rau kev ntsuas suab kom ua tiav goertzel (piv txwv, spectrum); detect_digit (spectrum);
yog (kuaj pom_digit.digit! = 0) {
drawSprite (font [kuaj pom_digit.index]); lmd.display (); } yog (z % 5 == 0) {rau (int i = 0; i <IX_LEN; i ++) {Serial.print (spectrum ); Serial.print ("\ t"); } Serial.println (); Serial.println ((int) kuaj pom_digit.digit); } z ++;
samplePos = 0;
ADCSRA | = _BV (ADIE); // Rov pib ua piv txwv cuam tshuam
}
ISR (ADC_vect) {
uint16_t qauv = ADC;
qauv [qauvPos ++] = qauv - 400;
yog (samplePos> = N) {ADCSRA & = ~ _BV (ADIE); // Tsis puv, cuam tshuam tawm}}
Kauj Ruam 3: Schematics
Cov kev sib txuas hauv qab no yuav tsum tau ua:
Mic rau Arduino
Tawm -> A0
Vcc -> 3.3V Gnd -> Gnd
Nws yog qhov tseem ceeb los txuas AREF rau 3.3V
Zaub rau Arduino
Vcc -> 5V
Gnd -> Gnd DIN -> D11 CLK -> D13 CS -> D9
Kauj ruam 4: Xaus
Dab tsi tuaj yeem txhim kho ntawm no? Kuv siv N = 256 qhov piv txwv ntawm tus nqi 9615Hz uas muaj qee qhov kev tawm mus, yog tias N = 205 thiab tus nqi yog 8000Hz ces qhov xav tau zaus ua ke nrog kev txiav txim siab daim phiaj. Rau qhov ADC yuav tsum tau siv nyob rau hauv timer hom ntws.
Pom zoo:
Zigbee Lub Tsev Ntes Ntes Ntes: 8 Kauj Ruam
Zigbee Bed Presence Detector: Rau qee lub sijhawm tam sim no kuv tau nrhiav txoj hauv kev txhawm rau txheeb xyuas thaum peb nyob hauv txaj. Qhov no rau kev siv cov ntaub ntawv no rau hauv Homeassistant. Nrog cov ntaub ntawv no kuv tuaj yeem ua lub tshuab kom kaw lub teeb thaum tsaus ntuj lossis piv txwv qhib lub tswb nrov hauv kuv li
Hnab Ntim Hnab Ntes Ntes Ntes: 7 Kauj Ruam
Pocket Sized Cough Detector: COVID19 yog qhov keeb kwm kis thoob ntiaj teb cuam tshuam rau lub ntiaj teb no phem heev thiab tib neeg tab tom tsim ntau yam cuab yeej tshiab los tawm tsam nrog nws. Peb kuj tseem tau tsim lub tshuab siv tshuaj tua kab mob tsis siv neeg thiab rab phom Thermal rau Kev Ntsuam Xyuas Qhov Tsis Kub. Tod
ESP32 Ntes Ntes Ntes: 5 Kauj Ruam
ESP32 Fall Detector: Kuv xav ua tsaug rau DFRobot rau kev txhawb nqa txoj haujlwm no. Nov yog cov npe uas siv: DFRobot ESP32 ESP-WROOM Module × 1-https://www.dfrobot.com/product-1559.html Silicon Labs CP2102 USB rau UART Choj × 1MCP73831 Li-Ion Charger IC × 1LM317BD2T A
Micro: ntsis Ntes Ntes Ntes Ntes: 3 Kauj Ruam
Micro: ntsis Ntes Ntes Ntes Ntes: Qhov no tsuas yog ib qho piv txwv luv luv rau lub suab nrov ntsuas ntsuas raws qhov micro: me ntsis thiab Pimoroni enviro: ntsis.Qhov microphone ntawm enviro: ntsis pom lub suab qib, thiab los ntawm qhov txiaj ntsig txiaj ntsig txoj haujlwm ntawm 5x5 LED matrix tau suav thiab
Ntws Ntes Ntes Ntes: 11 Kauj Ruam (nrog Duab)
Ntws Ntes Ntes: Tsis txhob cia qhov txhaws txhaws qeeb koj! Rov qab los ntawm peb hnub so, kuv thiab kuv tus poj niam tau xav tsis thoob los ntawm cov dej npog hauv pem teb ntawm peb chav tsev, thiab peb pom tias nws tsis yog dej huv, nws ntws txhua qhov. Tom qab tshem lub qhov dej tawm