Skip to content

Commit d464178

Browse files
committed
Add envelope extractor
1 parent b5d8f2f commit d464178

2 files changed

Lines changed: 152019 additions & 152001 deletions

File tree

raw2plot.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,32 @@
1010

1111
FILE *in, *out;
1212

13+
static float env(float f)
14+
{
15+
static float lmax = 0, pf = 0, diff = 0;
16+
float pdiff;
17+
18+
pdiff = diff;
19+
diff = f - pf;
20+
if (pdiff >= 0 && diff < 0)
21+
{
22+
/* f > lmax or derivative changed sign into negative (zero case a *bit* edgy): local maximum. */
23+
lmax = pf;
24+
}
25+
pf = f;
26+
return lmax;
27+
}
28+
1329
static void print(void)
1430
{
1531
unsigned long i;
1632
ssize_t r;
1733
float f;
1834

35+
fprintf(out, "sample out env\n");
1936
i = 0;
2037
while ((r = fread(&f, sizeof(float), 1, in)) == 1)
21-
fprintf(out, "%ld %f\n", i++, f);
38+
fprintf(out, "%ld %f %f\n", i++, f, env(f));
2239
}
2340

2441
int main(int argc, char *argv[])

0 commit comments

Comments
 (0)