C3861 : 'identifier not found

I'm trying to estimate the PSD from the FFT in C++. i got some error like

yulewalkerPSE : identifier is not found.
'sigma2' : undeclared identifier.
'a': undeclared identifier.
'b': undeclared identifier.


program code:
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
 #include <complex>
 #include <cmath>
 #include <iterator>
 using namespace std;
 
 unsigned int bitReverse(unsigned int x, int log2n)
 
 {
  int n = 0;
    for (int i=0; i < log2n; i++)
 
   {
     n <<= 1;
     n |= (x & 1);
     x >>= 1;
   }
     return n;
   }
  const double PI = 3.1415926536;
  template<class Iter_T>
  void fft(Iter_T a, Iter_T b, int log2n)
   {

    const complex<double> J(0, 1);
    int n = 1 << log2n;
    for (unsigned int i=0; i < n; ++i)
     {
        b[bitReverse(i, log2n)] = a[i];
     }
 
     for (int s = 1; s <= log2n; ++s)
 
     {
        int m = 1 << s;
        int m2 = m >> 1;
        complex<double>w(1, 0);
        complex<double> wm = exp(-J * (PI / m2));
        for (int j=0; j < m2; ++j)
 
         {
            for (int k=j; k < n; k += m)
 
              {
                 complex <double> t = w * b[k + m2];
                 complex <double> u = b[k];
                 b[k] = u + t;
                 b[k + m2] = u - t;
              }
            w *= wm;
          }
        }
      }
   template <typename Type>
   Vector<Type> yulewalkerPSE( const Vector<Type> &xn, int p, Type &sigma2 )
 {
    int N = xn.size();

    assert( p <= N );

    Vector<Type> rn(p+1);
    for( int i=0; i<=p; ++i )
        for( int k=0; k<N-i; ++k )
            rn[i] += xn[k+i]*xn[k];
    rn /= Type(N);

    return levinson( rn, sigma2 );
 }

   template <typename Type>
   Vector<Type> levinson( const Vector<Type> &rn, Type &sigma2 )
  {
    int p = rn.size()-1;
    Type tmp;
    Vector<Type> ak(p+1), akPrev(p+1);

    ak[0] = Type(1.0);
    sigma2 = rn[0];
    ak[1] = -rn[1]/sigma2;
    sigma2 *= 1 - ak[1]*ak[1];

    for( int k=2; k<=p; ++k )
    {
        tmp = 0;
        for( int i=0; i<k; ++i )
            tmp += ak[i]*rn[k-i];
        ak[k] = -tmp/sigma2;

        for( int i=1; i<k; ++i )
            akPrev[i] = ak[i] + ak[k]*ak[k-i];
        for( int i=1; i<k; ++i )
            ak[i] = akPrev[i];

        sigma2 *= 1 - ak[k]*ak[k];
    }

    return ak;
  }


  typedef double Type;

  int main( )
 
   {
     typedef complex <double> cx;
     Type sigma2;
     cx a[127];
      for(int i=0;i<127;i++)
       {
          a[i]=sin(2*PI*10*i*0.005);
       }

     cx b[127];
     fft(a, b, 7);
     for (int i=0; i<128; ++i)
     {
        cout << b[i] << "\n";
     } 
    
     int y=yulewalkerPSE(b,4,sigma2);
     cout<<y<<"\n";
     getchar();
     return 0;
  }
Last edited on
Always start with the first error in the list. It is often the case that later errors are caused by earlier errors.

When I try to compile your code the first error I get is "error: missing template arguments before ‘t’" at line 46. You need to specify what type the complex numbers should use each time you use the complex type.

1
2
complex<double> t = w * b[k + m2];
complex<double> u = b[k];
Last edited on
thank u for ur reply ,then how to clear this error?

56:4: error: 'Vector' does not name a type
72:4: error: 'Vector' does not name a type
122:36: error: 'yulewalkerPSE' was not declared in this scope In instantiation of 'void fft(Iter_T, Iter_T, int) [with Iter_T = std::complex<double>*]': 116:17: required from here
If you want to use std::vector you should spell it with lowercase letters and include <vector>.
yeah!! nice, but again two error is there . how to clear this?

1. see the declaration of 'yulewalkerPSE'

2. C2748 : std::vector<Type> yulewalker(const std :: vector<type>&,int ,Type &)': could not deduce template argument for 'const std:: vector<Type>&' from 'cx a[127]'
A vector is not the same thing as an array.
On line 121: You pass b which is not a vector.
ok , So how to pass the 'b' array data to the vector function( yulewalker() ) . Any idea..?
Change cx b[127]; -> std::vector<cx> b(127);
ok , i can changed cx b[127]; -> std::vector<cx> b(127) , but the error is
line no 115 ->
1. C2782 : void fft( Iter_T , iter_T , int) : template parameter 'Iter_T' is ambiguous.
2. see the declaration on the fft (line no 22)
Last edited on
Change
1
2
  template<class Iter_T>
  void fft(Iter_T a, Iter_T b, int log2n)

to
1
2
  template<class Iter1_T, class Iter2_T> // Note Iter1_T, Iter2_T
  void fft(Iter1_T a, Iter2_T b, int log2n) // Note Iter1_T, Iter2_T 

ok, i changed. but the error showing
1.C2748 : std::vector<Type> yulewalker(const std :: vector<type>&,int ,Type &)': template parameter 'Type' is ambiguous..
Yes, do the same as before. Introduce two template types:

template <typename Type1, typename Type2>

for yulewalkerPSE(...) and levinson(...)


Do you understand what that code is supposed to do? Since you need to ensure that these changes makes sense.
Topic archived. No new replies allowed.