use cic filter for decimation in analyzer

This commit is contained in:
Ahmet Inan 2015-01-08 22:18:50 +01:00
parent 659a644362
commit 9dcbdbdc69
2 changed files with 65 additions and 2 deletions

55
app/src/main/rs/cic.rsh Normal file
View file

@ -0,0 +1,55 @@
/*
Copyright 2015 Ahmet Inan <xdsopl@googlemail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef CIC_RSH
#define CIC_RSH
typedef struct {
int prev_comb, prev_int;
} cic_t;
static const int cic_cascade_order = 5;
typedef struct {
cic_t cic[cic_cascade_order];
} cic_cascade_t;
static int cic_comb(cic_t *cic, int input)
{
int output = input - cic->prev_comb;
cic->prev_comb = input;
return output;
}
static int cic_int(cic_t *cic, int input)
{
return cic->prev_int = input + cic->prev_int;
}
static int cic_comb_cascade(cic_cascade_t *cascade, int input)
{
for (int i = 0; i < cic_cascade_order; ++i)
input = cic_comb(cascade->cic + i, input);
return input;
}
static int cic_int_cascade(cic_cascade_t *cascade, int input)
{
for (int i = 0; i < cic_cascade_order; ++i)
input = cic_int(cascade->cic + i, input);
return input;
}
#endif

View file

@ -22,6 +22,7 @@ limitations under the License.
#include "utils.rsh"
#include "complex.rsh"
#include "radix2.rsh"
#include "cic.rsh"
#include "stft_generated.rsh"
static inline uchar4 rainbow(float v)
@ -43,11 +44,18 @@ static void freq_marker(int freq)
static void spectrum_analyzer(int amplitude)
{
const int M = 7;
static int n;
static int n, m;
static complex_t input[radix2_N];
static complex_t output[radix2_N];
static cic_cascade_t cascade;
input[(n/M)&(radix2_N-1)] += complex(stft_w[n] * amplitude, 0.0f);
int tmp = cic_int_cascade(&cascade, amplitude);
if (++m < M)
return;
m = 0;
amplitude = cic_comb_cascade(&cascade, tmp);
input[n&(radix2_N-1)] += complex(stft_w[n] * amplitude, 0.0f);
if (++n >= stft_N) {
n = 0;
// yep, were wasting 3x performance