• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修訂8bdc0852d2ff7efb566358f75572272fe638fe50 (tree)
時間2014-06-29 23:24:16
作者suikan <suikan@user...>
Commitersuikan

Log Message

FIRフィルタまで動作検証済み

Change Summary

差異

--- a/src_test/main.c
+++ b/src_test/main.c
@@ -9,23 +9,38 @@
99 #include <math.h>
1010 #include <stdio.h>
1111 #define CUTOFF (0.475)
12+#define TAPS 127
1213
1314 /* x : [0, 1.0) */
1415 double hanning(double x);
1516 /* cutoff : normalized frequency where cutoff freq / sampling freq */
1617 double sinc(double x, double cutoff);
18+ /* put a sample into the delayline */
19+void putSample( double aSample, double aDelayline[] );
20+ /* calc the convolution */
21+double convolute ( double aDelayline[], double offset );
1722
1823 double h( double x, int lenght);
1924
25+double delayline[TAPS];
26+
27+
28+
2029 int main(void)
2130 {
2231
23- int i;
32+ int readsize;
33+ float aSample;
2434
25- for ( i=0; i<127; i++)
35+ while ( 1)
2636 {
27-// printf( "%f\n", sinc(i, CUTOFF));
28- printf( "%f\n", h( i, 127));
37+ readsize = fread((void *)&aSample, sizeof(float), 1, stdin);
38+ if ( readsize < 1)
39+ break;
40+ putSample(aSample, delayline);
41+ aSample = convolute(delayline, 0.25);
42+ fwrite( &aSample, sizeof(float), 1, stdout );
43+
2944 }
3045
3146 return 0;
@@ -36,14 +51,10 @@ int main(void)
3651 double h( double x, int length)
3752 {
3853 int center;
39- double fractional;
40-
41- fractional = x - floor(x);
4254
4355 center = (length -1 )/2;
4456
45- return sinc( x - center, CUTOFF );
46-// return hanning ( x / ( length - 1 ));
57+ return sinc( x - center, CUTOFF )* hanning ( x / ( length - 1 ));
4758 }
4859
4960 double sinc(double x, double cutoff )
@@ -58,3 +69,26 @@ double hanning(double x)
5869 else
5970 return 0.0;
6071 }
72+
73+
74+void putSample( double aSample, double aDelayline[] )
75+{
76+ int i;
77+
78+ /* Shift the sample in the line */
79+ for ( i=TAPS-1; i>0; i--)
80+ aDelayline[i] = aDelayline[i-1];
81+
82+ aDelayline[0] = aSample;
83+}
84+
85+double convolute ( double aDelayline[], double offset )
86+{
87+ int i;
88+ double sum = 0.0;
89+
90+ for ( i=0; i< TAPS; i++ )
91+ sum += aDelayline[i] * h(i+offset, TAPS);
92+
93+ return sum;
94+}