please tell me how this code works

could anyone tell me briefly how this code works?thank you..

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
// nonrec_t.spc -- test program for non-recursive filter design 

  

#include "tools.h" 

#include "ltisys.h" 

#include "nonrec.h" 

  

int main() 

{ 

       Graph gr(3,2,"Non-Recursive Filter Design"); 

  

       // calculate low-pass filter and plot 

       LTISystem lp = NRLowPass(0.1,63); 

       lp.a.plot(gr,1,"Low-pass at 0.1","Samples","Amp"); 

  

       // calculate frequency response and plot 

       Spectrum lpf(500,1000); 

       for (int i=0;i<500;i++) lpf[i] = lp.response(i/1000.0); 

       lpf.plotLogMag(gr,2,"Frequency Response"); 

  

       // calculate high-pass filter and plot 

       LTISystem hp = NRHighPass(0.4,63); 

       hp.a.plot(gr,3,"High-pass at 0.4","Samples","Amp"); 

  

       // calculate frequency response and plot 

       Spectrum hpf(500,1000); 

       for (int i=0;i<500;i++) 

              hpf[i] = hp.response(i/1000.0); 

       hpf.plotLogMag(gr,4,"Frequency Response"); 

  

       // calculate band-pass filter and plot 

       LTISystem bp = NRBandPass(0.2,0.3,63); 

       bp.a.plot(gr,5,"Band-pass at 0.2-0.3","Samples","Amp"); 

  

       // calculate frequency response and plot 

       Spectrum bpf(500,1000); 

       for (int i=0;i<500;i++) bpf[i] = bp.response(i/1000.0); 

       bpf.plotLogMag(gr,6,"Frequency Response"); 

        

       gr.close(); 

} 


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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// kaiser_t.cpp -- test program for Kaiser window design 

  

#include "tools.h" 

#include "ltisys.h" 

#include "nonrec.h" 

#include "kaiser.h" 

  

const int MAXKAISERWIN=256; // maximum window length 

  

// Create non-recursive low-pass filter using Kaiser window 

LTISystem KaiserLowPass( 

       double freq,         // corner freq 

                           //  (fraction of sampling rate) 

       double ripple,       // allowed ripple (dB) 

       double twidth        // transition width 

                           //  (fraction of sampling rate) } 

       )                    // returns LTI System 

{ 

       int    i; 

  

       // get (half-)Kaiser window 

       Waveform kwin = Kaiser(ripple,twidth,MAXKAISERWIN); 

       int nhalf = kwin.count()-1; 

  

       // generate one half of coefficients from 

       //     windowed sinc() function 

       double omega = 2*PI*freq; 

       for (i=0;i<=nhalf;i++) 

              kwin[i+1] *= omega*sinc(i*omega)/PI; 

  

       // copy into LTI System 

       LTISystem lpfilt(2*nhalf,0); 

       lpfilt.a[nhalf] = kwin[1]; 

       for (i=1;i<=nhalf;i++) { 

              lpfilt.a[nhalf-i] = kwin[i+1]; 

              lpfilt.a[nhalf+i] = kwin[i+1]; 

       } 

  

       return lpfilt; 

} 
  



  

int main() 

{ 

       int    i; 

  

       // initialise graphics 

       Graph gr (2,2,"Kaiser Window Design"); 

  

       // plot Kaiser window 1 

       Waveform kwv1 = Kaiser(40.0,0.005,MAXKAISERWIN); 

       kwv1.plot(gr,1,"Kaiser (40dB/0.005)"); 

  

       // calculate and plot frequency response 

       LTISystem lp1 = KaiserLowPass(0.1,40.0,0.005); 

       Spectrum lpf1(500,1000); 

       for (i=0;i<500;i++) lpf1[i] = lp1.response(i/1000.0); 

       lpf1.plotLogMag(gr,2,"Frequency Response"); 

  

       // plot Kaiser window 2 

       Waveform kwv2 = Kaiser(80.0,0.01,MAXKAISERWIN); 

       kwv2.plot(gr,3,"Kaiser (80dB/0.01)"); 

  

       // calculate and plot frequency response 

       LTISystem lp2 = KaiserLowPass(0.1,80.0,0.01); 

       Spectrum lpf2(500,1000); 

       for (i=0;i<500;i++) lpf2[i] = lp2.response(i/1000.0); 

       lpf2.plotLogMag(gr,4,"Frequency Response"); 

  

       gr.close(); 

} 
Is this from CSound?

It appears to be two mathematical functions for modifying and analyzing waveforms.
Topic archived. No new replies allowed.