File: compand_cf_example.c

package info (click to toggle)
liquid-dsp 1.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,216 kB
  • sloc: ansic: 115,859; sh: 3,513; makefile: 1,350; python: 274; asm: 11
file content (64 lines) | stat: -rw-r--r-- 1,723 bytes parent folder | download | duplicates (5)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// compand_cf_example.c
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "liquid.h"

#define OUTPUT_FILENAME "compand_cf_example.m"

int main() {
    // options
    float mu=255.0f;
    int n=31;

    // open debug file
    FILE * fid = fopen(OUTPUT_FILENAME,"w");
    fprintf(fid,"%% %s: auto-generated file\n\n", OUTPUT_FILENAME);
    fprintf(fid,"clear all\n");
    fprintf(fid,"close all\n");

    float complex x, y, z;
    int i, j;

    for (i=0; i<n+1; i++) {
        for (j=0; j<n+1; j++) {
            x = (float)(2*i - n)/(float)(n) + _Complex_I*(float)(2*j-n)/(float)(n);
            compress_cf_mulaw(x,mu,&y);
            expand_cf_mulaw(y,mu,&z);

            if (i==j) {
                printf("%8.4f + j*%8.4f > ", crealf(x), cimagf(x));
                printf("%8.4f + j*%8.4f > ", crealf(y), cimagf(y));
                printf("%8.4f + j*%8.4f\n",  crealf(z), cimagf(z));
            }

            fprintf(fid,"x(%3d,%3d) = %12.4e + j*%12.4e;\n", i+1, j+1, crealf(x), cimagf(x));
            fprintf(fid,"y(%3d,%3d) = %12.4e + j*%12.4e;\n", i+1, j+1, crealf(y), cimagf(y));
        }
    }

    for (i=0; i<n+1; i++)
        fprintf(fid,"t(%3d) = %12.4e;\n", i+1, (float)(2*i-n)/(float)(n));

    // plot results
    fprintf(fid,"\n\n");
    fprintf(fid,"figure;\n");
    fprintf(fid,"mesh(t,t,real(y));\n");
    fprintf(fid,"xlabel('x: real');\n");
    fprintf(fid,"ylabel('x: imag');\n");
    fprintf(fid,"box off;\n");
    fprintf(fid,"view(3);\n");
    fprintf(fid,"title('real[y]');\n");
    //fprintf(fid,"axis([-1 1 -1 1 -1 1]);\n");

    // close debug file
    fclose(fid);
    printf("results wrtten to %s\n", OUTPUT_FILENAME);
    printf("done.\n");
    return 0;
}