- #1
btb4198
- 572
- 10
ok I wrote my own FFT class and I now have MatLab on my computer. I am comparing my code to mat-lab.
so my test i used it this :
which in MatLab is this:
so that is working great, I am getting the same values in MatLab as in my program.
now the problem is the fft itself:
my code gets:
and this is what Mat Lab has
so how should I go about troubleshooting my c# fft code?
is there a way to get Matlab to print out the steps it is during where it does the FFT?
is there a better way of troubleshooting my ftt code ?
so my test i used it this :
Code:
for (int y = 0; y < 100; y++)
{
double temp8 = (2D * (Math.Sin(2D * Math.PI * 4D * (double)y / 100D)));
buffer[y] = (float)temp8;
}
Code:
fo = 4;
Fs = 100;
Ts = 1/Fs;
0:Ts;1-Ts;
t = 0:Ts:1-Ts;
y = 2 * sin(2*pi*fo*t);
so that is working great, I am getting the same values in MatLab as in my program.
now the problem is the fft itself:
my code gets:
Code:
Real[ 0] =15.6438784003258
Img[ 0] =0
Real[ 1] =8.46128487984206
Img[ 1] =1.40568933318413
Real[ 2] =0
Img[ 2] =0
Real[ 3] =22.2310419428763
Img[ 3] =5.40923846876197
Real[ 4] =-1.80056660225914
Img[ 4] =5.74956074821605
Real[ 5] =0
Img[ 5] =0
Real[ 6] =-5.11379679263678
Img[ 6] =-0.688387862482321
Real[ 7] =-10.4312474863214
Img[ 7] =-8.80658407162755
Real[ 8] =0
Img[ 8] =0
Real[ 9] =7.79337236310158
Img[ 9] =9.18587953709857
Real[ 10] =-3.99240649537681
Img[ 10] =-2.95715001320984
Real[ 11] =0
Img[ 11] =0
Real[ 12] =-0.725325897426671
Img[ 12] =0.363923889449184
Real[ 13] =-3.48947495495046
Img[ 13] =-3.17979218818627
Real[ 14] =0
Img[ 14] =0
Real[ 15] =1.91405696078796
Img[ 15] =1.41155752908299
Real[ 16] =-4.65431128431017
Img[ 16] =-2.55948892517805
Real[ 17] =0
Img[ 17] =0
Real[ 18] =-2.66530083281111
Img[ 18] =-3.2978120014703
Real[ 19] =-2.18544418167612
Img[ 19] =-3.16506874433514
Real[ 20] =0
Img[ 20] =0
Real[ 21] =2.5183300759435
Img[ 21] =3.27070622595888
Real[ 22] =-1.91673308587846
Img[ 22] =-4.28146090355363
Real[ 23] =0
Img[ 23] =0
Real[ 24] =0
Img[ 24] =0
Real[ 25] =-0.127357929944991
Img[ 25] =0.380064934492111
Real[ 26] =-1.77076956563049
Img[ 26] =-1.16238391836151
Real[ 27] =0
Img[ 27] =0
Real[ 28] =1.33827428539545
Img[ 28] =1.82705801865022
Real[ 29] =-2.74387526172086
Img[ 29] =1.6918766374459
Real[ 30] =0
Img[ 30] =0
Real[ 31] =-1.23531162328276
Img[ 31] =-0.344879676029618
Real[ 32] =-0.490950246033762
Img[ 32] =-2.50634463327099
Real[ 33] =0
Img[ 33] =0
Real[ 34] =0.0616589288850338
Img[ 34] =1.41281177829685
Real[ 35] =-1.11021525078896
Img[ 35] =-1.6384014200336
Real[ 36] =0
Img[ 36] =0
Real[ 37] =-0.581764223242864
Img[ 37] =-0.565565392364546
Real[ 38] =-0.800557052119878
Img[ 38] =0.24862692145541
Real[ 39] =0
Img[ 39] =0
Real[ 40] =-0.155778218052648
Img[ 40] =-4.08014192142325
Real[ 41] =-1.59543284819159
Img[ 41] =3.38035787631867
Real[ 42] =0
Img[ 42] =0
Real[ 43] =-1.42509628490074
Img[ 43] =-0.690852268756354
Real[ 44] =-1.01489289175587
Img[ 44] =1.30057672045934
Real[ 45] =0
Img[ 45] =0
Real[ 46] =1.74167365638883
Img[ 46] =-1.85709851794845
Real[ 47] =-1.54097745212813
Img[ 47] =-5.30373068481949
Real[ 48] =0
Img[ 48] =0
Real[ 49] =0
Img[ 49] =0
Real[ 50] =0.124337077140807
Img[ 50] =0
Real[ 51] =-1.70945722097089
Img[ 51] =0.765800478188799
Real[ 52] =0
Img[ 52] =0
Real[ 53] =1.85429156562877
Img[ 53] =1.52216544624097
Real[ 54] =-3.37426422070059
Img[ 54] =5.34550387538567
Real[ 55] =0
Img[ 55] =0
Real[ 56] =-1.58324273924713
Img[ 56] =0.709457373828966
Real[ 57] =-0.509551690154068
Img[ 57] =-4.13778842089745
Real[ 58] =0
Img[ 58] =0
Real[ 59] =-0.111356595280117
Img[ 59] =4.16938599825349
Real[ 60] =-1.27006205100977
Img[ 60] =-0.979250998498057
Real[ 61] =0
Img[ 61] =0
Real[ 62] =-0.607477279265961
Img[ 62] =0.474591108126309
Real[ 63] =-0.789693160521237
Img[ 63] =-0.304816584641161
Real[ 64] =0
Img[ 64] =0
Real[ 65] =0.000684665428978715
Img[ 65] =-1.22197350537954
Real[ 66] =-1.43379200328076
Img[ 66] =2.51523743989183
Real[ 67] =0
Img[ 67] =0
Real[ 68] =-1.13493927974621
Img[ 68] =-0.045628157166532
Real[ 69] =-0.833622074048892
Img[ 69] =0.249244154952255
Real[ 70] =0
Img[ 70] =0
Real[ 71] =1.28236043172393
Img[ 71] =-1.54307771477549
Real[ 72] =-1.51791564293372
Img[ 72] =-2.19078665228718
Real[ 73] =0
Img[ 73] =0
Real[ 74] =0
Img[ 74] =0
Real[ 75] =-0.127357929944991
Img[ 75] =-0.380064934492111
Real[ 76] =-1.97025325016812
Img[ 76] =2.00831845114145
Real[ 77] =0
Img[ 77] =0
Real[ 78] =2.26040036086525
Img[ 78] =-3.00689615389389
Real[ 79] =-4.44019352391471
Img[ 79] =8.29860006881245
Real[ 80] =0
Img[ 80] =0
Real[ 81] =-2.58596181495194
Img[ 81] =3.06647330142348
Real[ 82] =-1.72270785043888
Img[ 82] =0.11127351919887
Real[ 83] =0
Img[ 83] =0
Real[ 84] =1.55682887842896
Img[ 84] =-0.943199069986429
Real[ 85] =-3.06412282603289
Img[ 85] =1.05092164080382
Real[ 86] =0
Img[ 86] =0
Real[ 87] =-0.856548737569082
Img[ 87] =-0.272949605210947
Real[ 88] =-3.91301515540254
Img[ 88] =3.17141962717599
Real[ 89] =0
Img[ 89] =0
Real[ 90] =6.30989470522789
Img[ 90] =-8.7777282723593
Real[ 91] =-10.2918483227761
Img[ 91] =8.89927095595156
Real[ 92] =0
Img[ 92] =0
Real[ 93] =-5.63808404993432
Img[ 93] =1.29162929065268
Real[ 94] =-12.8829923493748
Img[ 94] =5.99948970692771
Real[ 95] =0
Img[ 95] =0
Real[ 96] =20.9099985289662
Img[ 96] =-6.77868784657761
Real[ 97] =17.9336785221511
Img[ 97] =-9.01871999661001
Real[ 98] =0
Img[ 98] =0
Real[ 99] =0
Img[ 99] =0
and this is what Mat Lab has
Code:
YfreqDomain =
1.0e+02 *
Columns 1 through 2
0.0000 + 0.0000i -0.0000 + 0.0000i
Columns 3 through 4
-0.0000 - 0.0000i 0.0000 + 0.0000i
Columns 5 through 6
-0.0000 - 1.0000i 0.0000 - 0.0000i
Columns 7 through 8
0.0000 - 0.0000i 0.0000 + 0.0000i
Columns 9 through 10
0.0000 - 0.0000i 0.0000 + 0.0000i
Columns 11 through 12
-0.0000 - 0.0000i 0.0000 - 0.0000i
Columns 13 through 14
0.0000 - 0.0000i -0.0000 - 0.0000i
Columns 15 through 16
0.0000 - 0.0000i 0.0000 + 0.0000i
Columns 17 through 18
-0.0000 + 0.0000i 0.0000 + 0.0000i
Columns 19 through 20
-0.0000 + 0.0000i 0.0000 - 0.0000i
Columns 21 through 22
-0.0000 + 0.0000i -0.0000 + 0.0000i
Columns 23 through 24
0.0000 - 0.0000i 0.0000 + 0.0000i
Columns 25 through 26
-0.0000 - 0.0000i 0.0000 + 0.0000i
Columns 27 through 28
0.0000 - 0.0000i -0.0000 - 0.0000i
Columns 29 through 30
0.0000 + 0.0000i -0.0000 + 0.0000i
Columns 31 through 32
-0.0000 + 0.0000i 0.0000 + 0.0000i
Columns 33 through 34
-0.0000 + 0.0000i -0.0000 - 0.0000i
Columns 35 through 36
0.0000 - 0.0000i 0.0000 - 0.0000i
Columns 37 through 38
0.0000 + 0.0000i -0.0000 - 0.0000i
Columns 39 through 40
-0.0000 - 0.0000i 0.0000 + 0.0000i
Columns 41 through 42
0.0000 + 0.0000i -0.0000 + 0.0000i
Columns 43 through 44
0.0000 - 0.0000i 0.0000 + 0.0000i
Columns 45 through 46
-0.0000 + 0.0000i -0.0000 + 0.0000i
Columns 47 through 48
-0.0000 - 0.0000i -0.0000 - 0.0000i
Columns 49 through 50
-0.0000 - 0.0000i 0.0000 - 0.0000i
Columns 51 through 52
0.0000 + 0.0000i 0.0000 + 0.0000i
Columns 53 through 54
-0.0000 + 0.0000i -0.0000 + 0.0000i
Columns 55 through 56
-0.0000 + 0.0000i -0.0000 - 0.0000i
Columns 57 through 58
-0.0000 - 0.0000i 0.0000 - 0.0000i
Columns 59 through 60
0.0000 + 0.0000i -0.0000 - 0.0000i
Columns 61 through 62
0.0000 - 0.0000i 0.0000 - 0.0000i
Columns 63 through 64
-0.0000 + 0.0000i -0.0000 + 0.0000i
Columns 65 through 66
0.0000 - 0.0000i 0.0000 + 0.0000i
Columns 67 through 68
0.0000 + 0.0000i -0.0000 + 0.0000i
Columns 69 through 70
-0.0000 - 0.0000i 0.0000 - 0.0000i
Columns 71 through 72
-0.0000 - 0.0000i -0.0000 - 0.0000i
Columns 73 through 74
0.0000 - 0.0000i -0.0000 + 0.0000i
Columns 75 through 76
0.0000 + 0.0000i 0.0000 - 0.0000i
Columns 77 through 78
-0.0000 + 0.0000i 0.0000 - 0.0000i
Columns 79 through 80
0.0000 + 0.0000i -0.0000 - 0.0000i
Columns 81 through 82
-0.0000 - 0.0000i 0.0000 + 0.0000i
Columns 83 through 84
-0.0000 - 0.0000i 0.0000 - 0.0000i
Columns 85 through 86
-0.0000 + 0.0000i 0.0000 - 0.0000i
Columns 87 through 88
0.0000 + 0.0000i -0.0000 + 0.0000i
Columns 89 through 90
0.0000 + 0.0000i 0.0000 + 0.0000i
Columns 91 through 92
-0.0000 + 0.0000i 0.0000 - 0.0000i
Columns 93 through 94
0.0000 + 0.0000i 0.0000 - 0.0000i
Columns 95 through 96
0.0000 + 0.0000i 0.0000 + 0.0000i
Columns 97 through 98
-0.0000 + 1.0000i 0.0000 - 0.0000i
Columns 99 through 100
-0.0000 + 0.0000i -0.0000 - 0.0000i
so how should I go about troubleshooting my c# fft code?
is there a way to get Matlab to print out the steps it is during where it does the FFT?
is there a better way of troubleshooting my ftt code ?