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.
Fork of DSP_200kHz by
Jareds_DSP/demodulate.cpp
- Committer:
- baxterja
- Date:
- 2017-06-06
- Revision:
- 78:10b2916b8f5c
- Parent:
- 75:8bb94685c80b
- Child:
- 81:30d699e951a8
- Child:
- 84:5b4466dd2326
File content as of revision 78:10b2916b8f5c:
#include "demodulate.h"
#define MAX_NUMBER_DEMOD_FREQ 2
#define DEMOD_EXTRA_TABLE_LENGTH 16
#define TWOPI 6.28318530717959
float *imod[MAX_NUMBER_DEMOD_FREQ];
float *qmod[MAX_NUMBER_DEMOD_FREQ];
float demod_Carrier_Frequency[MAX_NUMBER_DEMOD_FREQ] = {200,1000};
float demod_Table_Length[MAX_NUMBER_DEMOD_FREQ] = {125,25};
float demod_Sample_Frequency[MAX_NUMBER_DEMOD_FREQ] = {12500,12500};
void precompute_tables()
{
static bool precomputed = false;
if (precomputed)
{
printf("TABLES HAVE ALREADY BEEN PRECOMPUTED");
return;
}
precomputed = true;
for (int i = 0; i<MAX_NUMBER_DEMOD_FREQ; i++)
{
int table_size = demod_Table_Length[i]+DEMOD_EXTRA_TABLE_LENGTH;
imod[i] = new float[table_size];
qmod[i] = new float[table_size];
for(int precompute_counter = 0; precompute_counter < demod_Table_Length[i]+DEMOD_EXTRA_TABLE_LENGTH; precompute_counter++)
{
imod[i][precompute_counter] = ( cos(TWOPI * demod_Carrier_Frequency[i] / demod_Sample_Frequency[i] * precompute_counter));
qmod[i][precompute_counter] = (-sin(TWOPI * demod_Carrier_Frequency[i] / demod_Sample_Frequency[i] * precompute_counter));
}
}
}
void demodulate(float *samples[MAX_NUMBER_OF_FILTERS], int num_filters, int sample_length, int demodulation_frequency)
{
static int demod_counters[MAX_NUMBER_DEMOD_FREQ] = {0,0};
if (demod_counters[demodulation_frequency]>=demod_Table_Length[demodulation_frequency])
{
demod_counters[demodulation_frequency]-=demod_Table_Length[demodulation_frequency];
}
for(int i = num_filters-1; i>=0; i--)
{
//important keep in this order or filter 0 will be odd
//multiply by -sin
arm_mult_f32(qmod[demodulation_frequency]+demod_counters[demodulation_frequency], samples[i], samples[2*i+1], sample_length);
//multiply by cos
arm_mult_f32(imod[demodulation_frequency]+demod_counters[demodulation_frequency], samples[i], samples[2*i], sample_length);
}
demod_counters[demodulation_frequency] +=sample_length;//increment counter
}

