File: test_window.c

package info (click to toggle)
bart 0.9.00-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,040 kB
  • sloc: ansic: 116,116; python: 1,329; sh: 726; makefile: 639; javascript: 589; cpp: 106
file content (90 lines) | stat: -rw-r--r-- 2,120 bytes parent folder | download | duplicates (6)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Copyright 2017. The Regents of the University of California.
 * All rights reserved. Use of this source code is governed by
 * a BSD-style license which can be found in the LICENSE file.
 *
 * Authors:
 * 2017	Jon Tamir <jtamir@eecs.berkeley.edu>
 */

#include <stdlib.h>

#include "num/filter.h"
#include "num/flpmath.h"
#include "num/multind.h"

#include "misc/misc.h"

#include "utest.h"


static bool test_window(unsigned int D, long dims[D], long flags, bool hamming, const complex float* ref)
{

	complex float* in = md_alloc(3, dims, CFL_SIZE);
	md_zfill(3, dims, in, 1.);

	complex float* out = md_alloc(3, dims, CFL_SIZE);

	(hamming ? md_zhamming : md_zhann)(3, dims, flags, out, in);

	bool ret = (md_znrmse(3, dims, &ref[0], out) < UT_TOL);

	md_free(out);
	md_free(in);
	
	return ret;
}

static bool test_hamming(void)
{
	// compare to Matlab:
	// >> z = permute(repmat(hamming(5)*hamming(4)', [1, 1, 2]), [3, 1, 2]);
	// >> z(:)
	const complex float ref[2 * 5 * 4] = {

		 0.0064, 0.0064, 0.0432, 0.0432,
		 0.0800, 0.0800, 0.0432, 0.0432,
		 0.0064, 0.0064, 0.0616, 0.0616,
		 0.4158, 0.4158, 0.7700, 0.7700,
		 0.4158, 0.4158, 0.0616, 0.0616,
		 0.0616, 0.0616, 0.4158, 0.4158,
		 0.7700, 0.7700, 0.4158, 0.4158,
		 0.0616, 0.0616, 0.0064, 0.0064,
		 0.0432, 0.0432, 0.0800, 0.0800,
		 0.0432, 0.0432, 0.0064, 0.0064,
	};

	long dims[3] = { 2, 5, 4 };

	return test_window(3, dims, MD_BIT(1) | MD_BIT(2), true, ref);
}

UT_REGISTER_TEST(test_hamming);

static bool test_hann(void)
{

	// compare to Matlab:
	// >> z = permute(repmat(hann(4)*hann(5)', [1, 1, 2]), [1, 3, 2]);
	// >> z(:)
	const complex float ref[4 * 2 * 5] = {

		0.0000, 0.0000, 0.0000, 0.0000,
		0.0000, 0.0000, 0.0000, 0.0000,
		0.0000, 0.3750, 0.3750, 0.0000,
		0.0000, 0.3750, 0.3750, 0.0000,
		0.0000, 0.7500, 0.7500, 0.0000,
		0.0000, 0.7500, 0.7500, 0.0000,
		0.0000, 0.3750, 0.3750, 0.0000,
		0.0000, 0.3750, 0.3750, 0.0000,
		0.0000, 0.0000, 0.0000, 0.0000,
		0.0000, 0.0000, 0.0000, 0.0000,
	};

	long dims[3] = { 4, 2, 5 };

	return test_window(3, dims, MD_BIT(0) | MD_BIT(2), false, ref);
}

UT_REGISTER_TEST(test_hann);