File: toeplitz.cpp

package info (click to toggle)
drc 3.2.1~dfsg0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,616 kB
  • ctags: 1,807
  • sloc: ansic: 13,385; cpp: 10,457; sh: 419; makefile: 45
file content (100 lines) | stat: -rw-r--r-- 2,568 bytes parent folder | download | duplicates (2)
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
91
92
93
94
95
96
97
98
99
100
/****************************************************************************

    DRC: Digital Room Correction
    Copyright (C) 2002, 2003 Denis Sbragion

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

		You can contact the author on Internet at the following address:

				d.sbragion@infotecna.it

****************************************************************************/

/* Risoluzione matrici Toeplitz */

#include "toeplitz.h"

/* Memory leaks debugger */
#ifdef DebugMLeaks
	#include "debug_new.h"
#endif

int ToeplitzSolve(const DLReal * A, const DLReal * B, DLReal * X, int N)
	{
  	int I, J, K;
  	DLReal PError;
  	DLReal RC;
  	DLReal Tmp;
  	DLReal Sum;
  	DLReal * TA;

  	PError = A[0];
  	if (PError <= 0)
   		return 1;

		/* Alloca un arrya temporaneo */
 		if ((TA = new DLReal[N]) == NULL)
 			return 1;

  	X[0] = B[0] / PError;
  	for (K = 0; K < N - 1; K++)
  		{
    		Sum = A[K + 1];
    		for (I = 0; I < K; I++)
      		Sum = Sum - A[K - I] * TA[I];
    		RC = -Sum / PError;

				/* Calcola l'errore del predittore (equivalente a
				PError = PError * (1 - RC**2). Un cambio di segno di
				PError indica che RC  maggiore dell'unit e quindi siamo
				di fronte ad un sistema di equazioni che non  definito
				positivo */

		    PError = PError + RC * Sum;
    		if (PError <= 0.0)
    			{
    				delete[] TA;
      			return 1;
      		}

    		TA[K] = -RC;
    		for (I = 0, J = K - 1; I < J; I++, J--)
    			{
      			Tmp = TA[I] + RC * TA[J];
      			TA[J] = TA[J] + RC * TA[I];
      			TA[I] = Tmp;
    			}

    		if (I == J)
      		TA[I] = TA[I] + RC * TA[I];

    		Sum = B[K+1];

    		for (I = 0, J = K + 1; I <= K; I++, J--)
      		Sum = Sum - X[I] * A[J];

    		X[K + 1] = Sum / PError;

    		for (I = 0, J = K; I <= K; I++, J--)
      		X[I] = X[I] - X[K + 1] * TA[J];

  		}

	 	/* Rimuove l'array temporaneo */
	 	delete[] TA;

	  return 0;
	}