This repository has been archived by the owner on Jun 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
dsp.c
50 lines (39 loc) · 1.11 KB
/
dsp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// $Id: dsp.c,v 1.2 2018/12/05 09:07:18 karn Exp $
// low-level subroutines useful in digital signal processing - mainly math related
// Copyright 2018, Phil Karn, KA9Q
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1 // Needed to get sincos/sincosf
#endif
#include <complex.h>
#include <math.h>
#include "dsp.h"
// return unit magnitude complex number with phase x radians
// I.e., cos(x) + j*sin(x)
complex float const csincosf(const float x){
float s,c;
sincosf(x,&s,&c);
return CMPLXF(c,s);
}
complex float const csincospif(const float x){
float s,c;
sincospif(x,&s,&c);
return CMPLXF(c,s);
}
// return unit magnitude complex number with given phase x
complex double const csincos(const double x){
double s,c;
sincos(x,&s,&c);
return CMPLX(c,s);
}
complex double const csincospi(const double x){
double s,c;
sincospi(x,&s,&c);
return CMPLX(c,s);
}
// Complex norm (sum of squares of real and imaginary parts)
float const cnrmf(const complex float x){
return crealf(x)*crealf(x) + cimagf(x) * cimagf(x);
}
double const cnrm(const complex double x){
return creal(x)*creal(x) + cimag(x) * cimag(x);
}