From a9b0f204b15155b29aa170122b9c2160bf89c121 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Grondin?= Date: Mon, 3 Jul 2017 15:21:53 -0400 Subject: [PATCH] Add files via upload --- src/system/frame2freq.c | 51 +++++++ src/system/frame2freq.h | 30 ++++ src/system/frame2hop.c | 67 ++++++++ src/system/frame2hop.h | 26 ++++ src/system/freq2frame.c | 51 +++++++ src/system/freq2frame.h | 30 ++++ src/system/freq2freq.c | 259 +++++++++++++++++++++++++++++++ src/system/freq2freq.h | 35 +++++ src/system/freq2xcorr.c | 53 +++++++ src/system/freq2xcorr.h | 28 ++++ src/system/gain2mask.c | 44 ++++++ src/system/gain2mask.h | 24 +++ src/system/hop2frame.c | 59 ++++++++ src/system/hop2frame.h | 26 ++++ src/system/hop2hop.c | 232 ++++++++++++++++++++++++++++ src/system/hop2hop.h | 54 +++++++ src/system/kalman2coherence.c | 171 +++++++++++++++++++++ src/system/kalman2coherence.h | 57 +++++++ src/system/kalman2kalman.c | 216 ++++++++++++++++++++++++++ src/system/kalman2kalman.h | 59 ++++++++ src/system/mixture2mixture.c | 230 ++++++++++++++++++++++++++++ src/system/mixture2mixture.h | 33 ++++ src/system/particle2coherence.c | 68 +++++++++ src/system/particle2coherence.h | 23 +++ src/system/particle2particle.c | 260 ++++++++++++++++++++++++++++++++ src/system/particle2particle.h | 56 +++++++ src/system/shift2freq.c | 68 +++++++++ src/system/shift2freq.h | 28 ++++ src/system/track2gain.c | 88 +++++++++++ src/system/track2gain.h | 27 ++++ src/system/track2shift.c | 58 +++++++ src/system/track2shift.h | 23 +++ src/system/xcorr2aimg.c | 50 ++++++ src/system/xcorr2aimg.h | 25 +++ src/system/xcorr2xcorr.c | 85 +++++++++++ src/system/xcorr2xcorr.h | 26 ++++ 36 files changed, 2720 insertions(+) create mode 100644 src/system/frame2freq.c create mode 100644 src/system/frame2freq.h create mode 100644 src/system/frame2hop.c create mode 100644 src/system/frame2hop.h create mode 100644 src/system/freq2frame.c create mode 100644 src/system/freq2frame.h create mode 100644 src/system/freq2freq.c create mode 100644 src/system/freq2freq.h create mode 100644 src/system/freq2xcorr.c create mode 100644 src/system/freq2xcorr.h create mode 100644 src/system/gain2mask.c create mode 100644 src/system/gain2mask.h create mode 100644 src/system/hop2frame.c create mode 100644 src/system/hop2frame.h create mode 100644 src/system/hop2hop.c create mode 100644 src/system/hop2hop.h create mode 100644 src/system/kalman2coherence.c create mode 100644 src/system/kalman2coherence.h create mode 100644 src/system/kalman2kalman.c create mode 100644 src/system/kalman2kalman.h create mode 100644 src/system/mixture2mixture.c create mode 100644 src/system/mixture2mixture.h create mode 100644 src/system/particle2coherence.c create mode 100644 src/system/particle2coherence.h create mode 100644 src/system/particle2particle.c create mode 100644 src/system/particle2particle.h create mode 100644 src/system/shift2freq.c create mode 100644 src/system/shift2freq.h create mode 100644 src/system/track2gain.c create mode 100644 src/system/track2gain.h create mode 100644 src/system/track2shift.c create mode 100644 src/system/track2shift.h create mode 100644 src/system/xcorr2aimg.c create mode 100644 src/system/xcorr2aimg.h create mode 100644 src/system/xcorr2xcorr.c create mode 100644 src/system/xcorr2xcorr.h diff --git a/src/system/frame2freq.c b/src/system/frame2freq.c new file mode 100644 index 0000000..beb8253 --- /dev/null +++ b/src/system/frame2freq.c @@ -0,0 +1,51 @@ + + #include "frame2freq.h" + + frame2freq_obj * frame2freq_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize) { + + frame2freq_obj * obj; + + obj = (frame2freq_obj *) malloc(sizeof(frame2freq_obj)); + + obj->frameSize = frameSize; + obj->halfFrameSize = halfFrameSize; + + obj->win = windowing_roothann(frameSize); + obj->frame = (float *) malloc(sizeof(float) * frameSize); + memset(obj->frame, 0x00, sizeof(float) * frameSize); + obj->fft = fft_construct(frameSize); + + return obj; + + } + + void frame2freq_destroy(frame2freq_obj * obj) { + + window_destroy(obj->win); + free((void *) obj->frame); + fft_destroy(obj->fft); + + free((void *) obj); + + } + + void frame2freq_process(frame2freq_obj * obj, const frames_obj * frames, freqs_obj * freqs) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < frames->nSignals; iSignal++) { + + for (iSample = 0; iSample < obj->frameSize; iSample++) { + + obj->frame[iSample] = obj->win->array[iSample] * frames->array[iSignal][iSample]; + + } + + fft_r2c(obj->fft, + obj->frame, + freqs->array[iSignal]); + + } + + } \ No newline at end of file diff --git a/src/system/frame2freq.h b/src/system/frame2freq.h new file mode 100644 index 0000000..a485602 --- /dev/null +++ b/src/system/frame2freq.h @@ -0,0 +1,30 @@ +#ifndef __ODAS_SYSTEM_FRAME2FREQ +#define __ODAS_SYSTEM_FRAME2FREQ + + #include + + #include "../init/windowing.h" + #include "../signal/frame.h" + #include "../signal/freq.h" + #include "../signal/window.h" + #include "../utils/fft.h" + + typedef struct frame2freq_obj { + + unsigned int frameSize; + unsigned int halfFrameSize; + + window_obj * win; + float * frame; + + fft_obj * fft; + + } frame2freq_obj; + + frame2freq_obj * frame2freq_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize); + + void frame2freq_destroy(frame2freq_obj * obj); + + void frame2freq_process(frame2freq_obj * obj, const frames_obj * frames, freqs_obj * freqs); + +#endif \ No newline at end of file diff --git a/src/system/frame2hop.c b/src/system/frame2hop.c new file mode 100644 index 0000000..c60c036 --- /dev/null +++ b/src/system/frame2hop.c @@ -0,0 +1,67 @@ + + #include "frame2hop.h" + + frame2hop_obj * frame2hop_construct_zero(const unsigned int hopSize, const unsigned int frameSize, const unsigned int nSignals) { + + frame2hop_obj * obj; + unsigned int iSignal; + + obj = (frame2hop_obj *) malloc(sizeof(frame2hop_obj)); + + obj->hopSize = hopSize; + obj->frameSize = frameSize; + obj->nSignals = nSignals; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = (float *) malloc(sizeof(float) * frameSize); + memset(obj->array[iSignal], 0x00, sizeof(float) * frameSize); + } + + return obj; + + } + + void frame2hop_destroy(frame2hop_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + free((void *) obj->array[iSignal]); + } + + free((void *) obj->array); + + free((void *) obj); + + } + + void frame2hop_process(frame2hop_obj * obj, const frames_obj * frames, hops_obj * hops) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + memmove(&(obj->array[iSignal][0]), + &(obj->array[iSignal][obj->hopSize]), + sizeof(float) * (obj->frameSize - obj->hopSize)); + + memset(&(obj->array[iSignal][obj->frameSize - obj->hopSize]), + 0x00, + sizeof(float) * (obj->hopSize)); + + for (iSample = 0; iSample < obj->frameSize; iSample++) { + + obj->array[iSignal][iSample] += frames->array[iSignal][iSample]; + + } + + memcpy(&(hops->array[iSignal][0]), + &(obj->array[iSignal][0]), + sizeof(float) * obj->hopSize); + + } + + } \ No newline at end of file diff --git a/src/system/frame2hop.h b/src/system/frame2hop.h new file mode 100644 index 0000000..a24a745 --- /dev/null +++ b/src/system/frame2hop.h @@ -0,0 +1,26 @@ +#ifndef __ODAS_SYSTEM_FRAME2HOP +#define __ODAS_SYSTEM_FRAME2HOP + + #include + #include + + #include "../signal/hop.h" + #include "../signal/frame.h" + + typedef struct frame2hop_obj { + + unsigned int hopSize; + unsigned int frameSize; + unsigned int nSignals; + + float ** array; + + } frame2hop_obj; + + frame2hop_obj * frame2hop_construct_zero(const unsigned int hopSize, const unsigned int frameSize, const unsigned int nSignals); + + void frame2hop_destroy(frame2hop_obj * obj); + + void frame2hop_process(frame2hop_obj * obj, const frames_obj * frames, hops_obj * hops); + +#endif \ No newline at end of file diff --git a/src/system/freq2frame.c b/src/system/freq2frame.c new file mode 100644 index 0000000..8898cad --- /dev/null +++ b/src/system/freq2frame.c @@ -0,0 +1,51 @@ + + #include "freq2frame.h" + + freq2frame_obj * freq2frame_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize) { + + freq2frame_obj * obj; + + obj = (freq2frame_obj *) malloc(sizeof(freq2frame_obj)); + + obj->frameSize = frameSize; + obj->halfFrameSize = halfFrameSize; + + obj->win = windowing_roothann(frameSize); + obj->frame = (float *) malloc(sizeof(float) * frameSize); + memset(obj->frame, 0x00, sizeof(float) * frameSize); + obj->fft = fft_construct(frameSize); + + return obj; + + } + + void freq2frame_destroy(freq2frame_obj * obj) { + + window_destroy(obj->win); + free((void *) obj->frame); + fft_destroy(obj->fft); + + free((void *) obj); + + } + + void freq2frame_process(freq2frame_obj * obj, const freqs_obj * freqs, frames_obj * frames) { + + unsigned int iSignal; + unsigned int iSample; + + for (iSignal = 0; iSignal < frames->nSignals; iSignal++) { + + fft_c2r(obj->fft, + freqs->array[iSignal], + obj->frame); + + for (iSample = 0; iSample < obj->frameSize; iSample++) { + + frames->array[iSignal][iSample] = obj->win->array[iSample] * obj->frame[iSample]; + + } + + } + + } \ No newline at end of file diff --git a/src/system/freq2frame.h b/src/system/freq2frame.h new file mode 100644 index 0000000..43981de --- /dev/null +++ b/src/system/freq2frame.h @@ -0,0 +1,30 @@ +#ifndef __ODAS_SYSTEM_FREQ2FRAME +#define __ODAS_SYSTEM_FREQ2FRAME + + #include + + #include "../init/windowing.h" + #include "../signal/frame.h" + #include "../signal/freq.h" + #include "../signal/window.h" + #include "../utils/fft.h" + + typedef struct freq2frame_obj { + + unsigned int frameSize; + unsigned int halfFrameSize; + + window_obj * win; + float * frame; + + fft_obj * fft; + + } freq2frame_obj; + + freq2frame_obj * freq2frame_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize); + + void freq2frame_destroy(freq2frame_obj * obj); + + void freq2frame_process(freq2frame_obj * obj, const freqs_obj * freqs, frames_obj * frames); + +#endif \ No newline at end of file diff --git a/src/system/freq2freq.c b/src/system/freq2freq.c new file mode 100644 index 0000000..2aa0280 --- /dev/null +++ b/src/system/freq2freq.c @@ -0,0 +1,259 @@ + + #include "freq2freq.h" + + freq2freq_obj * freq2freq_construct_zero(const unsigned int halfFrameSize, const unsigned int lowPassCut, const float epsilon) { + + freq2freq_obj * obj; + + obj = (freq2freq_obj *) malloc(sizeof(freq2freq_obj)); + + obj->halfFrameSize = halfFrameSize; + obj->lowPassCut = lowPassCut; + obj->epsilon = epsilon; + + return obj; + + } + + void freq2freq_destroy(freq2freq_obj * obj) { + + free((void *) obj); + + } + + void freq2freq_process_phasor(freq2freq_obj * obj, const freqs_obj * freqs, freqs_obj * phasors) { + + unsigned int iSignal, iSample; + float real, imag; + float magnitude; + + for (iSignal = 0; iSignal < freqs->nSignals; iSignal++) { + + for (iSample = 0; iSample < freqs->halfFrameSize; iSample++) { + + real = freqs->array[iSignal][iSample * 2 + 0]; + imag = freqs->array[iSignal][iSample * 2 + 1]; + magnitude = sqrtf(real*real+imag*imag) + obj->epsilon; + + phasors->array[iSignal][iSample * 2 + 0] = real / magnitude; + phasors->array[iSignal][iSample * 2 + 1] = imag / magnitude; + + } + + } + + } + + void freq2freq_process_product(freq2freq_obj * obj, const freqs_obj * freqs1, const freqs_obj * freqs2, const pairs_obj * pairs, freqs_obj * freqs12) { + + unsigned int iSignal1, iSignal2, iSignal12, iSample; + float real1, imag1; + float real2, imag2; + + iSignal12 = 0; + + for (iSignal1 = 0; iSignal1 < freqs1->nSignals; iSignal1++) { + + for (iSignal2 = (iSignal1+1); iSignal2 < freqs2->nSignals; iSignal2++) { + + if (pairs->array[iSignal12] == 0x01) { + + for (iSample = 0; iSample < obj->halfFrameSize; iSample++) { + + real1 = freqs1->array[iSignal1][iSample * 2 + 0]; + imag1 = freqs1->array[iSignal1][iSample * 2 + 1]; + real2 = freqs2->array[iSignal2][iSample * 2 + 0]; + imag2 = freqs2->array[iSignal2][iSample * 2 + 1]; + + freqs12->array[iSignal12][iSample * 2 + 0] = real1 * real2 + imag1 * imag2; + freqs12->array[iSignal12][iSample * 2 + 1] = imag1 * real2 - imag2 * real1; + + } + + } + + iSignal12++; + + } + + } + + } + + void freq2freq_process_lowpass(freq2freq_obj * obj, const freqs_obj * freqsAllPass, freqs_obj * freqsLowPass) { + + unsigned int iSignal; + + freqs_zero(freqsLowPass); + + for (iSignal = 0; iSignal < freqsAllPass->nSignals; iSignal++) { + + memcpy(freqsLowPass->array[iSignal], freqsAllPass->array[iSignal], sizeof(float) * 2 * obj->lowPassCut); + + } + + } + + void freq2freq_process_delaysum(freq2freq_obj * obj, const freqs_obj * freqsChannels, const shifts_obj * shifts, const gains_obj * gains, const masks_obj * masks, freqs_obj * freqsSeps) { + + unsigned int iSep; + unsigned int iChannel; + unsigned int iSample; + + unsigned int nSeps; + unsigned int nChannels; + unsigned int nSamples; + float N; + + float channelReal; + float channelImag; + + float gainTotal; + float gain; + float tau; + float phase; + + float shiftReal; + float shiftImag; + + float sepReal; + float sepImag; + + nSeps = freqsSeps->nSignals; + nChannels = freqsChannels->nSignals; + nSamples = freqsChannels->halfFrameSize; + + N = (float) (2 * (freqsChannels->halfFrameSize-1)); + + for (iSep = 0; iSep < nSeps; iSep++) { + + memset(freqsSeps->array[iSep], 0x00, sizeof(float) * nSamples * 2); + + gainTotal = 0.0f; + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + if (masks->array[iSep * nChannels + iChannel] == 0x01) { + + gainTotal += gains->array[iSep * nChannels + iChannel]; + + } + + } + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + if (masks->array[iSep * nChannels + iChannel] == 0x01) { + + gain = gains->array[iSep * nChannels + iChannel] / gainTotal; + tau = shifts->array[iSep * nChannels + iChannel]; + + for (iSample = 0; iSample < freqsChannels->halfFrameSize; iSample++) { + + phase = 2.0f * M_PI * tau * ((float) iSample) / N; + + shiftReal = gain * cosf(phase); + shiftImag = gain * sinf(phase); + + channelReal = freqsChannels->array[iChannel][iSample * 2 + 0]; + channelImag = freqsChannels->array[iChannel][iSample * 2 + 1]; + + sepReal = channelReal * shiftReal - channelImag * shiftImag; + sepImag = channelImag * shiftReal + channelReal * shiftImag; + + freqsSeps->array[iSep][iSample * 2 + 0] += sepReal; + freqsSeps->array[iSep][iSample * 2 + 1] += sepImag; + + } + + } + + } + + } + + } + + void freq2freq_process_postfilter(freq2freq_obj * obj, const freqs_obj * freqsChannels, const freqs_obj * freqsSeps, const gains_obj * gains, const masks_obj * masks, freqs_obj * freqsPosts) { + + unsigned int iSep; + unsigned int iChannel; + unsigned int iSample; + + unsigned int nSeps; + unsigned int nChannels; + unsigned int nSamples; + + float sepReal; + float sepImag; + float sepPwr; + + float gain; + float gainTotal; + float gainTotal2; + + float channelReal; + float channelImag; + float channelPwr; + float channelsPwr; + + float ratio; + float factor; + + nSeps = freqsSeps->nSignals; + nChannels = freqsChannels->nSignals; + nSamples = freqsChannels->halfFrameSize; + + for (iSample = 0; iSample < nSamples; iSample++) { + + for (iSep = 0; iSep < nSeps; iSep++) { + + sepReal = freqsSeps->array[iSep][iSample * 2 + 0]; + sepImag = freqsSeps->array[iSep][iSample * 2 + 1]; + sepPwr = sepReal * sepReal + sepImag * sepImag; + + gainTotal = 0.0f; + gainTotal2 = 0.0f; + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + if (masks->array[iSep * nChannels + iChannel] == 0x01) { + + gain = gains->array[iSep * nChannels + iChannel]; + gainTotal += gain; + gainTotal2 += gain * gain; + + } + + } + + channelsPwr = 0.0f; + + for (iChannel = 0; iChannel < nChannels; iChannel++) { + + if (masks->array[iSep * nChannels + iChannel] == 0x01) { + + gain = gains->array[iSep * nChannels + iChannel] / gainTotal; + + channelReal = gain * freqsChannels->array[iChannel][iSample * 2 + 0]; + channelImag = gain * freqsChannels->array[iChannel][iSample * 2 + 1]; + channelPwr = channelReal * channelReal + channelImag * channelImag; + + channelsPwr += channelPwr; + + } + + } + + ratio = sepPwr / (channelsPwr * gainTotal2 + obj->epsilon); + + factor = 0.9f / (1.0f + expf(-20.0f * (ratio-0.5f))) + 0.1f; + + freqsPosts->array[iSep][iSample * 2 + 0] = factor * freqsSeps->array[iSep][iSample * 2 + 0]; + freqsPosts->array[iSep][iSample * 2 + 1] = factor * freqsSeps->array[iSep][iSample * 2 + 1]; + + } + + } + + } \ No newline at end of file diff --git a/src/system/freq2freq.h b/src/system/freq2freq.h new file mode 100644 index 0000000..1115a9c --- /dev/null +++ b/src/system/freq2freq.h @@ -0,0 +1,35 @@ +#ifndef __ODAS_SYSTEM_FREQ2FREQ +#define __ODAS_SYSTEM_FREQ2FREQ + + #include + #include + + #include "../signal/freq.h" + #include "../signal/gain.h" + #include "../signal/mask.h" + #include "../signal/pair.h" + #include "../signal/shift.h" + + typedef struct freq2freq_obj { + + unsigned int halfFrameSize; + unsigned int lowPassCut; + float epsilon; + + } freq2freq_obj; + + freq2freq_obj * freq2freq_construct_zero(const unsigned int halfFrameSize, const unsigned int lowPassCut, const float epsilon); + + void freq2freq_destroy(freq2freq_obj * obj); + + void freq2freq_process_phasor(freq2freq_obj * obj, const freqs_obj * freqs, freqs_obj * phasors); + + void freq2freq_process_product(freq2freq_obj * obj, const freqs_obj * freqs1, const freqs_obj * freqs2, const pairs_obj * pairs, freqs_obj * freqs12); + + void freq2freq_process_lowpass(freq2freq_obj * obj, const freqs_obj * freqsAllPass, freqs_obj * freqsLowPass); + + void freq2freq_process_delaysum(freq2freq_obj * obj, const freqs_obj * freqsChannels, const shifts_obj * shifts, const gains_obj * gains, const masks_obj * masks, freqs_obj * freqsSeps); + + void freq2freq_process_postfilter(freq2freq_obj * obj, const freqs_obj * freqsChannels, const freqs_obj * freqsSeps, const gains_obj * gains, const masks_obj * masks, freqs_obj * freqsPosts); + +#endif \ No newline at end of file diff --git a/src/system/freq2xcorr.c b/src/system/freq2xcorr.c new file mode 100644 index 0000000..84da9b2 --- /dev/null +++ b/src/system/freq2xcorr.c @@ -0,0 +1,53 @@ + + #include "freq2xcorr.h" + + freq2xcorr_obj * freq2xcorr_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize) { + + freq2xcorr_obj * obj; + + obj = (freq2xcorr_obj *) malloc(sizeof(freq2xcorr_obj)); + + obj->frameSize = frameSize; + obj->halfFrameSize = halfFrameSize; + + obj->frame = (float *) malloc(sizeof(float) * halfFrameSize * 2); + memset(obj->frame,0x00,sizeof(float)* halfFrameSize * 2); + + obj->fft = fft_construct(frameSize); + + return obj; + + } + + void freq2xcorr_destroy(freq2xcorr_obj * obj) { + + fft_destroy(obj->fft); + free((void *) obj->frame); + + free((void *) obj); + + } + + void freq2xcorr_process(freq2xcorr_obj * obj, const freqs_obj * freqs, const pairs_obj * pairs, xcorrs_obj * xcorrs) { + + unsigned int iSignal; + unsigned int iSample; + unsigned int iSampleSrc; + unsigned int iSampleDest; + + for (iSignal = 0; iSignal < freqs->nSignals; iSignal++) { + + if (pairs->array[iSignal] == 0x01) { + + fft_c2r(obj->fft, + freqs->array[iSignal], + obj->frame); + + memcpy(&(xcorrs->array[iSignal][0]),&(obj->frame[obj->frameSize/2]),(obj->frameSize/2)*sizeof(float)); + memcpy(&(xcorrs->array[iSignal][obj->frameSize/2]),&(obj->frame[0]),(obj->frameSize/2)*sizeof(float)); + + } + + } + + } \ No newline at end of file diff --git a/src/system/freq2xcorr.h b/src/system/freq2xcorr.h new file mode 100644 index 0000000..5f61f33 --- /dev/null +++ b/src/system/freq2xcorr.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SYSTEM_FREQ2XCORR +#define __ODAS_SYSTEM_FREQ2XCORR + + #include "../signal/frame.h" + #include "../signal/freq.h" + #include "../signal/pair.h" + #include "../signal/tdoa.h" + #include "../signal/xcorr.h" + #include "../utils/fft.h" + + typedef struct freq2xcorr_obj { + + unsigned int frameSize; + unsigned int halfFrameSize; + + float * frame; + + fft_obj * fft; + + } freq2xcorr_obj; + + freq2xcorr_obj * freq2xcorr_construct_zero(const unsigned int frameSize, const unsigned int halfFrameSize); + + void freq2xcorr_destroy(freq2xcorr_obj * obj); + + void freq2xcorr_process(freq2xcorr_obj * obj, const freqs_obj * freqs, const pairs_obj * pairs, xcorrs_obj * xcorrs); + +#endif \ No newline at end of file diff --git a/src/system/gain2mask.c b/src/system/gain2mask.c new file mode 100644 index 0000000..1f7767c --- /dev/null +++ b/src/system/gain2mask.c @@ -0,0 +1,44 @@ + + #include "gain2mask.h" + + gain2mask_obj * gain2mask_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const float gainMin) { + + gain2mask_obj * obj; + + obj = (gain2mask_obj *) malloc(sizeof(gain2mask_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + obj->gainMin = gainMin; + + return obj; + + } + + void gain2mask_destroy(gain2mask_obj * obj) { + + free((void *) obj); + + } + + void gain2mask_process(gain2mask_obj * obj, const gains_obj * gains, masks_obj * masks) { + + unsigned int iSep; + unsigned int iChannel; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + if (gains->array[iSep * obj->nChannels + iChannel] >= obj->gainMin) { + masks->array[iSep * obj->nChannels + iChannel] = 0x01; + } + else { + masks->array[iSep * obj->nChannels + iChannel] = 0x00; + } + + } + + } + + } diff --git a/src/system/gain2mask.h b/src/system/gain2mask.h new file mode 100644 index 0000000..4ce68de --- /dev/null +++ b/src/system/gain2mask.h @@ -0,0 +1,24 @@ +#ifndef __ODAS_SYSTEM_GAIN2MASK +#define __ODAS_SYSTEM_GAIN2MASK + + #include "../signal/gain.h" + #include "../signal/mask.h" + + #include + #include + + typedef struct gain2mask_obj { + + unsigned int nSeps; + unsigned int nChannels; + float gainMin; + + } gain2mask_obj; + + gain2mask_obj * gain2mask_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const float gainMin); + + void gain2mask_destroy(gain2mask_obj * obj); + + void gain2mask_process(gain2mask_obj * obj, const gains_obj * gains, masks_obj * masks); + +#endif \ No newline at end of file diff --git a/src/system/hop2frame.c b/src/system/hop2frame.c new file mode 100644 index 0000000..60d7240 --- /dev/null +++ b/src/system/hop2frame.c @@ -0,0 +1,59 @@ + + #include "hop2frame.h" + + hop2frame_obj * hop2frame_construct_zero(const unsigned int hopSize, const unsigned int frameSize, const unsigned int nSignals) { + + hop2frame_obj * obj; + unsigned int iSignal; + + obj = (hop2frame_obj *) malloc(sizeof(hop2frame_obj)); + + obj->hopSize = hopSize; + obj->frameSize = frameSize; + obj->nSignals = nSignals; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + + for (iSignal = 0; iSignal < nSignals; iSignal++) { + obj->array[iSignal] = (float *) malloc(sizeof(float) * frameSize); + memset(obj->array[iSignal], 0x00, sizeof(float) * frameSize); + } + + return obj; + + } + + void hop2frame_destroy(hop2frame_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + free((void *) obj->array[iSignal]); + } + + free((void *) obj->array); + free((void *) obj); + + } + + void hop2frame_process(hop2frame_obj * obj, const hops_obj * hops, frames_obj * frames) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < hops->nSignals; iSignal++) { + + memmove(&(obj->array[iSignal][0]), + &(obj->array[iSignal][obj->hopSize]), + sizeof(float) * (obj->frameSize-obj->hopSize)); + + memcpy(&(obj->array[iSignal][(obj->frameSize-obj->hopSize)]), + &(hops->array[iSignal][0]), + sizeof(float) * obj->hopSize); + + memcpy(frames->array[iSignal], + obj->array[iSignal], + sizeof(float) * obj->frameSize); + + } + + } \ No newline at end of file diff --git a/src/system/hop2frame.h b/src/system/hop2frame.h new file mode 100644 index 0000000..f2edbd3 --- /dev/null +++ b/src/system/hop2frame.h @@ -0,0 +1,26 @@ +#ifndef __ODAS_SYSTEM_HOP2FRAME +#define __ODAS_SYSTEM_HOP2FRAME + + #include + #include + + #include "../signal/hop.h" + #include "../signal/frame.h" + + typedef struct hop2frame_obj { + + unsigned int hopSize; + unsigned int frameSize; + unsigned int nSignals; + + float ** array; + + } hop2frame_obj; + + hop2frame_obj * hop2frame_construct_zero(const unsigned int hopSize, const unsigned int frameSize, const unsigned int nSignals); + + void hop2frame_destroy(hop2frame_obj * obj); + + void hop2frame_process(hop2frame_obj * obj, const hops_obj * hops, frames_obj * frames); + +#endif \ No newline at end of file diff --git a/src/system/hop2hop.c b/src/system/hop2hop.c new file mode 100644 index 0000000..943f518 --- /dev/null +++ b/src/system/hop2hop.c @@ -0,0 +1,232 @@ + + #include "hop2hop.h" + + hop2hop_multiplex_obj * hop2hop_multiplex_construct_zero(const unsigned int hopSize) { + + hop2hop_multiplex_obj * obj; + + obj = (hop2hop_multiplex_obj *) malloc(sizeof(hop2hop_multiplex_obj)); + + obj->hopSize = hopSize; + + return obj; + + } + + void hop2hop_multiplex_destroy(hop2hop_multiplex_obj * obj) { + + free((void *) obj); + + } + + void hop2hop_multiplex_process(hop2hop_multiplex_obj * obj, const links_obj * links, const hops_obj * src, hops_obj * dest) { + + unsigned int iLink; + + for (iLink = 0; iLink < links->nLinks; iLink++) { + + if (links->array[iLink] == 0) { + + memset(dest->array[iLink], 0x00, sizeof(float) * obj->hopSize); + + } + else { + + memcpy(dest->array[iLink], src->array[links->array[iLink]-1], sizeof(float) * obj->hopSize); + + } + + } + + } + + hop2hop_buffer_obj * hop2hop_buffer_construct_zero(const unsigned int nSignals, const unsigned int hopSizeIn, const unsigned int hopSizeOut, const float ratio) { + + hop2hop_buffer_obj * obj; + unsigned int iSignal; + + obj = (hop2hop_buffer_obj *) malloc(sizeof(hop2hop_buffer_obj)); + + obj->nSignals = nSignals; + obj->hopSizeIn = hopSizeIn; + obj->hopSizeOut = hopSizeOut; + obj->intervalIn = (float) hopSizeIn; + obj->intervalOut = ((float) hopSizeOut) / ratio; + obj->intervalSize = 0.0f; + obj->ratio = ratio; + obj->delta = 1.0f / ratio; + + if (obj->intervalIn >= obj->intervalOut) { + + obj->bufferSize = (unsigned int) ceilf(2.0f * obj->intervalIn); + + } + else { + + obj->bufferSize = (unsigned int) ceilf(2.0f * obj->intervalOut); + + } + + obj->iRead = 0.0f; + obj->iWrite = 0.0f; + + obj->array = (float **) malloc(sizeof(float *) * nSignals); + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + obj->array[iSignal] = (float *) malloc(sizeof(float) * obj->bufferSize); + memset(obj->array[iSignal], 0x00, sizeof(float) * obj->bufferSize); + + } + + return obj; + + } + + void hop2hop_buffer_destroy(hop2hop_buffer_obj * obj) { + + unsigned int iSignal; + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + free((void *) obj->array[iSignal]); + } + + free((void *) obj->array); + free((void *) obj); + + } + + void hop2hop_buffer_push(hop2hop_buffer_obj * obj, const hops_obj * hops) { + + unsigned int iWriteInt; + + unsigned int iHop1; + unsigned int iBuffer1; + unsigned int nSamples1; + unsigned int iHop2; + unsigned int iBuffer2; + unsigned int nSamples2; + + unsigned int iSignal; + + if ((obj->intervalSize + obj->intervalIn) <= ((float) obj->bufferSize)) { + + iWriteInt = (unsigned int) obj->iWrite; + + if ((obj->iWrite + obj->intervalIn) <= ((float) obj->bufferSize)) { + + iHop1 = 0; + iBuffer1 = iWriteInt; + nSamples1 = (unsigned int) obj->intervalIn; + + iHop2 = 0; + iBuffer2 = 0; + nSamples2 = 0; + + } + else { + + iHop1 = 0; + iBuffer1 = iWriteInt; + nSamples1 = (obj->bufferSize - iWriteInt); + + iHop2 = (obj->bufferSize - iWriteInt); + iBuffer2 = 0; + nSamples2 = obj->intervalIn - (obj->bufferSize - iWriteInt); + + } + + for (iSignal = 0; iSignal < hops->nSignals; iSignal++) { + + memcpy(&(obj->array[iSignal][iBuffer1]), + &(hops->array[iSignal][iHop1]), + nSamples1 * sizeof(float)); + + memcpy(&(obj->array[iSignal][iBuffer2]), + &(hops->array[iSignal][iHop2]), + nSamples2 * sizeof(float)); + + } + + obj->intervalSize += (float) obj->intervalIn; + + obj->iWrite += (float) obj->intervalIn; + obj->iWrite = fmod(obj->iWrite, (float) obj->bufferSize); + + } + + } + + void hop2hop_buffer_pop(hop2hop_buffer_obj * obj, hops_obj * hops) { + + unsigned int iSample; + unsigned int iReadFloor; + unsigned int iReadCeil; + float yFloor; + float yCeil; + float yDelta; + float xDelta; + + unsigned int iSignal; + + if (obj->intervalOut <= obj->intervalSize) { + + for (iSample = 0; iSample < obj->hopSizeOut; iSample++) { + + iReadFloor = (unsigned int) floorf(obj->iRead); + iReadCeil = (iReadFloor + 1) % obj->bufferSize; + + xDelta = obj->iRead - floorf(obj->iRead); + + for (iSignal = 0; iSignal < obj->nSignals; iSignal++) { + + yFloor = obj->array[iSignal][iReadFloor]; + yCeil = obj->array[iSignal][iReadCeil]; + yDelta = yCeil - yFloor; + + hops->array[iSignal][iSample] = xDelta * yDelta + yFloor; + + } + + obj->iRead += obj->delta; + obj->iRead = fmod(obj->iRead, (float) obj->bufferSize); + + } + + obj->intervalSize -= (float) obj->intervalOut; + + } + + } + + char hop2hop_buffer_isFull(hop2hop_buffer_obj * obj) { + + char rtnValue; + + rtnValue = 0; + + if ((obj->intervalSize + obj->intervalIn) > ((float) obj->bufferSize)) { + + rtnValue = 1; + + } + + return rtnValue; + + } + + char hop2hop_buffer_isEmpty(hop2hop_buffer_obj * obj) { + + char rtnValue; + + rtnValue = 0; + + if (obj->intervalOut > obj->intervalSize) { + + rtnValue = 1; + + } + + return rtnValue; + + } \ No newline at end of file diff --git a/src/system/hop2hop.h b/src/system/hop2hop.h new file mode 100644 index 0000000..dae23c2 --- /dev/null +++ b/src/system/hop2hop.h @@ -0,0 +1,54 @@ +#ifndef __ODAS_SYSTEM_HOP2HOP +#define __ODAS_SYSTEM_HOP2HOP + + #include + #include + #include + + #include "../signal/hop.h" + #include "../general/link.h" + + typedef struct hop2hop_multiplex_obj { + + unsigned int hopSize; + + } hop2hop_multiplex_obj; + + typedef struct hop2hop_buffer_obj { + + unsigned int nSignals; + unsigned int hopSizeIn; + unsigned int hopSizeOut; + float intervalIn; + float intervalOut; + float intervalSize; + unsigned int bufferSize; + float ratio; + float delta; + + float iWrite; + float iRead; + + float ** array; + + } hop2hop_buffer_obj; + + hop2hop_multiplex_obj * hop2hop_multiplex_construct_zero(const unsigned int hopSize); + + void hop2hop_multiplex_destroy(hop2hop_multiplex_obj * obj); + + void hop2hop_multiplex_process(hop2hop_multiplex_obj * obj, const links_obj * links, const hops_obj * src, hops_obj * dest); + + hop2hop_buffer_obj * hop2hop_buffer_construct_zero(const unsigned int nSignals, const unsigned int hopSizeIn, const unsigned int hopSizeOut, const float ratio); + + void hop2hop_buffer_destroy(hop2hop_buffer_obj * obj); + + void hop2hop_buffer_push(hop2hop_buffer_obj * obj, const hops_obj * hops); + + void hop2hop_buffer_pop(hop2hop_buffer_obj * obj, hops_obj * hops); + + char hop2hop_buffer_isFull(hop2hop_buffer_obj * obj); + + char hop2hop_buffer_isEmpty(hop2hop_buffer_obj * obj); + +#endif \ No newline at end of file diff --git a/src/system/kalman2coherence.c b/src/system/kalman2coherence.c new file mode 100644 index 0000000..5531c49 --- /dev/null +++ b/src/system/kalman2coherence.c @@ -0,0 +1,171 @@ + + #include "kalman2coherence.h" + + kalman2coherence_obj * kalman2coherence_construct(const float epsilon, const float sigmaR) { + + kalman2coherence_obj * obj; + + obj = (kalman2coherence_obj *) malloc(sizeof(kalman2coherence_obj)); + + obj->epsilon = epsilon; + + obj->H = matrix_construct_zero(3,6); + obj->H->array[0][0] = 1.0f; + obj->H->array[1][1] = 1.0f; + obj->H->array[2][2] = 1.0f; + + obj->Ht = matrix_construct_zero(6,3); + obj->Ht->array[0][0] = 1.0f; + obj->Ht->array[1][1] = 1.0f; + obj->Ht->array[2][2] = 1.0f; + + obj->mu_t = matrix_construct_zero(3,1); + obj->mu_t_t = matrix_construct_zero(1,3); + obj->mu_s = matrix_construct_zero(3,1); + obj->mu_s_t = matrix_construct_zero(1,3); + obj->mu_st = matrix_construct_zero(3,1); + obj->mu_st_t = matrix_construct_zero(1,3); + + obj->HP = matrix_construct_zero(3,6); + obj->sigma_epsilon = matrix_construct_zero(3,3); + + obj->sigma_t = matrix_construct_zero(3,3); + obj->sigma_s = matrix_construct_zero(3,3); + obj->sigma_st = matrix_construct_zero(3,3); + + obj->sigma_t_epsilon = matrix_construct_zero(3,3); + obj->sigma_t_inv = matrix_construct_zero(3,3); + obj->sigma_s_inv = matrix_construct_zero(3,3); + obj->sigma_st_inv = matrix_construct_zero(3,3); + + obj->sigma_t_inv_mu_t = matrix_construct_zero(3,1); + obj->sigma_s_inv_mu_s = matrix_construct_zero(3,1); + obj->sigma_st_inv_mu_st = matrix_construct_zero(3,1); + + obj->mu_t_t_sigma_t_inv_mu_t = matrix_construct_zero(1,1); + obj->mu_s_t_sigma_s_inv_mu_s = matrix_construct_zero(1,1); + obj->mu_st_t_sigma_st_inv_mu_st = matrix_construct_zero(1,1); + + obj->sigma_t_inv_mu_t_sigma_s_inv_mu_s = matrix_construct_zero(3,1); + + obj->sigma_s->array[0][0] = sigmaR*sigmaR; + obj->sigma_s->array[1][1] = sigmaR*sigmaR; + obj->sigma_s->array[2][2] = sigmaR*sigmaR; + + obj->sigma_epsilon->array[0][0] = epsilon; + obj->sigma_epsilon->array[1][1] = epsilon; + obj->sigma_epsilon->array[2][2] = epsilon; + + matrix_inv(obj->sigma_s_inv, obj->sigma_s); + + return obj; + + } + + void kalman2coherence_destroy(kalman2coherence_obj * obj) { + + matrix_destroy(obj->H); + matrix_destroy(obj->Ht); + + matrix_destroy(obj->mu_t); + matrix_destroy(obj->mu_t_t); + matrix_destroy(obj->mu_s); + matrix_destroy(obj->mu_s_t); + matrix_destroy(obj->mu_st); + matrix_destroy(obj->mu_st_t); + + matrix_destroy(obj->HP); + matrix_destroy(obj->sigma_epsilon); + + matrix_destroy(obj->sigma_t); + matrix_destroy(obj->sigma_s); + matrix_destroy(obj->sigma_st); + + matrix_destroy(obj->sigma_t_epsilon); + matrix_destroy(obj->sigma_t_inv); + matrix_destroy(obj->sigma_s_inv); + matrix_destroy(obj->sigma_st_inv); + + matrix_destroy(obj->sigma_t_inv_mu_t); + matrix_destroy(obj->sigma_s_inv_mu_s); + matrix_destroy(obj->sigma_st_inv_mu_st); + + matrix_destroy(obj->mu_t_t_sigma_t_inv_mu_t); + matrix_destroy(obj->mu_s_t_sigma_s_inv_mu_s); + matrix_destroy(obj->mu_st_t_sigma_st_inv_mu_st); + + matrix_destroy(obj->sigma_t_inv_mu_t_sigma_s_inv_mu_s); + + free((void *) obj); + + } + + void kalman2coherence_process(kalman2coherence_obj * obj, const kalman_obj * kalman, const pots_obj * pots, const unsigned int iTrack, coherences_obj * coherences) { + + unsigned int iPot; + float B1, B2, B3, B4; + float weight; + + // Compute mu_t + matrix_mul(obj->mu_t, obj->H, kalman->x_llm1); + matrix_transpose(obj->mu_t_t, obj->mu_t); + + // Compute sigma_t + matrix_mul(obj->HP, obj->H, kalman->P_llm1); + matrix_mul(obj->sigma_t, obj->HP, obj->Ht); + matrix_add(obj->sigma_t_epsilon, obj->sigma_t, obj->sigma_epsilon); + + // Compute sigma_t^-1 + matrix_inv(obj->sigma_t_inv, obj->sigma_t_epsilon); + + // Compute sigma_t^-1 * mu_t + matrix_mul(obj->sigma_t_inv_mu_t, obj->sigma_t_inv, obj->mu_t); + + // Compute B3 + matrix_mul(obj->mu_t_t_sigma_t_inv_mu_t, obj->mu_t_t, obj->sigma_t_inv_mu_t); + B3 = obj->mu_t_t_sigma_t_inv_mu_t->array[0][0]; + + for (iPot = 0; iPot < pots->nPots; iPot++) { + + // Compute mu_s + obj->mu_s->array[0][0] = pots->array[iPot*4+0]; + obj->mu_s->array[1][0] = pots->array[iPot*4+1]; + obj->mu_s->array[2][0] = pots->array[iPot*4+2]; + matrix_transpose(obj->mu_s_t, obj->mu_s); + + // Compute sigma_st^-1 + matrix_add(obj->sigma_st_inv, obj->sigma_s_inv, obj->sigma_t_inv); + + // Compute sigma_st + matrix_inv(obj->sigma_st, obj->sigma_st_inv); + + // Compute sigma_s^-1 * mu_s + matrix_mul(obj->sigma_s_inv_mu_s, obj->sigma_s_inv, obj->mu_s); + + // Compute (sigma_t^-1 * mu_t + sigma_s^-1 * mu_s) + matrix_add(obj->sigma_t_inv_mu_t_sigma_s_inv_mu_s, obj->sigma_t_inv_mu_t, obj->sigma_s_inv_mu_s); + + // Compute mu_st = sigma_st * (sigma_t^-1 * mu_t + sigma_s^-1 * mu_s) + matrix_mul(obj->mu_st, obj->sigma_st, obj->sigma_t_inv_mu_t_sigma_s_inv_mu_s); + matrix_transpose(obj->mu_st_t, obj->mu_st); + + // Compute B1 + B1 = logf(matrix_det(obj->sigma_st)) - logf(8.0f * M_PI * M_PI * M_PI * matrix_det(obj->sigma_t) * matrix_det(obj->sigma_s)); + + // Compute B2 + matrix_mul(obj->sigma_st_inv_mu_st, obj->sigma_st_inv, obj->mu_st); + matrix_mul(obj->mu_st_t_sigma_st_inv_mu_st, obj->mu_st_t, obj->sigma_st_inv_mu_st); + B2 = obj->mu_st_t_sigma_st_inv_mu_st->array[0][0]; + + // Compute B4 + matrix_mul(obj->mu_s_t_sigma_s_inv_mu_s, obj->mu_s_t, obj->sigma_s_inv_mu_s); + B4 = obj->mu_s_t_sigma_s_inv_mu_s->array[0][0]; + + // Compute weight + weight = expf(0.5f * (B1+B2-B3-B4)); + + coherences->array[iTrack * pots->nPots + iPot] = weight; + + } + + } \ No newline at end of file diff --git a/src/system/kalman2coherence.h b/src/system/kalman2coherence.h new file mode 100644 index 0000000..0aac38c --- /dev/null +++ b/src/system/kalman2coherence.h @@ -0,0 +1,57 @@ +#ifndef __ODAS_SYSTEM_KALMAN2PRIOR +#define __ODAS_SYSTEM_KALMAN2PRIOR + + #include + #include + + #include "../signal/coherence.h" + #include "../signal/kalman.h" + #include "../signal/pot.h" + #include "../utils/matrix.h" + + typedef struct kalman2coherence_obj { + + float epsilon; + + matrix_obj * H; + matrix_obj * Ht; + + matrix_obj * mu_t; + matrix_obj * mu_t_t; + matrix_obj * mu_s; + matrix_obj * mu_s_t; + matrix_obj * mu_st; + matrix_obj * mu_st_t; + + matrix_obj * HP; + matrix_obj * sigma_epsilon; + + matrix_obj * sigma_t; + matrix_obj * sigma_s; + matrix_obj * sigma_st; + + matrix_obj * sigma_t_epsilon; + matrix_obj * sigma_t_inv; + matrix_obj * sigma_s_inv; + matrix_obj * sigma_st_inv; + + matrix_obj * sigma_t_inv_mu_t; + matrix_obj * sigma_s_inv_mu_s; + matrix_obj * sigma_st_inv_mu_st; + + matrix_obj * mu_t_t_sigma_t_inv_mu_t; + matrix_obj * mu_s_t_sigma_s_inv_mu_s; + matrix_obj * mu_st_t_sigma_st_inv_mu_st; + + matrix_obj * sigma_t_inv_mu_t_sigma_s_inv_mu_s; + + } kalman2coherence_obj; + + kalman2coherence_obj * kalman2coherence_construct(const float epsilon, const float sigmaR); + + void kalman2coherence_destroy(kalman2coherence_obj * obj); + + void kalman2coherence_process(kalman2coherence_obj * obj, const kalman_obj * kalman, const pots_obj * pots, const unsigned int iTrack, coherences_obj * coherences); + + +#endif \ No newline at end of file diff --git a/src/system/kalman2kalman.c b/src/system/kalman2kalman.c new file mode 100644 index 0000000..9fe71c9 --- /dev/null +++ b/src/system/kalman2kalman.c @@ -0,0 +1,216 @@ + + #include "kalman2kalman.h" + + kalman2kalman_obj * kalman2kalman_construct(const float deltaT, const float sigmaQ, const float sigmaR, const float epsilon) { + + kalman2kalman_obj * obj; + + obj = (kalman2kalman_obj *) malloc(sizeof(kalman2kalman_obj)); + + obj->deltaT = deltaT; + obj->sigmaQ = sigmaQ; + obj->sigmaR = sigmaR; + obj->epsilon = epsilon; + + obj->F = matrix_construct_zero(6,6); + obj->Ft = matrix_construct_zero(6,6); + obj->Q = matrix_construct_zero(6,6); + obj->H = matrix_construct_zero(3,6); + obj->Ht = matrix_construct_zero(6,3); + obj->R = matrix_construct_zero(3,3); + + obj->F->array[0][0] = 1.0f; + obj->F->array[0][3] = deltaT; + obj->F->array[1][1] = 1.0f; + obj->F->array[1][4] = deltaT; + obj->F->array[2][2] = 1.0f; + obj->F->array[2][5] = deltaT; + obj->F->array[3][3] = 1.0f; + obj->F->array[4][4] = 1.0f; + obj->F->array[5][5] = 1.0f; + + obj->Ft->array[0][0] = 1.0f; + obj->Ft->array[3][0] = deltaT; + obj->Ft->array[1][1] = 1.0f; + obj->Ft->array[4][1] = deltaT; + obj->Ft->array[2][2] = 1.0f; + obj->Ft->array[5][2] = deltaT; + obj->Ft->array[3][3] = 1.0f; + obj->Ft->array[4][4] = 1.0f; + obj->Ft->array[5][5] = 1.0f; + + obj->Q->array[3][3] = sigmaQ*sigmaQ; + obj->Q->array[4][4] = sigmaQ*sigmaQ; + obj->Q->array[5][5] = sigmaQ*sigmaQ; + + obj->H->array[0][0] = 1.0f; + obj->H->array[1][1] = 1.0f; + obj->H->array[2][2] = 1.0f; + + obj->Ht->array[0][0] = 1.0f; + obj->Ht->array[1][1] = 1.0f; + obj->Ht->array[2][2] = 1.0f; + + obj->R->array[0][0] = sigmaR*sigmaR; + obj->R->array[1][1] = sigmaR*sigmaR; + obj->R->array[2][2] = sigmaR*sigmaR; + + obj->FP = matrix_construct_zero(6,6); + obj->FPFt = matrix_construct_zero(6,6); + + obj->K = matrix_construct_zero(6,3); + obj->PHt = matrix_construct_zero(6,3); + obj->HP = matrix_construct_zero(3,6); + obj->HPHt = matrix_construct_zero(3,3); + obj->HPHt_R = matrix_construct_zero(3,3); + obj->HPHt_Rinv = matrix_construct_zero(3,3); + obj->Hx = matrix_construct_zero(3,1); + obj->z = matrix_construct_zero(3,1); + obj->z_Hx = matrix_construct_zero(3,1); + obj->Kz_Hx = matrix_construct_zero(6,1); + obj->pKz_Hx = matrix_construct_zero(6,1); + obj->KHP = matrix_construct_zero(6,6); + obj->pKHP = matrix_construct_zero(6,6); + + return obj; + + } + + void kalman2kalman_destroy(kalman2kalman_obj * obj) { + + matrix_destroy(obj->F); + matrix_destroy(obj->Ft); + matrix_destroy(obj->Q); + matrix_destroy(obj->H); + matrix_destroy(obj->Ht); + matrix_destroy(obj->R); + + matrix_destroy(obj->FP); + matrix_destroy(obj->FPFt); + + matrix_destroy(obj->K); + matrix_destroy(obj->PHt); + matrix_destroy(obj->HP); + matrix_destroy(obj->HPHt); + matrix_destroy(obj->HPHt_R); + matrix_destroy(obj->HPHt_Rinv); + matrix_destroy(obj->Hx); + matrix_destroy(obj->z); + matrix_destroy(obj->z_Hx); + matrix_destroy(obj->Kz_Hx); + matrix_destroy(obj->pKz_Hx); + matrix_destroy(obj->KHP); + matrix_destroy(obj->pKHP); + + free((void *) obj); + + } + + void kalman2kalman_init(kalman2kalman_obj * obj, const pots_obj * pots, const unsigned int iPot, kalman_obj * kalman) { + + matrix_copy_zero(kalman->x_llm1); + matrix_copy_zero(kalman->x_lm1lm1); + matrix_copy_zero(kalman->P_llm1); + matrix_copy_zero(kalman->P_lm1lm1); + + kalman->P_lm1lm1->array[0][0] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[1][1] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[2][2] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[3][3] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[4][4] = obj->sigmaQ * obj->sigmaQ; + kalman->P_lm1lm1->array[5][5] = obj->sigmaQ * obj->sigmaQ; + + kalman->x_lm1lm1->array[0][0] = pots->array[iPot * 4 + 0]; + kalman->x_lm1lm1->array[1][0] = pots->array[iPot * 4 + 1]; + kalman->x_lm1lm1->array[2][0] = pots->array[iPot * 4 + 2]; + + } + + void kalman2kalman_predict(kalman2kalman_obj * obj, kalman_obj * kalman) { + + float xx, xy, xz; + float vx, vy, vz; + float norm, norm2, proj; + + matrix_mul(kalman->x_llm1, obj->F, kalman->x_lm1lm1); + matrix_mul(obj->FP, obj->F, kalman->P_lm1lm1); + matrix_mul(obj->FPFt, obj->FP, obj->Ft); + matrix_add(kalman->P_llm1, obj->FPFt, obj->Q); + + xx = kalman->x_llm1->array[0][0]; + xy = kalman->x_llm1->array[1][0]; + xz = kalman->x_llm1->array[2][0]; + vx = kalman->x_llm1->array[3][0]; + vy = kalman->x_llm1->array[4][0]; + vz = kalman->x_llm1->array[5][0]; + + norm2 = xx*xx + xy*xy + xz*xz; + norm = sqrtf(norm2); + proj = xx*vx + xy*vy + xz*vz; + + kalman->x_llm1->array[0][0] = xx / (norm + obj->epsilon); + kalman->x_llm1->array[1][0] = xy / (norm + obj->epsilon); + kalman->x_llm1->array[2][0] = xz / (norm + obj->epsilon); + kalman->x_llm1->array[3][0] = vx - xx * proj / (norm2 + obj->epsilon); + kalman->x_llm1->array[4][0] = vy - xy * proj / (norm2 + obj->epsilon); + kalman->x_llm1->array[5][0] = vz - xz * proj / (norm2 + obj->epsilon); + + } + + void kalman2kalman_update(kalman2kalman_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, kalman_obj * kalman) { + + unsigned int iPot; + float maxValue; + unsigned int maxIndex; + float updateFactor; + + // Find potential source with max prob + + maxValue = postprobs->arrayTrack[iTrack * postprobs->nPots]; + maxIndex = 0; + + for (iPot = 1; iPot < postprobs->nPots; iPot++) { + + if (maxValue < postprobs->arrayTrack[iTrack * postprobs->nPots + iPot]) { + maxValue = postprobs->arrayTrack[iTrack * postprobs->nPots + iPot]; + maxIndex = iPot; + } + + } + + obj->z->array[0][0] = pots->array[maxIndex * 4 + 0]; + obj->z->array[1][0] = pots->array[maxIndex * 4 + 1]; + obj->z->array[2][0] = pots->array[maxIndex * 4 + 2]; + + // Compute K + matrix_mul(obj->HP, obj->H, kalman->P_llm1); + matrix_mul(obj->HPHt, obj->HP, obj->Ht); + matrix_add(obj->HPHt_R, obj->HPHt, obj->R); + matrix_inv(obj->HPHt_Rinv, obj->HPHt_R); + matrix_mul(obj->PHt, kalman->P_llm1, obj->Ht); + matrix_mul(obj->K, obj->PHt, obj->HPHt_Rinv); + + updateFactor = postprobs->arrayTrackTotal[iTrack]; + + // Update x + matrix_mul(obj->Hx, obj->H, kalman->x_llm1); + matrix_sub(obj->z_Hx, obj->z, obj->Hx); + matrix_mul(obj->Kz_Hx, obj->K, obj->z_Hx); + matrix_scale(obj->pKz_Hx, obj->Kz_Hx, updateFactor); + matrix_add(kalman->x_lm1lm1, kalman->x_llm1, obj->pKz_Hx); + + + // Update P + matrix_mul(obj->KHP, obj->K, obj->HP); + matrix_scale(obj->pKHP, obj->KHP, updateFactor); + matrix_sub(kalman->P_lm1lm1, kalman->P_llm1, obj->pKHP); + + } + + void kalman2kalman_estimate(kalman2kalman_obj * obj, const kalman_obj * kalman, float * x, float * y, float * z) { + + *x = kalman->x_lm1lm1->array[0][0]; + *y = kalman->x_lm1lm1->array[1][0]; + *z = kalman->x_lm1lm1->array[2][0]; + + } \ No newline at end of file diff --git a/src/system/kalman2kalman.h b/src/system/kalman2kalman.h new file mode 100644 index 0000000..e102bfb --- /dev/null +++ b/src/system/kalman2kalman.h @@ -0,0 +1,59 @@ +#ifndef __ODAS_SYSTEM_KALMAN2KALMAN +#define __ODAS_SYSTEM_KALMAN2KALMAN + + #include + #include + #include + + #include "../signal/postprob.h" + #include "../signal/kalman.h" + #include "../signal/pot.h" + #include "../utils/matrix.h" + + typedef struct kalman2kalman_obj { + + float epsilon; + + float deltaT; + float sigmaQ; + float sigmaR; + + matrix_obj * F; + matrix_obj * Ft; + matrix_obj * Q; + matrix_obj * H; + matrix_obj * Ht; + matrix_obj * R; + + matrix_obj * FP; + matrix_obj * FPFt; + + matrix_obj * K; + matrix_obj * PHt; + matrix_obj * HP; + matrix_obj * HPHt; + matrix_obj * HPHt_R; + matrix_obj * HPHt_Rinv; + matrix_obj * Hx; + matrix_obj * z; + matrix_obj * z_Hx; + matrix_obj * Kz_Hx; + matrix_obj * pKz_Hx; + matrix_obj * KHP; + matrix_obj * pKHP; + + } kalman2kalman_obj; + + kalman2kalman_obj * kalman2kalman_construct(const float deltaT, const float sigmaQ, const float sigmaR, const float epsilon); + + void kalman2kalman_destroy(kalman2kalman_obj * obj); + + void kalman2kalman_init(kalman2kalman_obj * obj, const pots_obj * pots, const unsigned int iPot, kalman_obj * kalman); + + void kalman2kalman_predict(kalman2kalman_obj * obj, kalman_obj * kalman); + + void kalman2kalman_update(kalman2kalman_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, kalman_obj * kalman); + + void kalman2kalman_estimate(kalman2kalman_obj * obj, const kalman_obj * kalman, float * x, float * y, float * z); + +#endif \ No newline at end of file diff --git a/src/system/mixture2mixture.c b/src/system/mixture2mixture.c new file mode 100644 index 0000000..0c86710 --- /dev/null +++ b/src/system/mixture2mixture.c @@ -0,0 +1,230 @@ + + #include "mixture2mixture.h" + + mixture2mixture_obj * mixture2mixture_construct(const gaussians_1d_obj * active_gmm, const gaussians_1d_obj * inactive_gmm, const float diffuse_cst, const float Pfalse, const float Pnew, const float Ptrack, const float epsilon) { + + mixture2mixture_obj * obj; + + obj = (mixture2mixture_obj *) malloc(sizeof(mixture2mixture_obj)); + + obj->active = gaussians_1d_construct_gaussians(active_gmm); + obj->inactive = gaussians_1d_construct_gaussians(inactive_gmm); + obj->diffuse = diffuse_cst; + + obj->Pfalse = Pfalse; + obj->Pnew = Pnew; + obj->Ptrack = Ptrack; + obj->epsilon = epsilon; + + return obj; + + } + + void mixture2mixture_destroy(mixture2mixture_obj * obj) { + + gaussians_1d_destroy(obj->active); + gaussians_1d_destroy(obj->inactive); + + free((void *) obj); + + } + + void mixture2mixture_process(mixture2mixture_obj * obj, mixture_obj * mixture, const pots_obj * pots, const coherences_obj * coherences, postprobs_obj * postprobs) { + + unsigned int iPot; + unsigned int iTrack; + unsigned int iTrackNewFalse; + unsigned int iCombination; + + signed int t; + float total; + unsigned char match; + + // Compute likelihood + + // p(E^s_l|A), p(E^s_l|I) & p(z^s_l|D) + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + mixture->p_Ez_AICD[0 * pots->nPots + iPot] = gaussians_1d_eval(obj->active, pots->array[iPot * 4 + 3]); + mixture->p_Ez_AICD[1 * pots->nPots + iPot] = gaussians_1d_eval(obj->inactive, pots->array[iPot * 4 + 3]); + mixture->p_Ez_AICD[2 * pots->nPots + iPot] = obj->diffuse; + + } + + // p(z^s_l|C,t) + + for (iTrack = 0; iTrack < mixture->nTracks; iTrack++) { + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + mixture->p_Ez_AICD[(3 + iTrack) * pots->nPots + iPot] = coherences->array[iTrack * mixture->nPots + iPot]; + + } + + } + + // p(E^s_l,z^s_l|phis_c) + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + for (iTrackNewFalse = 0; iTrackNewFalse < mixture->nTracksNewFalse; iTrackNewFalse++) { + + t = (((signed int) iTrackNewFalse) - 2); + + if (t == -2) { + + mixture->p_Eszs_phics[iTrackNewFalse * mixture->nPots + iPot] = mixture->p_Ez_AICD[1 * pots->nPots + iPot] * mixture->p_Ez_AICD[2 * pots->nPots + iPot]; + + } + else if (t == -1) { + + mixture->p_Eszs_phics[iTrackNewFalse * mixture->nPots + iPot] = mixture->p_Ez_AICD[0 * pots->nPots + iPot] * mixture->p_Ez_AICD[2 * pots->nPots + iPot]; + + } + else { + + mixture->p_Eszs_phics[iTrackNewFalse * mixture->nPots + iPot] = mixture->p_Ez_AICD[0 * pots->nPots + iPot] * mixture->p_Ez_AICD[(t + 3) * pots->nPots + iPot]; + + } + + } + + } + + // Prior probabilities + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + for (iTrackNewFalse = 0; iTrackNewFalse < mixture->nTracksNewFalse; iTrackNewFalse++) { + + t = (((signed int) iTrackNewFalse) - 2); + + if (t == -2) { + + mixture->p_phics[iTrackNewFalse * mixture->nPots + iPot] = obj->Pfalse; + + } + else if (t == -1) { + + mixture->p_phics[iTrackNewFalse * mixture->nPots + iPot] = obj->Pnew; + + } + else { + + mixture->p_phics[iTrackNewFalse * mixture->nPots + iPot] = obj->Ptrack; + + } + + } + + } + + // Posterior probabilities + + total = obj->epsilon; + + for (iCombination = 0; iCombination < mixture->nCombinations; iCombination++) { + + mixture->p_Ez_phic[iCombination] = 1.0f; + mixture->p_phic[iCombination] = 1.0f; + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + t = mixture->assignations->array[iCombination * mixture->nPots + iPot]; + iTrackNewFalse = (unsigned int) (t + 2); + + mixture->p_Ez_phic[iCombination] *= mixture->p_Eszs_phics[iTrackNewFalse * mixture->nPots + iPot]; + mixture->p_phic[iCombination] *= mixture->p_phics[iTrackNewFalse * mixture->nPots + iPot]; + + } + + mixture->p_phic_Ez[iCombination] = mixture->p_Ez_phic[iCombination] * mixture->p_phic[iCombination]; + + total += mixture->p_phic_Ez[iCombination]; + + } + + for (iCombination = 0; iCombination < mixture->nCombinations; iCombination++) { + + mixture->p_phic_Ez[iCombination] /= total; + + } + + // Tracking - Potential probabilities + + for (iTrack = 0; iTrack < mixture->nTracks; iTrack++) { + + t = ((signed int) iTrack); + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + postprobs->arrayTrack[iTrack * mixture->nPots + iPot] = 0.0f; + + for (iCombination = 0; iCombination < mixture->nCombinations; iCombination++) { + + if (mixture->assignations->array[iCombination * mixture->nPots + iPot] == t) { + + postprobs->arrayTrack[iTrack * mixture->nPots + iPot] += mixture->p_phic_Ez[iCombination]; + + } + + } + + } + + } + + // New probabilities + + postprobs->arrayNew[0] = 0.0f; + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + postprobs->arrayNew[iPot] = 0.0f; + + for (iCombination = 0; iCombination < mixture->nCombinations; iCombination++) { + + if (mixture->assignations->array[iCombination * mixture->nPots + iPot] == -1) { + + postprobs->arrayNew[iPot] += mixture->p_phic_Ez[iCombination]; + + } + + } + + } + + // Tracking probabilities + + for (iTrack = 0; iTrack < mixture->nTracks; iTrack++) { + + t = ((signed int) iTrack); + postprobs->arrayTrackTotal[iTrack] = 0.0f; + + for (iCombination = 0; iCombination < mixture->nCombinations; iCombination++) { + + match = 0; + + for (iPot = 0; iPot < mixture->nPots; iPot++) { + + if (mixture->assignations->array[iCombination * mixture->nPots + iPot] == t) { + + match = 1; + break; + + } + + } + + if (match == 1) { + + postprobs->arrayTrackTotal[iTrack] += mixture->p_phic_Ez[iCombination]; + + } + + } + + } + + } \ No newline at end of file diff --git a/src/system/mixture2mixture.h b/src/system/mixture2mixture.h new file mode 100644 index 0000000..f3dec07 --- /dev/null +++ b/src/system/mixture2mixture.h @@ -0,0 +1,33 @@ +#ifndef __ODAS_SYSTEM_MIXTURE2MIXTURE +#define __ODAS_SYSTEM_MIXTURE2MIXTURE + + #include + #include + #include + + #include "../utils/gaussian.h" + #include "../signal/coherence.h" + #include "../signal/mixture.h" + #include "../signal/pot.h" + #include "../signal/postprob.h" + + typedef struct mixture2mixture_obj { + + gaussians_1d_obj * active; + gaussians_1d_obj * inactive; + float diffuse; + + float Pfalse; + float Pnew; + float Ptrack; + float epsilon; + + } mixture2mixture_obj; + + mixture2mixture_obj * mixture2mixture_construct(const gaussians_1d_obj * active_gmm, const gaussians_1d_obj * inactive_gmm, const float diffuse_cst, const float Pfalse, const float Pnew, const float Ptrack, const float epsilon); + + void mixture2mixture_destroy(mixture2mixture_obj * obj); + + void mixture2mixture_process(mixture2mixture_obj * obj, mixture_obj * mixture, const pots_obj * pots, const coherences_obj * coherences, postprobs_obj * postprobs); + +#endif \ No newline at end of file diff --git a/src/system/particle2coherence.c b/src/system/particle2coherence.c new file mode 100644 index 0000000..ea040e9 --- /dev/null +++ b/src/system/particle2coherence.c @@ -0,0 +1,68 @@ + + #include "particle2coherence.h" + + particle2coherence_obj * particle2coherence_construct(const float sigmaR) { + + particle2coherence_obj * obj; + + obj = (particle2coherence_obj *) malloc(sizeof(particle2coherence_obj)); + + obj->sigmaR = sigmaR; + obj->expScale = 1.0f / (sigmaR*sigmaR*sigmaR * powf(2*M_PI,(3.0f/2.0f))); + obj->expFactor = -1.0f / (2.0f * sigmaR * sigmaR); + + return obj; + + } + + void particle2coherence_destroy(particle2coherence_obj * obj) { + + free((void *) obj); + + } + + void particle2coherence_process(particle2coherence_obj * obj, const particles_obj * particles, const pots_obj * pots, const unsigned int iTrack, coherences_obj * coherences) { + + unsigned int iPot; + unsigned int iParticle; + + float total; + float x1, y1, z1; + float x2, y2, z2, w2; + float dx, dy, dz; + float scale, factor; + float expr; + + scale = obj->expScale; + factor = obj->expFactor; + + for (iPot = 0; iPot < pots->nPots; iPot++) { + + x1 = pots->array[iPot * 4 + 0]; + y1 = pots->array[iPot * 4 + 1]; + z1 = pots->array[iPot * 4 + 2]; + + total = 0.0f; + + for (iParticle = 0; iParticle < particles->nParticles; iParticle++) { + + x2 = particles->array[iParticle * 7 + 0]; + y2 = particles->array[iParticle * 7 + 1]; + z2 = particles->array[iParticle * 7 + 2]; + w2 = particles->array[iParticle * 7 + 6]; + + dx = x1 - x2; + dy = y1 - y2; + dz = z1 - z2; + + total += w2 * expf(factor * (dx*dx + dy*dy + dz*dz)); + + } + + total *= scale; + + coherences->array[iTrack * coherences->nPots + iPot] = total; + + } + + } \ No newline at end of file diff --git a/src/system/particle2coherence.h b/src/system/particle2coherence.h new file mode 100644 index 0000000..ea59c42 --- /dev/null +++ b/src/system/particle2coherence.h @@ -0,0 +1,23 @@ +#ifndef __ODAS_SYSTEM_PARTICLE2COHERENCE +#define __ODAS_SYSTEM_PARTICLE2COHERENCE + + #include "../utils/gaussian.h" + #include "../signal/particle.h" + #include "../signal/coherence.h" + #include "../signal/pot.h" + + typedef struct particle2coherence_obj { + + float sigmaR; + float expScale; + float expFactor; + + } particle2coherence_obj; + + particle2coherence_obj * particle2coherence_construct(const float sigmaR); + + void particle2coherence_destroy(particle2coherence_obj * obj); + + void particle2coherence_process(particle2coherence_obj * obj, const particles_obj * particles, const pots_obj * pots, const unsigned int iTrack, coherences_obj * coherences); + +#endif \ No newline at end of file diff --git a/src/system/particle2particle.c b/src/system/particle2particle.c new file mode 100644 index 0000000..3823f9a --- /dev/null +++ b/src/system/particle2particle.c @@ -0,0 +1,260 @@ + + #include "particle2particle.h" + + particle2particle_obj * particle2particle_construct(const unsigned int nParticles, const float deltaT, const float st_alpha, const float st_beta, const float st_ratio, const float ve_alpha, const float ve_beta, const float ve_ratio, const float ac_alpha, const float ac_beta, const float ac_ratio, const double epsilon, const float sigmaR, const float Nmin) { + + particle2particle_obj * obj; + unsigned int iState; + + obj = (particle2particle_obj *) malloc(sizeof(particle2particle_obj)); + + obj->nParticles = nParticles; + obj->deltaT = deltaT; + + obj->alphas[0] = st_alpha; + obj->alphas[1] = ve_alpha; + obj->alphas[2] = ac_alpha; + obj->betas[0] = st_beta; + obj->betas[1] = ve_beta; + obj->betas[2] = ac_beta; + obj->ratios[0] = st_ratio; + obj->ratios[1] = ve_ratio; + obj->ratios[2] = ac_ratio; + + for (iState = 0; iState < 3; iState++) { + + obj->as[iState] = expf(-1.0f * obj->alphas[iState] * deltaT); + obj->bs[iState] = obj->betas[iState] * sqrtf(1.0f - obj->as[iState] * obj->as[iState]); + + } + + obj->rnd_ratio = random_construct_zero(3); + random_pdf(obj->rnd_ratio, obj->ratios); + obj->indexes_ratio = (unsigned int *) malloc(sizeof(unsigned int) * nParticles); + + obj->pdf_weight = (float *) malloc(sizeof(float) * nParticles); + obj->indexes_weight = (unsigned int *) malloc(sizeof(unsigned int) * nParticles); + obj->rnd_weight = random_construct_zero(nParticles); + + obj->realisation_normal = (float *) malloc(sizeof(float) * nParticles * 3); + obj->normaloff = normaloff_construct_rnd(epsilon, 10000); + + obj->epsilon = epsilon; + obj->Nmin = Nmin; + + obj->sigmaR = sigmaR; + obj->expScale = 1.0f / (sigmaR*sigmaR*sigmaR * powf(2*M_PI,(3.0f/2.0f))); + obj->expFactor = -1.0f / (2.0f * obj->sigmaR * obj->sigmaR); + + obj->sum_P_p_x_O = (float *) malloc(sizeof(float) * nParticles); + obj->particles = particles_construct_zero(nParticles); + + return obj; + + } + + void particle2particle_destroy(particle2particle_obj * obj) { + + random_destroy(obj->rnd_ratio); + free((void *) obj->indexes_ratio); + + free((void *) obj->pdf_weight); + free((void *) obj->indexes_weight); + random_destroy(obj->rnd_weight); + + free((void *) obj->realisation_normal); + normaloff_destroy(obj->normaloff); + + free((void *) obj->sum_P_p_x_O); + particles_destroy(obj->particles); + + free((void *) obj); + + } + + void particle2particle_init(particle2particle_obj * obj, const pots_obj * pots, const unsigned int iPot, particles_obj * particles) { + + unsigned int iParticle; + + random_generate(obj->rnd_ratio, obj->nParticles, obj->indexes_ratio); + + memset(particles->array, 0x00, sizeof(float) * 7 * obj->nParticles); + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + particles->array[iParticle * 7 + 0] = pots->array[iPot * 4 + 0]; + particles->array[iParticle * 7 + 1] = pots->array[iPot * 4 + 1]; + particles->array[iParticle * 7 + 2] = pots->array[iPot * 4 + 2]; + particles->array[iParticle * 7 + 6] = (1.0f / ((float) obj->nParticles)); + + particles->state[iParticle] = (unsigned char) (obj->indexes_ratio[iParticle]); + + } + + } + + void particle2particle_predict(particle2particle_obj * obj, particles_obj * particles) { + + unsigned int iParticle; + float a, b; + + normaloff_generate(obj->normaloff, obj->nParticles * 3, obj->realisation_normal); + + for (iParticle = 0; iParticle < particles->nParticles; iParticle++) { + + a = obj->as[particles->state[iParticle]]; + b = obj->bs[particles->state[iParticle]]; + + particles->array[iParticle * 7 + 3] = a * particles->array[iParticle * 7 + 3] + b * obj->realisation_normal[iParticle * 3 + 0]; + particles->array[iParticle * 7 + 4] = a * particles->array[iParticle * 7 + 4] + b * obj->realisation_normal[iParticle * 3 + 1]; + particles->array[iParticle * 7 + 5] = a * particles->array[iParticle * 7 + 5] + b * obj->realisation_normal[iParticle * 3 + 2]; + + particles->array[iParticle * 7 + 0] = particles->array[iParticle * 7 + 0] + obj->deltaT * particles->array[iParticle * 7 + 3]; + particles->array[iParticle * 7 + 1] = particles->array[iParticle * 7 + 1] + obj->deltaT * particles->array[iParticle * 7 + 4]; + particles->array[iParticle * 7 + 2] = particles->array[iParticle * 7 + 2] + obj->deltaT * particles->array[iParticle * 7 + 5]; + + } + + } + + void particle2particle_update(particle2particle_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, particles_obj * particles) { + + unsigned int iParticle; + unsigned int iPot; + float x1, y1, z1; + float x2, y2, z2; + float dx, dy, dz; + float scale, factor; + float postprob; + float expr, value; + float uniform, alpha, oneminusalpha, alphanorm; + float p_x_O; + + float total_sum_P_p_x_O; + float total_w; + + float Neff; + + // Compute sum{P_q,j * p(O_q|x_j,i)}, and normalize + + memset(obj->sum_P_p_x_O, 0x00, sizeof(float) * obj->nParticles); + + total_sum_P_p_x_O = obj->epsilon; + scale = obj->expScale; + factor = obj->expFactor; + + for (iPot = 0; iPot < pots->nPots; iPot++) { + + x1 = pots->array[iPot * 4 + 0]; + y1 = pots->array[iPot * 4 + 1]; + z1 = pots->array[iPot * 4 + 2]; + + postprob = postprobs->arrayTrack[iTrack * pots->nPots + iPot]; + + for (iParticle = 0; iParticle < particles->nParticles; iParticle++) { + + x2 = particles->array[iParticle * 7 + 0]; + y2 = particles->array[iParticle * 7 + 1]; + z2 = particles->array[iParticle * 7 + 2]; + + dx = x1 - x2; + dy = y1 - y2; + dz = z1 - z2; + + // We don't need the scale since we normalize + expr = expf(factor * (dx*dx + dy*dy + dz*dz)); + value = postprob * expr; + + obj->sum_P_p_x_O[iParticle] += value; + total_sum_P_p_x_O += value; + + } + + } + + // Compute p(x_j,i|O) and update weights + + uniform = (1.0f/((float) obj->nParticles)); + alpha = postprobs->arrayTrackTotal[iTrack]; + oneminusalpha = (1.0f - alpha); + alphanorm = alpha / total_sum_P_p_x_O; + + total_w = obj->epsilon; + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + p_x_O = oneminusalpha * uniform + alphanorm * obj->sum_P_p_x_O[iParticle]; + particles->array[iParticle * 7 + 6] *= p_x_O; + total_w += particles->array[iParticle * 7 + 6]; + + } + + Neff = obj->epsilon; + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + particles->array[iParticle * 7 + 6] /= total_w; + Neff += particles->array[iParticle * 7 + 6] * particles->array[iParticle * 7 + 6]; + + } + + // Resample if needed + + Neff = 1.0f / Neff; + + if (Neff < (obj->Nmin * (float) obj->nParticles)) { + + memcpy(obj->particles->array, particles->array, sizeof(float) * 7 * obj->nParticles); + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + obj->pdf_weight[iParticle] = obj->particles->array[iParticle * 7 + 6]; + + } + + random_pdf(obj->rnd_weight, obj->pdf_weight); + random_generate(obj->rnd_weight, obj->nParticles, obj->indexes_weight); + random_generate(obj->rnd_ratio, obj->nParticles, obj->indexes_ratio); + uniform = (1.0f/((float) obj->nParticles)); + + for (iParticle = 0; iParticle < obj->nParticles; iParticle++) { + + particles->array[iParticle * 7 + 0] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 0]; + particles->array[iParticle * 7 + 1] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 1]; + particles->array[iParticle * 7 + 2] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 2]; + particles->array[iParticle * 7 + 3] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 3]; + particles->array[iParticle * 7 + 4] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 4]; + particles->array[iParticle * 7 + 5] = obj->particles->array[obj->indexes_weight[iParticle] * 7 + 5]; + + particles->state[iParticle] = (unsigned char) obj->indexes_ratio[iParticle]; + + particles->array[iParticle * 7 + 6] = uniform; + + } + + } + + } + + void particle2particle_estimate(const particle2particle_obj * obj, const particles_obj * particles, float * x, float * y, float * z) { + + unsigned int iParticle; + float xTotal, yTotal, zTotal; + + xTotal = 0.0f; + yTotal = 0.0f; + zTotal = 0.0f; + + for (iParticle = 0; iParticle < particles->nParticles; iParticle++) { + + xTotal += particles->array[iParticle * 7 + 6] * particles->array[iParticle * 7 + 0]; + yTotal += particles->array[iParticle * 7 + 6] * particles->array[iParticle * 7 + 1]; + zTotal += particles->array[iParticle * 7 + 6] * particles->array[iParticle * 7 + 2]; + + } + + *x = xTotal; + *y = yTotal; + *z = zTotal; + + } \ No newline at end of file diff --git a/src/system/particle2particle.h b/src/system/particle2particle.h new file mode 100644 index 0000000..0dfa4f4 --- /dev/null +++ b/src/system/particle2particle.h @@ -0,0 +1,56 @@ +#ifndef __ODAS_SYSTEM_PARTICLE2PARTICLE +#define __ODAS_SYSTEM_PARTICLE2PARTICLE + + #include "../utils/gaussian.h" + #include "../utils/random.h" + #include "../signal/particle.h" + #include "../signal/postprob.h" + #include "../signal/pot.h" + + typedef struct particle2particle_obj { + + unsigned int nParticles; + float deltaT; + + float alphas[3]; + float betas[3]; + float as[3]; + float bs[3]; + float ratios[3]; + + float sigmaR; + float expScale; + float expFactor; + + float * pdf_ratio; + unsigned int * indexes_ratio; + random_obj * rnd_ratio; + + float * pdf_weight; + unsigned int * indexes_weight; + random_obj * rnd_weight; + + float * realisation_normal; + double epsilon; + normaloff_obj * normaloff; + + float * sum_P_p_x_O; + particles_obj * particles; + + float Nmin; + + } particle2particle_obj; + + particle2particle_obj * particle2particle_construct(const unsigned int nParticles, const float deltaT, const float st_alpha, const float st_beta, const float st_ratio, const float ve_alpha, const float ve_beta, const float ve_ratio, const float ac_alpha, const float ac_beta, const float ac_ratio, const double epsilon, const float sigmaR, const float Nmin); + + void particle2particle_destroy(particle2particle_obj * obj); + + void particle2particle_init(particle2particle_obj * obj, const pots_obj * pots, const unsigned int iPot, particles_obj * particles); + + void particle2particle_predict(particle2particle_obj * obj, particles_obj * particles); + + void particle2particle_update(particle2particle_obj * obj, const postprobs_obj * postprobs, const unsigned int iTrack, const pots_obj * pots, particles_obj * particles); + + void particle2particle_estimate(const particle2particle_obj * obj, const particles_obj * particles, float * x, float * y, float * z); + +#endif \ No newline at end of file diff --git a/src/system/shift2freq.c b/src/system/shift2freq.c new file mode 100644 index 0000000..9cc1692 --- /dev/null +++ b/src/system/shift2freq.c @@ -0,0 +1,68 @@ + + #include "shift2freq.h" + + shift2freq_obj * shift2freq_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize) { + + shift2freq_obj * obj; + unsigned int iSample; + + obj = (shift2freq_obj *) malloc(sizeof(shift2freq_obj)); + + obj->nChannels = nChannels; + obj->halfFrameSize = halfFrameSize; + + obj->array = (float *) malloc(sizeof(float) * halfFrameSize); + + for (iSample = 0; iSample < halfFrameSize; iSample++) { + + obj->array[iSample] = 2.0f * M_PI * ((float) iSample) / ((float) ((halfFrameSize-1)*2)); + + } + + return obj; + + } + + void shift2freq_destroy(shift2freq_obj * obj) { + + free((void *) obj); + + } + + void shift2freq_process(shift2freq_obj * obj, const shifts_obj * shifts, const gains_obj * gains, const masks_obj * masks, freqs_obj * freqs) { + + unsigned int iChannel; + unsigned int iSample; + float gainTotal; + float normalize; + + gainTotal = 0.0f; + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + if (masks->array[iChannel] == 0x01) { + + gainTotal += gains->array[iChannel]; + + } + + } + + normalize = 1.0f / (gainTotal); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + if (masks->array[iChannel] == 0x01) { + + for (iSample = 0; iSample < obj->halfFrameSize; iSample++) { + + freqs->array[iChannel][iSample*2+0] = normalize * gains->array[iChannel] * cosf(obj->array[iSample] * shifts->array[iChannel]); + freqs->array[iChannel][iSample*2+1] = normalize * gains->array[iChannel] * sinf(obj->array[iSample] * shifts->array[iChannel]); + + } + + } + + } + + } \ No newline at end of file diff --git a/src/system/shift2freq.h b/src/system/shift2freq.h new file mode 100644 index 0000000..5e64de3 --- /dev/null +++ b/src/system/shift2freq.h @@ -0,0 +1,28 @@ +#ifndef __ODAS_SYSTEM_SHIFT2FREQ +#define __ODAS_SYSTEM_SHIFT2FREQ + + #include "../signal/gain.h" + #include "../signal/mask.h" + #include "../signal/shift.h" + #include "../signal/freq.h" + + #include + #include + #include + + typedef struct shift2freq_obj { + + unsigned int nChannels; + unsigned int halfFrameSize; + + float * array; + + } shift2freq_obj; + + shift2freq_obj * shift2freq_construct_zero(const unsigned int nChannels, const unsigned int halfFrameSize); + + void shift2freq_destroy(shift2freq_obj * obj); + + void shift2freq_process(shift2freq_obj * obj, const shifts_obj * shifts, const gains_obj * gains, const masks_obj * masks, freqs_obj * freqs); + +#endif \ No newline at end of file diff --git a/src/system/track2gain.c b/src/system/track2gain.c new file mode 100644 index 0000000..2088cfe --- /dev/null +++ b/src/system/track2gain.c @@ -0,0 +1,88 @@ + + #include "track2gain.h" + + track2gain_obj * track2gain_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const float * directions) { + + track2gain_obj * obj; + + obj = (track2gain_obj *) malloc(sizeof(track2gain_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + + obj->directions = (float *) malloc(sizeof(float) * nChannels * 3); + memcpy(obj->directions, directions, sizeof(float) * nChannels * 3); + + return obj; + + } + + void track2gain_destroy(track2gain_obj * obj) { + + free((void *) obj->directions); + free((void *) obj); + + } + + void track2gain_process(track2gain_obj * obj, const beampatterns_obj * beampatterns, const tracks_obj * tracks, gains_obj * gains) { + + unsigned int iSep; + unsigned int iChannel; + unsigned int iTheta; + + float ux, uy, uz; + float uNorm; + float dx, dy, dz; + float dNorm; + + float proj; + float theta; + float gain; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + ux = tracks->array[iSep * 3 + 0]; + uy = tracks->array[iSep * 3 + 1]; + uz = tracks->array[iSep * 3 + 2]; + + uNorm = sqrtf(ux * ux + uy * uy + uz * uz); + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + dx = obj->directions[iChannel * 3 + 0]; + dy = obj->directions[iChannel * 3 + 1]; + dz = obj->directions[iChannel * 3 + 2]; + + dNorm = sqrtf(dx * dx + dy * dy + dz * dz); + + proj = dx * ux + dy * uy + dz * uz; + + theta = (360.0f/(2.0f * M_PI)) * acosf(proj / (dNorm * uNorm)); + + iTheta = roundf((theta - beampatterns->minThetas[iChannel]) / (beampatterns->deltaThetas[iChannel]) + beampatterns->minThetas[iChannel]); + + if (iTheta < 0) { + iTheta = 0; + } + if (iTheta >= beampatterns->nThetas) { + iTheta = beampatterns->nThetas - 1; + } + + gain = beampatterns->gains[iChannel * beampatterns->nThetas + iTheta]; + + gains->array[iSep * obj->nChannels + iChannel] = gain; + + } + + } + else { + + memset(&(gains->array[iSep * obj->nChannels]), 0x00, sizeof(float) * obj->nChannels); + + } + + } + + } \ No newline at end of file diff --git a/src/system/track2gain.h b/src/system/track2gain.h new file mode 100644 index 0000000..4a2e1db --- /dev/null +++ b/src/system/track2gain.h @@ -0,0 +1,27 @@ +#ifndef __ODAS_SYSTEM_TRACK2GAIN +#define __ODAS_SYSTEM_TRACK2GAIN + + #include "../signal/beampattern.h" + #include "../signal/track.h" + #include "../signal/gain.h" + + #include + #include + #include + + typedef struct track2gain_obj { + + unsigned int nSeps; + unsigned int nChannels; + float * directions; + + } track2gain_obj; + + track2gain_obj * track2gain_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const float * directions); + + void track2gain_destroy(track2gain_obj * obj); + + void track2gain_process(track2gain_obj * obj, const beampatterns_obj * beampatterns, const tracks_obj * tracks, gains_obj * gains); + + +#endif \ No newline at end of file diff --git a/src/system/track2shift.c b/src/system/track2shift.c new file mode 100644 index 0000000..87cac52 --- /dev/null +++ b/src/system/track2shift.c @@ -0,0 +1,58 @@ + + #include "track2shift.h" + + track2shift_obj * track2shift_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int fS, const unsigned int c, const float * mics) { + + track2shift_obj * obj; + + obj = (track2shift_obj *) malloc(sizeof(track2shift_obj)); + + obj->nSeps = nSeps; + obj->nChannels = nChannels; + obj->fS = fS; + obj->c = c; + + obj->mics = (float *) malloc(sizeof(float) * nChannels * 3); + memcpy(obj->mics, mics, sizeof(float) * nChannels * 3); + + return obj; + + } + + void track2shift_destroy(track2shift_obj * obj) { + + free((void *) obj->mics); + free((void *) obj); + + } + + void track2shift_process(track2shift_obj * obj, const tracks_obj * tracks, shifts_obj * shifts) { + + unsigned int iSep; + unsigned int iChannel; + float dist; + + for (iSep = 0; iSep < obj->nSeps; iSep++) { + + if (tracks->ids[iSep] != 0) { + + for (iChannel = 0; iChannel < obj->nChannels; iChannel++) { + + dist = tracks->array[iSep * 3 + 0] * obj->mics[iChannel * 3 + 0] + + tracks->array[iSep * 3 + 1] * obj->mics[iChannel * 3 + 1] + + tracks->array[iSep * 3 + 2] * obj->mics[iChannel * 3 + 2]; + + shifts->array[iSep * obj->nChannels + iChannel] = (((float) obj->fS) / obj->c) * dist; + + } + + } + else { + + memset(&(shifts->array[iSep * obj->nChannels]), 0x00, sizeof(float) * obj->nChannels); + + } + + } + + } \ No newline at end of file diff --git a/src/system/track2shift.h b/src/system/track2shift.h new file mode 100644 index 0000000..111797f --- /dev/null +++ b/src/system/track2shift.h @@ -0,0 +1,23 @@ +#ifndef __ODAS_SYSTEM_TRACK2SHIFT +#define __ODAS_SYSTEM_TRACK2SHIFT + + #include "../signal/track.h" + #include "../signal/shift.h" + + typedef struct track2shift_obj { + + unsigned int nSeps; + unsigned int nChannels; + unsigned int fS; + float c; + float * mics; + + } track2shift_obj; + + track2shift_obj * track2shift_construct_zero(const unsigned int nSeps, const unsigned int nChannels, const unsigned int fS, const unsigned int c, const float * mics); + + void track2shift_destroy(track2shift_obj * obj); + + void track2shift_process(track2shift_obj * obj, const tracks_obj * tracks, shifts_obj * shifts); + +#endif \ No newline at end of file diff --git a/src/system/xcorr2aimg.c b/src/system/xcorr2aimg.c new file mode 100644 index 0000000..892bd9c --- /dev/null +++ b/src/system/xcorr2aimg.c @@ -0,0 +1,50 @@ + + #include "xcorr2aimg.h" + + xcorr2aimg_obj * xcorr2aimg_construct_zero(const unsigned int aimgSize) { + + xcorr2aimg_obj * obj; + + obj = (xcorr2aimg_obj *) malloc(sizeof(xcorr2aimg_obj)); + + obj->aimgSize = aimgSize; + + return obj; + + } + + void xcorr2aimg_destroy(xcorr2aimg_obj * obj) { + + free((void *) obj); + + } + + void xcorr2aimg_process(xcorr2aimg_obj * obj, const tdoas_obj * tdoas, const indexes_obj * indexes, const spatialindexes_obj * spatialindexes, const unsigned int iCoarse, const xcorrs_obj * xcorrs, aimg_obj * aimg) { + + unsigned int iSpatialIndex; + unsigned int iPair; + unsigned int iFine; + unsigned int iPoint; + unsigned int tau; + + memset(aimg->array, 0x00, sizeof(float) * aimg->aimgSize); + + for (iFine = 0; iFine < indexes->count[iCoarse]; iFine++) { + + iPoint = indexes->array[iCoarse * indexes->nFines + iFine]; + + for (iSpatialIndex = 0; iSpatialIndex < spatialindexes->count[iPoint]; iSpatialIndex++) { + + iPair = spatialindexes->array[iPoint * spatialindexes->nPairs + iSpatialIndex]; + + tau = tdoas->array[iPoint * tdoas->nPairs + iPair]; + + aimg->array[iPoint] += xcorrs->array[iPair][tau]; + + } + + aimg->array[iPoint] /= ((float) spatialindexes->count[iPoint]); + + } + + } \ No newline at end of file diff --git a/src/system/xcorr2aimg.h b/src/system/xcorr2aimg.h new file mode 100644 index 0000000..8e44810 --- /dev/null +++ b/src/system/xcorr2aimg.h @@ -0,0 +1,25 @@ +#ifndef __ODAS_SYSTEM_XCORR2AIMG +#define __ODAS_SYSTEM_XCORR2AIMG + + #include + + #include "../signal/tdoa.h" + #include "../signal/index.h" + #include "../signal/xcorr.h" + #include "../signal/aimg.h" + #include "../signal/spatialindex.h" + + //! Update the states of the particle filter + typedef struct xcorr2aimg_obj { + + unsigned int aimgSize; ///< Number of points scanned. + + } xcorr2aimg_obj; + + xcorr2aimg_obj * xcorr2aimg_construct_zero(const unsigned int aimgSize); + + void xcorr2aimg_destroy(xcorr2aimg_obj * obj); + + void xcorr2aimg_process(xcorr2aimg_obj * obj, const tdoas_obj * tdoas, const indexes_obj * indexes, const spatialindexes_obj * spatialindexes, const unsigned int iCoarse, const xcorrs_obj * xcorrs, aimg_obj * aimg); + +#endif \ No newline at end of file diff --git a/src/system/xcorr2xcorr.c b/src/system/xcorr2xcorr.c new file mode 100644 index 0000000..c7d5385 --- /dev/null +++ b/src/system/xcorr2xcorr.c @@ -0,0 +1,85 @@ + + #include "xcorr2xcorr.h" + + xcorr2xcorr_obj * xcorr2xcorr_construct_zero(const unsigned int frameSize) { + + xcorr2xcorr_obj * obj; + + obj = (xcorr2xcorr_obj *) malloc(sizeof(xcorr2xcorr_obj)); + + obj->frameSize = frameSize; + + return obj; + + } + + void xcorr2xcorr_destroy(xcorr2xcorr_obj * obj) { + + free((void *) obj); + + } + + void xcorr2xcorr_process_max(xcorr2xcorr_obj * obj, const xcorrs_obj * xcorrs, const tdoas_obj * tdoas, const deltas_obj * deltas, const pairs_obj * pairs, xcorrs_obj * xcorrsMax) { + + unsigned int iSignal; + unsigned int iSampleMax; + unsigned int iSampleMaxLeft; + unsigned int iSampleMaxRight; + unsigned int iSample; + unsigned int delta; + float maxValue; + + for (iSignal = 0; iSignal < xcorrs->nSignals; iSignal++) { + + if (pairs->array[iSignal] == 0x01) { + + delta = deltas->array[iSignal]; + iSampleMaxLeft = tdoas->min[iSignal]; + iSampleMaxRight = tdoas->max[iSignal]; + + for (iSampleMax = iSampleMaxLeft; iSampleMax <= iSampleMaxRight; iSampleMax++) { + + maxValue = xcorrs->array[iSignal][iSampleMax]; + + for (iSample = (iSampleMax-delta); iSample <= (iSampleMax+delta); iSample++) { + + if (xcorrs->array[iSignal][iSample] > maxValue) { + + maxValue = xcorrs->array[iSignal][iSample]; + + } + + } + + xcorrsMax->array[iSignal][iSampleMax] = maxValue; + + } + + } + + } + + } + + void xcorr2xcorr_process_reset(xcorr2xcorr_obj * obj, const tdoas_obj * tdoas, const deltas_obj * deltas, const pairs_obj * pairs, const unsigned int iPoint, xcorrs_obj * xcorrs) { + + unsigned int iSignal; + unsigned int iSample; + unsigned int nSamples; + unsigned int delta; + + for (iSignal = 0; iSignal < xcorrs->nSignals; iSignal++) { + + if (pairs->array[iSignal] == 0x01) { + + delta = deltas->array[iSignal]; + iSample = tdoas->array[iPoint * tdoas->nPairs + iSignal] - delta; + nSamples = 2 * delta + 1; + + memset(&(xcorrs->array[iSignal][iSample]), 0x00, sizeof(float) * nSamples); + + } + + } + + } diff --git a/src/system/xcorr2xcorr.h b/src/system/xcorr2xcorr.h new file mode 100644 index 0000000..365a9e6 --- /dev/null +++ b/src/system/xcorr2xcorr.h @@ -0,0 +1,26 @@ +#ifndef __ODAS_SYSTEM_XCORR +#define __ODAS_SYSTEM_XCORR + + #include + #include + + #include "../signal/delta.h" + #include "../signal/xcorr.h" + #include "../signal/tdoa.h" + #include "../signal/pair.h" + + typedef struct xcorr2xcorr_obj { + + unsigned int frameSize; ///< Number of samples per frame. + + } xcorr2xcorr_obj; + + xcorr2xcorr_obj * xcorr2xcorr_construct_zero(const unsigned int frameSize); + + void xcorr2xcorr_destroy(xcorr2xcorr_obj * obj); + + void xcorr2xcorr_process_max(xcorr2xcorr_obj * obj, const xcorrs_obj * xcorrs, const tdoas_obj * tdoas, const deltas_obj * deltas, const pairs_obj * pairs, xcorrs_obj * xcorrsMax); + + void xcorr2xcorr_process_reset(xcorr2xcorr_obj * obj, const tdoas_obj * tdoas, const deltas_obj * deltas, const pairs_obj * pairs, const unsigned int iPoint, xcorrs_obj * xcorrs); + +#endif \ No newline at end of file -- 2.34.1