|
| 1 | +// (c) Copyright 2019-2022 Xilinx, Inc. All rights reserved. |
| 2 | +// (c) Copyright 2022-2025 Advanced Micro Devices, Inc. All rights reserved. |
| 3 | +// |
| 4 | +// This file contains confidential and proprietary information |
| 5 | +// of Xilinx, Inc. and is protected under U.S. and |
| 6 | +// international copyright and other intellectual property |
| 7 | +// laws. |
| 8 | +// |
| 9 | +// DISCLAIMER |
| 10 | +// This disclaimer is not a license and does not grant any |
| 11 | +// rights to the materials distributed herewith. Except as |
| 12 | +// otherwise provided in a valid license issued to you by |
| 13 | +// Xilinx, and to the maximum extent permitted by applicable |
| 14 | +// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND |
| 15 | +// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES |
| 16 | +// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING |
| 17 | +// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- |
| 18 | +// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and |
| 19 | +// (2) Xilinx shall not be liable (whether in contract or tort, |
| 20 | +// including negligence, or under any other theory of |
| 21 | +// liability) for any loss or damage of any kind or nature |
| 22 | +// related to, arising under or in connection with these |
| 23 | +// materials, including for any direct, or any indirect, |
| 24 | +// special, incidental, or consequential loss or damage |
| 25 | +// (including loss of data, profits, goodwill, or any type of |
| 26 | +// loss or damage suffered as a result of any action brought |
| 27 | +// by a third party) even if such damage or loss was |
| 28 | +// reasonably foreseeable or Xilinx had been advised of the |
| 29 | +// possibility of the same. |
| 30 | +// |
| 31 | +// CRITICAL APPLICATIONS |
| 32 | +// Xilinx products are not designed or intended to be fail- |
| 33 | +// safe, or for use in any application requiring fail-safe |
| 34 | +// performance, such as life-support or safety devices or |
| 35 | +// systems, Class III medical devices, nuclear facilities, |
| 36 | +// applications related to the deployment of airbags, or any |
| 37 | +// other applications that could lead to death, personal |
| 38 | +// injury, or severe property or environmental damage |
| 39 | +// (individually and collectively, "Critical |
| 40 | +// Applications"). Customer assumes the sole risk and |
| 41 | +// liability of any use of Xilinx products in Critical |
| 42 | +// Applications, subject only to applicable laws and |
| 43 | +// regulations governing limitations on product liability. |
| 44 | + |
| 45 | +#include <math.h> |
| 46 | +#include <stdio.h> |
| 47 | +#include <stdlib.h> |
| 48 | + |
| 49 | +//----------------------------------------- |
| 50 | +// test FFTz model |
| 51 | +//----------------------------------------- |
| 52 | +int main(int argc, char *argv[]) { |
| 53 | + |
| 54 | + if (argc != 3) { |
| 55 | + printf("\n\tUsage: get_sqnr( ref_file_name, dut_file_name )\n\n"); |
| 56 | + exit(-1); |
| 57 | + } |
| 58 | + |
| 59 | + FILE *fpin0 = fopen(argv[1], "rt"); |
| 60 | + FILE *fpin1 = fopen(argv[2], "rt"); |
| 61 | + |
| 62 | + if (fpin0 == NULL) { |
| 63 | + printf(" Error! Unable to open the ref file = %s\n", argv[1]); |
| 64 | + exit(-1); |
| 65 | + } |
| 66 | + |
| 67 | + if (fpin1 == NULL) { |
| 68 | + printf(" Error! Unable to open the dut file = %s\n", argv[2]); |
| 69 | + exit(-1); |
| 70 | + } |
| 71 | + |
| 72 | + float ref; |
| 73 | + double sumpwr = 0; |
| 74 | + double sumdif = 0; |
| 75 | + int din; |
| 76 | + |
| 77 | + int dut_int; |
| 78 | + float *dut_p = (float *)&dut_int; |
| 79 | + |
| 80 | + long long samplecnt = 0; |
| 81 | + |
| 82 | + printf("Computing EVM for %s against %s ...", argv[2], argv[1]); |
| 83 | + |
| 84 | + while (fscanf(fpin0, "%f", &ref) == 1) { |
| 85 | + |
| 86 | + samplecnt += 1; |
| 87 | + |
| 88 | + if (fscanf(fpin1, "%d", &din) == 1) { |
| 89 | + |
| 90 | + dut_int = din; |
| 91 | + |
| 92 | + float dut = *dut_p; |
| 93 | + |
| 94 | + double a = ref - dut; |
| 95 | + double b = ref; |
| 96 | + sumpwr += b * b; |
| 97 | + sumdif += a * a; |
| 98 | + } else { |
| 99 | + printf("\n\nWarning: DUT file is shorten than ref. Sample Cnt = %lld.\n", |
| 100 | + samplecnt); |
| 101 | + break; |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + if (sumdif == 0) { |
| 106 | + printf("Input Files Bit-true Match.\n"); |
| 107 | + } else { |
| 108 | + // printf("sum diff = %e, sum_pwr = %e\n", sumdif, sumpwr); |
| 109 | + printf("MSE = %.1f dBc\n", 10 * log10(sumdif / sumpwr)); |
| 110 | + } |
| 111 | + |
| 112 | + fclose(fpin0); |
| 113 | + fclose(fpin1); |
| 114 | +} |
0 commit comments