Debian Codegraph @

src/multichannel/tests/firpfbch_crcf_synthesizer_autotest.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2007 - 2026 Joseph Gaeddert
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23 #include <assert.h>
24 #include "liquid.autotest.h"cxx . . $ `<file>/include/liquid.autotest.h`/
25 #include "liquid.h"cxx . . $ `<file>/include/liquid.h`/
26
27 LIQUID_AUTOTESTcxx . . $ `include/liquid.autotest.h:92:9`!(firpfbch_crcf_synthesis,"validate firpfbch synthesis correctness","",0.1)
28 {
29 // options
30 float tol = 1e-4f; // error tolerance
31 unsigned int num_channels=4; // number of channels
32 unsigned int p=5; // filter length (symbols)
33 unsigned int num_symbols=40; // number of symbols
34
35 // derived values
36 unsigned int num_samples = num_channels * num_symbols;
37
38 unsigned int i;
39 unsigned int j;
40
41 // generate filter
42 // NOTE : these coefficients can be random; the purpose of this
43 // exercise is to demonstrate mathematical equivalence.
44 // For the sake of consistency, use pseudo-random values
45 // chosen from m-sequences
46 unsigned int h_len = p*num_channels;
47 float h[h_len];
48 msequencecxx . . $ msequence# ms = msequence_create_defaultcxx . . $ msequence_create_default(c501917398a8b71b).(6);
49 for (i=0; i<h_len; i++)
50 h[i] = (float)msequence_generate_symbolcxx . . $ msequence_generate_symbol(60332c0e3dd17f91).(ms, 2) - 1.5f; // (-1.5, -0.5, 0.5, 1.5)
51 msequence_destroycxx . . $ msequence_destroy(34d4b8ff5a4773b3).(ms);
52
53 // create filter object
54 firfilt_crcfcxx . . $ firfilt_crcf# f = firfilt_crcf_createcxx . . $ firfilt_crcf_create(22c884c7366accc6).(h, h_len);
55
56 // create filterbank channelizer object
57 firpfbch_crcfcxx . . $ firpfbch_crcf# q = firpfbch_crcf_createcxx . . $ firpfbch_crcf_create(be2350ee41e869fb).(LIQUID_SYNTHESIZERcxx . . $ `include/liquid.h:9266:9`!, num_channels, p, h);
58
59 float complexcxx . . $ `<external>/4939322597784029111/complex.h:43:9`! Y[num_symbols][num_channels]; // channelized input
60 float complexcxx . . $ `<external>/4939322597784029111/complex.h:43:9`! y0[num_samples]; // time-domain output
61 float complexcxx . . $ `<external>/4939322597784029111/complex.h:43:9`! y1[num_samples]; // time-domain output
62
63 // generate input sequence (complex noise)
64 ms = msequence_create_defaultcxx . . $ msequence_create_default(c501917398a8b71b).(7);
65 for (i=0; i<num_symbols; i++) {
66 for (j=0; j<num_channels; j++) {
67 Y[i][j] = 0.1f * M_SQRT1_2cxx . . $ `<external>/11263917310783833665/math.h:1128:10`! * ((float)msequence_generate_symbolcxx . . $ msequence_generate_symbol(60332c0e3dd17f91).(ms,2) - 1.5f) +
68 0.1f * M_SQRT1_2cxx . . $ `<external>/11263917310783833665/math.h:1128:10`! * ((float)msequence_generate_symbolcxx . . $ msequence_generate_symbol(60332c0e3dd17f91).(ms,2) - 1.5f)*_Complex_Icxx . . $ `<external>/4939322597784029111/complex.h:48:9`!;
69 }
70 }
71 msequence_destroycxx . . $ msequence_destroy(34d4b8ff5a4773b3).(ms);
72
73 //
74 // run synthesis filter bank
75 //
76
77 for (i=0; i<num_symbols; i++)
78 firpfbch_crcf_synthesizer_executecxx . . $ firpfbch_crcf_synthesizer_execute(259569ec6f4f7ad6).(q, &Y[i][0], &y0[i*num_channels]);
79
80 //
81 // run traditional up-converter (inefficient)
82 //
83
84 // clear output array
85 for (i=0; i<num_samples; i++)
86 y1[i] = 0.0f;
87
88 unsigned int n;
89 float dphi; // carrier frequency
90 float complexcxx . . $ `<external>/4939322597784029111/complex.h:43:9`! y_hat;
91 for (i=0; i<num_channels; i++) {
92 // reset filter
93 firfilt_crcf_resetcxx . . $ firfilt_crcf_reset(a5f2ec02d7ba5b83).(f);
94
95 // set center frequency
96 dphi = 2.0f * M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`! * (float)i / (float)num_channels;
97
98 // reset input symbol counter
99 n=0;
100
101 for (j=0; j<num_samples; j++) {
102
103 // interpolate sequence
104 if ( (j%num_channels)==0 ) {
105 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(n<num_symbols);
106 firfilt_crcf_pushcxx . . $ firfilt_crcf_push(4e53e13cc9ce52a2).(f, Y[n][i]);
107 n++;
108 } else {
109 firfilt_crcf_pushcxx . . $ firfilt_crcf_push(4e53e13cc9ce52a2).(f, 0);
110 }
111 firfilt_crcf_executecxx . . $ firfilt_crcf_execute(1fb37bc14e1b8467).(f, &y_hat);
112
113 // accumulate up-converted sample
114 y1[j] += y_hat * cexpf(_Complex_Icxx . . $ `<external>/4939322597784029111/complex.h:48:9`!*j*dphi);
115 }
116 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(n==num_symbols);
117 }
118
119 // destroy objects
120 firfilt_crcf_destroycxx . . $ firfilt_crcf_destroy(a5f2ec02d7ba5b83).(f);
121 firpfbch_crcf_destroycxx . . $ firpfbch_crcf_destroy(e48403c6524b5248).(q);
122
123 // compare results
124 for (i=0; i<num_samples; i++) {
125 liquid_log_debugcxx . . $ `include/liquid.h:415:11`!("%3u: old:%8.5f+j%8.5f, firpfbch:%8.5f+j%8.5f, error:%12.4e+j%12.4f",
126 i,
127 crealf(y0[i]), cimagf(y0[i]),
128 crealf(y1[i]), cimagf(y1[i]),
129 crealf(y1[i]-y0[i]), cimagf(y1[i]-y0[i]));
130
131 LIQUID_CHECK_DELTAcxx . . $ `include/liquid.autotest.h:249:9`!( crealf(y0[i]), crealf(y1[i]), tol );
132 LIQUID_CHECK_DELTAcxx . . $ `include/liquid.autotest.h:249:9`!( cimagf(y0[i]), cimagf(y1[i]), tol );
133 }
134 }
135