Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sound Sensor TYWu.

Similar presentations


Presentation on theme: "Sound Sensor TYWu."— Presentation transcript:

1 Sound Sensor TYWu

2 Sound Sensor Sound Sensor Module (Made by Seeed)

3 Sound Sensor Schematic D2 is useless

4 Experiments Typical DSP (Digital Signal Processing) System

5 Experiments Echo Arduino System Integrator Arduino Sound Sensor Module
PWM Integrator Arduino Sound Sensor Module

6 Experiments PWM (8bits in Arduino)

7 Experiments PWM

8 Experiments Echo Block Diagram Finite Impulse Response (FIR) Filter

9 Experiments Sketch #define SOUND_INPUT_PIN 0
#define SOUND_OUTPUT_PIN 5 // By PWM #define RECORD_SIZE 500 int sound_record[RECORD_SIZE]; int delay_time_unit = 399; float echo_sound_weight = 0.5; int sensorValue; int cur_idx; int output_sound_value; void setup() { pinMode(SOUND_OUTPUT_PIN, OUTPUT); }

10 Experiments Sketch void loop() {
TCCR0B = TCCR0B & 0b | 0x01; // Modify the Freq. of Pin5 PWM cur_idx++; if(cur_idx >= RECORD_SIZE) cur_idx = 0; sensorValue = analogRead(SOUND_INPUT_PIN); //use A0 to read the electrical signal sound_record[cur_idx] = sensorValue / 4; // > 256 output_sound_value = 0; int j = cur_idx - delay_time_unit; if (j < 0) j = j + RECORD_SIZE; output_sound_value = sound_record[cur_idx] + sound_record[j] * echo_sound_weight; if(output_sound_value > 255) output_sound_value = 255; analogWrite(SOUND_OUTPUT_PIN, output_sound_value); sound_record[cur_idx] = output_sound_value; }

11 Experiments Which one? + sound_record[cur_idx] * echo_sound_weight
output * echo_sound_weight sound_record[cur_idx] + output

12 Experiments FFT Spectrum Library

13 Experiments FFT Spectrum

14 Experiments FFT Spectrum

15 Experiments FFT Spectrum (16*75Hz=1200Hz)

16 Experiments Sketch #include "PCD8544.h" #include <stdint.h>
#include <ffft.h> #define IR_AUDIO 0 // ADC channel to capture PCD8544 nokia = PCD8544(3, 4, 5, 7, 6); volatile byte position = 0; volatile long zero = 0; int16_t capture[FFT_N]; /* Wave captureing buffer */ complex_t bfly_buff[FFT_N]; /* FFT buffer */ uint16_t spektrum[FFT_N/2]; /* Spectrum output buffer */ int pl = 0; void setup() { Serial.begin(57600); adcInit(); adcCalb(); // establishContact(); // send a byte to establish contact until Processing respon nokia.init(); nokia.command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL); nokia.clear(); }

17 Experiments void loop() { int spek_for_draw; if (position == FFT_N)
fft_input(capture, bfly_buff); fft_execute(bfly_buff); fft_output(bfly_buff, spektrum); pl = 0; for (byte i = 0; i < 64; i++){ // Serial.print(spektrum[i],BYTE); if (spektrum[i] > 100) { pl = 1; Serial.print(i, DEC); Serial.print("="); Serial.print(spektrum[i]); //TYWU Serial.print(", "); delay(1); } for (byte i = 1; i < 64; i++){ // Skip 0 Channel spek_for_draw = spektrum[i] / 2.5; // 0/2.5 ~ 255/2.5 if (spek_for_draw > 39) spek_for_draw = 39; nokia.drawline(i+10, 39 - spek_for_draw, i+10, 39, BLACK); nokia.drawstring(5, 5, " "); nokia.display(); // Update Screen nokia.clear(); // Clear Screen for the animation if (pl == 1) Serial.println(" "); position = 0;

18 Experiments void establishContact() {
while (Serial.available() <= 0) { Serial.print('A', BYTE); // send a capital A delay(300); } // free running ADC fills capture buffer ISR(ADC_vect) { if (position >= FFT_N) return; capture[position] = ADC + zero; if (capture[position] == -1 || capture[position] == 1) capture[position] = 0; position++; void adcInit(){ /* REFS0 : VCC use as a ref, IR_AUDIO : channel selection, ADEN : ADC Enable, ADSC : ADC Start, ADATE : ADC Auto Trigger Enable, ADIE : ADC Interrupt Enable, ADPS : ADC Prescaler */ // free running ADC mode, f = ( 16MHz / prescaler ) / 13 cycles per conversion ADMUX = _BV(REFS0) | IR_AUDIO; // | _BV(ADLAR); // ADCSRA = _BV(ADSC) | _BV(ADEN) | _BV(ADATE) | _BV(ADIE) | _BV(ADPS2) | _BV(ADPS1) //prescaler 64 : Hz - 300Hz per 64 divisions ADCSRA = _BV(ADSC) | _BV(ADEN) | _BV(ADATE) | _BV(ADIE) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); // prescaler 128 : 9615 Hz Hz per 64 divisions, better for most music sei(); void adcCalb(){ Serial.println("Start to calc zero"); long midl = 0; // get 2 meashurment at 2 sec // on ADC input must be NO SIGNAL!!! for (byte i = 0; i < 2; i++) position = 0; delay(100); midl += capture[0]; delay(900); zero = -midl/2; Serial.println("Done.");

19 Experiments Cartoon Sound #define SOUND_INPUT_PIN 0
#define SOUND_OUTPUT_PIN 5 // Pin 4 for ATMEGA 1280, Pin 5 for Arduino UNO (for PWM output) #define RECORD_SIZE 100 char sound_record[RECORD_SIZE]; int sensorValue; int write_idx=0, read_idx=1; int output_sound_value; int frequency_type = 25; // 7: 0.75 time, 10: 1 time, 15: 1.5 times, 20: two times, 25: 2.5 times void setup() { pinMode(SOUND_OUTPUT_PIN, OUTPUT); // Serial.begin(9600); }

20 Experiments void loop() { TCCR0B = TCCR0B & 0b11111000 | 0x01;
// Modify the Frequency of Pin5 PWM sensorValue = analogRead(SOUND_INPUT_PIN); //use A0 to read the electrical signal sound_record[write_idx++] = sensorValue >> 2; // > 256 if(write_idx >= RECORD_SIZE) write_idx = 0; //if(write_idx >= RECORD_SIZE / 2) { if(frequency_type >= 10 || (frequency_type ==7 && write_idx % 4 != 0)) { output_sound_value = (sound_record[read_idx - 1] + sound_record[read_idx]) / 2; analogWrite(SOUND_OUTPUT_PIN, output_sound_value); sound_record[read_idx] = sound_record[read_idx++] >> 1; }

21 Experiments if((frequency_type == 15 || frequency_type == 25) && write_idx % 2 == 0) { output_sound_value = (output_sound_value + sound_record[read_idx]) / 2; analogWrite(SOUND_OUTPUT_PIN, output_sound_value); sound_record[read_idx] = sound_record[read_idx++] >> 1; } if(frequency_type >= 20) { sound_record[read_idx++] = output_sound_value >> 1; if(read_idx >= RECORD_SIZE) {read_idx = 1;}


Download ppt "Sound Sensor TYWu."

Similar presentations


Ads by Google