Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FastAnalogIn NVIC_set_all_priorities mbed-dsp mbed
Revision 0:2ccf3099b859, committed 2015-12-01
- Comitter:
- henryclon
- Date:
- Tue Dec 01 01:08:58 2015 +0000
- Child:
- 1:7655383ca5fd
- Commit message:
- Primera versi?n del identificador de tonos DTMF
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FastAnalogIn.lib Tue Dec 01 01:08:58 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/FastAnalogIn/#a9b753c25073
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NVIC_set_all_priorities.lib Tue Dec 01 01:08:58 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/frankvnk/code/NVIC_set_all_priorities/#01504ecd2025
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/arm_const_structs.h Tue Dec 01 01:08:58 2015 +0000
@@ -0,0 +1,86 @@
+/* ----------------------------------------------------------------------
+* Copyright (C) 2010-2013 ARM Limited. All rights reserved.
+*
+* $Date: 17. January 2013
+* $Revision: V1.4.1
+*
+* Project: CMSIS DSP Library
+* Title: arm_const_structs.h
+*
+* Description: This file has constant structs that are initialized for
+* user convenience. For example, some can be given as
+* arguments to the arm_cfft_f32() function.
+*
+* Target Processor: Cortex-M4/Cortex-M3
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* - Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* - Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in
+* the documentation and/or other materials provided with the
+* distribution.
+* - Neither the name of ARM LIMITED nor the names of its contributors
+* may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+* -------------------------------------------------------------------- */
+
+#ifndef _ARM_CONST_STRUCTS_H
+#define _ARM_CONST_STRUCTS_H
+
+#include "arm_math.h"
+#include "arm_common_tables.h"
+
+ const arm_cfft_instance_f32 arm_cfft_sR_f32_len16 = {
+ 16, twiddleCoef_16, armBitRevIndexTable16, ARMBITREVINDEXTABLE__16_TABLE_LENGTH
+ };
+
+ const arm_cfft_instance_f32 arm_cfft_sR_f32_len32 = {
+ 32, twiddleCoef_32, armBitRevIndexTable32, ARMBITREVINDEXTABLE__32_TABLE_LENGTH
+ };
+
+ const arm_cfft_instance_f32 arm_cfft_sR_f32_len64 = {
+ 64, twiddleCoef_64, armBitRevIndexTable64, ARMBITREVINDEXTABLE__64_TABLE_LENGTH
+ };
+
+ const arm_cfft_instance_f32 arm_cfft_sR_f32_len128 = {
+ 128, twiddleCoef_128, armBitRevIndexTable128, ARMBITREVINDEXTABLE_128_TABLE_LENGTH
+ };
+
+ const arm_cfft_instance_f32 arm_cfft_sR_f32_len256 = {
+ 256, twiddleCoef_256, armBitRevIndexTable256, ARMBITREVINDEXTABLE_256_TABLE_LENGTH
+ };
+
+ const arm_cfft_instance_f32 arm_cfft_sR_f32_len512 = {
+ 512, twiddleCoef_512, armBitRevIndexTable512, ARMBITREVINDEXTABLE_512_TABLE_LENGTH
+ };
+
+ const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024 = {
+ 1024, twiddleCoef_1024, armBitRevIndexTable1024, ARMBITREVINDEXTABLE1024_TABLE_LENGTH
+ };
+
+ const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048 = {
+ 2048, twiddleCoef_2048, armBitRevIndexTable2048, ARMBITREVINDEXTABLE2048_TABLE_LENGTH
+ };
+
+ const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096 = {
+ 4096, twiddleCoef_4096, armBitRevIndexTable4096, ARMBITREVINDEXTABLE4096_TABLE_LENGTH
+ };
+
+#endif
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Dec 01 01:08:58 2015 +0000
@@ -0,0 +1,204 @@
+#include "mbed.h"
+#include "NVIC_set_all_priorities.h"
+#include <ctype.h>
+#include "arm_math.h"
+#include "arm_const_structs.h"
+#include "FastAnalogIn.h"
+#include <string>
+
+PwmOut myled(LED_GREEN);
+Serial pc(USBTX, USBRX);
+FastAnalogIn Audio(PTC0);
+
+////Parametros////
+int SAMPLE_RATE_HZ = 4000;
+const int FFT_SIZE = 256;
+
+////Otras Variables////
+const static arm_cfft_instance_f32 *S;
+Ticker samplingTimer;
+float samples[FFT_SIZE*2];
+float magnitudes[FFT_SIZE];
+int sampleCounter = 0;
+//*********//
+
+////Utilidades////
+void printArr(int bigsize, float arr[]){
+ int size = (bigsize/sizeof(arr[0]));
+ pc.printf("\r\n [");
+ int limit = size - 1;
+ for (int i = 0; i < size; i++){
+ i == limit ? pc.printf("%.3f", arr[i]): pc.printf("%.3f ,", arr[i]);
+ }
+ pc.printf("] \n");
+}
+
+int frequencyToBin(float frequency)
+{
+ float binFrequency = float(SAMPLE_RATE_HZ) / float(FFT_SIZE);
+ return int(frequency / binFrequency);
+}
+//*********//
+
+////Sampling////
+
+void samplingCallback()
+{
+ // Read from the ADC and store the sample data
+ samples[sampleCounter] = (1023 * Audio) - 511.0f;
+ // Complex FFT functions require a coefficient for the imaginary part of the input.
+ // Since we only have real data, set this coefficient to zero.
+ samples[sampleCounter+1] = 0.0;
+ // Update sample buffer position and stop after the buffer is filled
+ sampleCounter += 2;
+ if (sampleCounter >= FFT_SIZE*2) {
+ samplingTimer.detach();
+ }
+}
+
+void samplingBegin()
+{
+ // Reset sample buffer position and start callback at necessary rate.
+ sampleCounter = 0;
+ samplingTimer.attach_us(&samplingCallback, 1000000/SAMPLE_RATE_HZ);
+}
+
+bool samplingIsDone()
+{
+ return sampleCounter >= FFT_SIZE*2;
+}
+
+//**********//
+
+//Funciones para DTMF//
+int col1 = frequencyToBin(1209);
+int col2 = frequencyToBin(1336);
+int col3 = frequencyToBin(1477);
+int row1 = frequencyToBin(697);
+int row2 = frequencyToBin(770);
+int row3 = frequencyToBin(852);
+int row4 = frequencyToBin(941);
+string valC1[] = {"1", "4", "7", "*"};
+string valC2[] = {"2", "5", "8", "0"};
+string valC3[] = {"3", "6", "9", "#"};
+
+
+int maxCol(){
+ int col = 0;
+ float max = 0.0;
+ if (magnitudes[col1] > max){
+ max = magnitudes[col1];
+ col = 1;
+ }
+ if(magnitudes[col2] > max){
+ max = magnitudes[col2];
+ col = 2;
+ }
+ if(magnitudes[col3] > max){
+ col = 3;
+ }
+ return col;
+}
+
+int maxRow(){
+ int row = 0;
+ float max = 0.0;
+ if (magnitudes[row1] > max){
+ max = magnitudes[row1];
+ row = 1;
+ }
+ if(magnitudes[row2] > max){
+ max = magnitudes[row2];
+ row = 2;
+ }
+ if(magnitudes[row3] > max){
+ max = magnitudes[row3];
+ row = 3;
+ }
+ if(magnitudes[row4] > max){
+ row = 4;
+ }
+ return row;
+}
+
+string valor(){
+ int R = maxRow() - 1;
+ int C = maxCol();
+ //pc.printf("Las coordenadas son: %i, %i \n", R, C); //debug
+ string salida = "no";
+ switch (C){
+ case 1:
+ salida = valC1[R];
+ break;
+ case 2:
+ salida = valC2[R];
+ break;
+ case 3:
+ salida = valC3[R];
+ break;
+ }
+ return salida;
+}
+//**********//
+
+int main(){
+ myled = 0.999;
+
+ NVIC_set_all_irq_priorities(1);
+ NVIC_SetPriority(UART0_IRQn, 0);
+ // Set up serial port.
+ pc.baud (9600);
+
+ // Begin sampling audio
+ samplingBegin();
+
+ // Init arm_ccft_32
+ switch (FFT_SIZE)
+ {
+ case 16:
+ S = & arm_cfft_sR_f32_len16;
+ break;
+ case 32:
+ S = & arm_cfft_sR_f32_len32;
+ break;
+ case 64:
+ S = & arm_cfft_sR_f32_len64;
+ break;
+ case 128:
+ S = & arm_cfft_sR_f32_len128;
+ break;
+ case 256:
+ S = & arm_cfft_sR_f32_len256;
+ break;
+ case 512:
+ S = & arm_cfft_sR_f32_len512;
+ break;
+ case 1024:
+ S = & arm_cfft_sR_f32_len1024;
+ break;
+ case 2048:
+ S = & arm_cfft_sR_f32_len2048;
+ break;
+ case 4096:
+ S = & arm_cfft_sR_f32_len4096;
+ break;
+ }
+
+ while(true){
+ // Calculate FFT if a full sample is available.
+ if (samplingIsDone()) {
+ // Run FFT on sample data.
+ arm_cfft_f32(S, samples, 0, 1);
+ // Calculate magnitude of complex numbers output by the FFT.
+ arm_cmplx_mag_f32(samples, magnitudes, FFT_SIZE);
+ // Restart audio sampling.
+ samplingBegin();
+ //Correr identificacion de tonos
+
+ printf(valor().c_str());
+ printf("\r\n");
+ }
+
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-dsp.lib Tue Dec 01 01:08:58 2015 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/teams/mbed-official/code/mbed-dsp/#7a284390b0ce
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Dec 01 01:08:58 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b \ No newline at end of file