#include
using namespace std;
#define MAX
2048
#define FFT_1024
#define FFTNUM
1024
#ifdef
FFT_1024
const double sin_tab[] = {
0.0000,0.00614,0.01227,0.01841,0.02454,0.03067,0.03681,0.04294,0.04907,0.0552,0.06132,0.06744,0.07356,0.07968,0.0858,0.09191,
0.09802,0.10412,0.11022,0.11632,0.12241,0.1285,0.13458,0.14066,0.14673,0.1528,0.15886,0.16491,0.17096,0.177,0.18304,0.18907,
0.19509,0.2011,0.20711,0.21311,0.2191,0.22508,0.23106,0.23702,0.24298,0.24893,0.25487,0.26079,0.26671,0.27262,0.27852,0.28441,
0.29028,0.29615,0.30201,0.30785,0.31368,0.3195,0.32531,0.33111,0.33689,0.34266,0.34842,0.35416,0.3599,0.36561,0.37132,0.37701,
0.38268,0.38835,0.39399,0.39962,0.40524,0.41084,0.41643,0.422,0.42756,0.43309,0.43862,0.44412,0.44961,0.45508,0.46054,0.46598,
0.4714,0.4768,0.48218,0.48755,0.4929,0.49823,0.50354,0.50883,0.5141,0.51936,0.52459,0.5298,0.535,0.54017,0.54532,0.55046,
0.55557,0.56066,0.56573,0.57078,0.57581,0.58081,0.5858,0.59076,0.5957,0.60062,0.60551,0.61038,0.61523,0.62006,0.62486,0.62964,
0.63439,0.63912,0.64383,0.64851,0.65317,0.65781,0.66242,0.667,0.67156,0.67609,0.6806,0.68508,0.68954,0.69397,0.69838,0.70275,
0.70711,0.71143,0.71573,0.72,0.72425,0.72846,0.73265,0.73682,0.74095,0.74506,0.74914,0.75319,0.75721,0.7612,0.76517,0.7691,
0.77301,0.77689,0.78074,0.78456,0.78835,0.79211,0.79584,0.79954,0.80321,0.80685,0.81046,0.81404,0.81758,0.8211,0.82459,0.82805,
0.83147,0.83486,0.83822,0.84155,0.84485,0.84812,0.85136,0.85456,0.85773,0.86087,0.86397,0.86705,0.87009,0.87309,0.87607,0.87901,
0.88192,0.8848,0.88764,0.89045,0.89322,0.89597,0.89867,0.90135,0.90399,0.9066,0.90917,0.91171,0.91421,0.91668,0.91911,0.92151,
0.92388,0.92621,0.92851,0.93077,0.93299,0.93518,0.93734,0.93946,0.94154,0.94359,0.94561,0.94759,0.94953,0.95144,0.95331,0.95514,
0.95694,0.9587,0.96043,0.96212,0.96378,0.96539,0.96698,0.96852,0.97003,0.9715,0.97294,0.97434,0.9757,0.97703,0.97832,0.97957,
0.98079,0.98196,0.98311,0.98421,0.98528,0.98631,0.9873,0.98826,0.98918,0.99006,0.9909,0.99171,0.99248,0.99321,0.99391,0.99456,
0.99518,0.99577,0.99631,0.99682,0.99729,0.99772,0.99812,0.99848,0.9988,0.99908,0.99932,0.99953,0.9997,0.99983,0.99992,0.99998,
1,0.99998,0.99992,0.99983,0.9997,0.99953,0.99932,0.99908,0.9988,0.99848,0.99812,0.99772,0.99729,0.99682,0.99631,0.99577,
0.99518,0.99456,0.99391,0.99321,0.99248,0.99171,0.9909,0.99006,0.98918,0.98826,0.9873,0.98631,0.98528,0.98421,0.98311,0.98196,
0.98079,0.97957,0.97832,0.97703,0.9757,0.97434,0.97294,0.9715,0.97003,0.96852,0.96698,0.96539,0.96378,0.96212,0.96043,0.9587,
0.95694,0.95514,0.95331,0.95144,0.94953,0.94759,0.94561,0.94359,0.94154,0.93946,0.93734,0.93518,0.93299,0.93077,0.92851,0.92621,
0.92388,0.92151,0.91911,0.91668,0.91421,0.91171,0.90917,0.9066,0.90399,0.90135,0.89867,0.89597,0.89322,0.89045,0.88764,0.8848,
0.88192,0.87901,0.87607,0.87309,0.87009,0.86705,0.86397,0.86087,0.85773,0.85456,0.85136,0.84812,0.84485,0.84155,0.83822,0.83486,
0.83147,0.82805,0.82459,0.8211,0.81758,0.81404,0.81046,0.80685,0.80321,0.79954,0.79584,0.79211,0.78835,0.78456,0.78074,0.77689,
0.77301,0.7691,0.76517,0.7612,0.75721,0.75319,0.74914,0.74506,0.74095,0.73682,0.73265,0.72846,0.72425,0.72,0.71573,0.71143,
0.70711,0.70275,0.69838,0.69397,0.68954,0.68508,0.6806,0.67609,0.67156,0.667,0.66242,0.65781,0.65317,0.64851,0.64383,0.63912,
0.63439,0.62964,0.62486,0.62006,0.61523,0.61038,0.60551,0.60062,0.5957,0.59076,0.5858,0.58081,0.57581,0.57078,0.56573,0.56066,
0.55557,0.55046,0.54532,0.54017,0.535,0.5298,0.52459,0.51936,0.5141,0.50883,0.50354,0.49823,0.4929,0.48755,0.48218,0.4768,0.4714,
0.46598,0.46054,0.45508,0.44961,0.44412,0.43862,0.43309,0.42756,0.422,0.41643,0.41084,0.40524,0.39962,0.39399,0.38835,0.38268,
0.37701,0.37132,0.36561,0.3599,0.35416,0.34842,0.34266,0.33689,0.33111,0.32531,0.3195,0.31368,0.30785,0.30201,0.29615,0.29028,
0.28441,0.27852,0.27262,0.26671,0.26079,0.25487,0.24893,0.24298,0.23702,0.23106,0.22508,0.2191,0.21311,0.20711,0.2011,0.19509,
0.18907,0.18304,0.177,0.17096,0.16491,0.15886,0.1528,0.14673,0.14066,0.13458,0.1285,0.12241,0.11632,0.11022,0.10412,0.09802,
0.09191,0.0858,0.07968,0.07356,0.06744,0.06132,0.0552,0.04907,0.04294,0.03681,0.03067,0.02454,0.01841,0.01227,0.00614,0,
-0.00614,-0.01227,-0.01841,-0.02454,-0.03067,-0.03681,-0.04294,-0.04907,-0.0552,-0.06132,-0.06744,-0.07356,-0.07968,-0.0858,
-0.09191,-0.09802,-0.10412,-0.11022,-0.11632,-0.12241,-0.1285,-0.13458,-0.14066,-0.14673,-0.1528,-0.15886,-0.16491,-0.17096,
-0.177,-0.18304,-0.18907,-0.19509,-0.2011,-0.20711,-0.21311,-0.2191,-0.22508,-0.23106,-0.23702,-0.24298,-0.24893,-0.25487,
-0.26079,-0.26671,-0.27262,-0.27852,-0.28441,-0.29028,-0.29615,-0.30201,-0.30785,-0.31368,-0.3195,-0.32531,-0.33111,-0.33689,
-0.34266,-0.34842,-0.35416,-0.3599,-0.36561,-0.37132,-0.37701,-0.38268,-0.38835,-0.39399,-0.39962,-0.40524,-0.41084,-0.41643,
-0.422,-0.42756,-0.43309,-0.43862,-0.44412,-0.44961,-0.45508,-0.46054,-0.46598,-0.4714,-0.4768,-0.48218,-0.48755,-0.4929,
-0.49823,-0.50354,-0.50883,-0.5141,-0.51936,-0.52459,-0.5298,-0.535,-0.54017,-0.54532,-0.55046,-0.55557,-0.56066,-0.56573,
-0.57078,-0.57581,-0.58081,-0.5858,-0.59076,-0.5957,-0.60062,-0.60551,-0.61038,-0.61523,-0.62006,-0.62486,-0.62964,-0.63439,
-0.63912,-0.64383,-0.64851,-0.65317,-0.65781,-0.66242,-0.667,-0.67156,-0.67609,-0.6806,-0.68508,-0.68954,-0.69397,-0.69838,
-0.70275,-0.70711,-0.71143,-0.71573,-0.72,-0.72425,-0.72846,-0.73265,-0.73682,-0.74095,-0.74506,-0.74914,-0.75319,-0.75721,
-0.7612,-0.76517,-0.7691,-0.77301,-0.77689,-0.78074,-0.78456,-0.78835,-0.79211,-0.79584,-0.79954,-0.80321,-0.80685,-0.81046,
-0.81404,-0.81758,-0.8211,-0.82459,-0.82805,-0.83147,-0.83486,-0.83822,-0.84155,-0.84485,-0.84812,-0.85136,-0.85456,-0.85773,
-0.86087,-0.86397,-0.86705,-0.87009,-0.87309,-0.87607,-0.87901,-0.88192,-0.8848,-0.88764,-0.89045,-0.89322,-0.89597,-0.89867,
-0.90135,-0.90399,-0.9066,-0.90917,-0.91171,-0.91421,-0.91668,-0.91911,-0.92151,-0.92388,-0.92621,-0.92851,-0.93077,-0.93299,
-0.93518,-0.93734,-0.93946,-0.94154,-0.94359,-0.94561,-0.94759,-0.94953,-0.95144,-0.95331,-0.95514,-0.95694,-0.9587,-0.96043,
-0.96212,-0.96378,-0.96539,-0.96698,-0.96852,-0.97003,-0.9715,-0.97294,-0.97434,-0.9757,-0.97703,-0.97832,-0.97957,-0.98079,
-0.98196,-0.98311,-0.98421,-0.98528,-0.98631,-0.9873,-0.98826,-0.98918,-0.99006,-0.9909,-0.99171,-0.99248,-0.99321,-0.99391,
-0.99456,-0.99518,-0.99577,-0.99631,-0.99682,-0.99729,-0.99772,-0.99812,-0.99848,-0.9988,-0.99908,-0.99932,-0.99953,-0.9997,
-0.99983,-0.99992,-0.99998,-1,-0.99998,-0.99992,-0.99983,-0.9997,-0.99953,-0.99932,-0.99908,-0.9988,-0.99848,-0.99812,-0.99772,
-0.99729,-0.99682,-0.99631,-0.99577,-0.99518,-0.99456,-0.99391,-0.99321,-0.99248,-0.99171,-0.9909,-0.99006,-0.98918,-0.98826,
-0.9873,-0.98631,-0.98528,-0.98421,-0.98311,-0.98196,-0.98079,-0.97957,-0.97832,-0.97703,-0.9757,-0.97434,-0.97294,-0.9715,
-0.97003,-0.96852,-0.96698,-0.96539,-0.96378,-0.96212,-0.96043,-0.9587,-0.95694,-0.95514,-0.95331,-0.95144,-0.94953,-0.94759,
-0.94561,-0.94359,-0.94154,-0.93946,-0.93734,-0.93518,-0.93299,-0.93077,-0.92851,-0.92621,-0.92388,-0.92151,-0.91911,-0.91668,
-0.91421,-0.91171,-0.90917,-0.9066,-0.90399,-0.90135,-0.89867,-0.89597,-0.89322,-0.89045,-0.88764,-0.8848,-0.88192,-0.87901,
-0.87607,-0.87309,-0.87009,-0.86705,-0.86397,-0.86087,-0.85773,-0.85456,-0.85136,-0.84812,-0.84485,-0.84155,-0.83822,-0.83486,
-0.83147,-0.82805,-0.82459,-0.8211,-0.81758,-0.81404,-0.81046,-0.80685,-0.80321,-0.79954,-0.79584,-0.79211,-0.78835,-0.78456,
-0.78074,-0.77689,-0.77301,-0.7691,-0.76517,-0.7612,-0.75721,-0.75319,-0.74914,-0.74506,-0.74095,-0.73682,-0.73265,-0.72846,
-0.72425,-0.72,-0.71573,-0.71143,-0.70711,-0.70275,-0.69838,-0.69397,-0.68954,-0.68508,-0.6806,-0.67609,-0.67156,-0.667,
-0.66242,-0.65781,-0.65317,-0.64851,-0.64383,-0.63912,-0.63439,-0.62964,-0.62486,-0.62006,-0.61523,-0.61038,-0.60551,-0.60062,
-0.5957,-0.59076,-0.5858,-0.58081,-0.57581,-0.57078,-0.56573,-0.56066,-0.55557,-0.55046,-0.54532,-0.54017,-0.535,-0.5298,-0.52459,
-0.51936,-0.5141,-0.50883,-0.50354,-0.49823,-0.4929,-0.48755,-0.48218,-0.4768,-0.4714,-0.46598,-0.46054,-0.45508,-0.44961,-0.44412,
-0.43862,-0.43309,-0.42756,-0.422,-0.41643,-0.41084,-0.40524,-0.39962,-0.39399,-0.38835,-0.38268,-0.37701,-0.37132,-0.36561,-0.3599,
-0.35416,-0.34842,-0.34266,-0.33689,-0.33111,-0.32531,-0.3195,-0.31368,-0.30785,-0.30201,-0.29615,-0.29028,-0.28441,-0.27852,
-0.27262,-0.26671,-0.26079,-0.25487,-0.24893,-0.24298,-0.23702,-0.23106,-0.22508,-0.2191,-0.21311,-0.20711,-0.2011,-0.19509,
-0.18907,-0.18304,-0.177,-0.17096,-0.16491,-0.15886,-0.1528,-0.14673,-0.14066,-0.13458,-0.1285,-0.12241,-0.11632,-0.11022,
-0.10412,-0.09802,-0.09191,-0.0858,-0.07968,-0.07356,-0.06744,-0.06132,-0.0552,-0.04907,-0.04294,-0.03681,-0.03067,-0.02454,
-0.01841,-0.01227,-0.00614};
const double cos_tab[] = {
1,0.99998,0.99992,0.99983,0.9997,0.99953,0.99932,0.99908,0.9988,0.99848,0.99812,0.99772,0.99729,0.99682,0.99631,0.99577,0.99518,
0.99456,0.99391,0.99321,0.99248,0.99171,0.9909,0.99006,0.98918,0.98826,0.9873,0.98631,0.98528,0.98421,0.98311,0.98196,0.98079,
0.97957,0.97832,0.97703,0.9757,0.97434,0.97294,0.9715,0.97003,0.96852,0.96698,0.96539,0.96378,0.96212,0.96043,0.9587,0.95694,
0.95514,0.95331,0.95144,0.94953,0.94759,0.94561,0.94359,0.94154,0.93946,0.93734,0.93518,0.93299,0.93077,0.92851,0.92621,0.92388,
0.92151,0.91911,0.91668,0.91421,0.91171,0.90917,0.9066,0.90399,0.90135,0.89867,0.89597,0.89322,0.89045,0.88764,0.8848,0.88192,
0.87901,0.87607,0.87309,0.87009,0.86705,0.86397,0.86087,0.85773,0.85456,0.85136,0.84812,0.84485,0.84155,0.83822,0.83486,0.83147,
0.82805,0.82459,0.8211,0.81758,0.81404,0.81046,0.80685,0.80321,0.79954,0.79584,0.79211,0.78835,0.78456,0.78074,0.77689,0.77301,
0.7691,0.76517,0.7612,0.75721,0.75319,0.74914,0.74506,0.74095,0.73682,0.73265,0.72846,0.72425,0.72,0.71573,0.71143,0.70711,0.70275,
0.69838,0.69397,0.68954,0.68508,0.6806,0.67609,0.67156,0.667,0.66242,0.65781,0.65317,0.64851,0.64383,0.63912,0.63439,0.62964,
0.62486,0.62006,0.61523,0.61038,0.60551,0.60062,0.5957,0.59076,0.5858,0.58081,0.57581,0.57078,0.56573,0.56066,0.55557,0.55046,
0.54532,0.54017,0.535,0.5298,0.52459,0.51936,0.5141,0.50883,0.50354,0.49823,0.4929,0.48755,0.48218,0.4768,0.4714,0.46598,0.46054,
0.45508,0.44961,0.44412,0.43862,0.43309,0.42756,0.422,0.41643,0.41084,0.40524,0.39962,0.39399,0.38835,0.38268,0.37701,0.37132,
0.36561,0.3599,0.35416,0.34842,0.34266,0.33689,0.33111,0.32531,0.3195,0.31368,0.30785,0.30201,0.29615,0.29028,0.28441,0.27852,
0.27262,0.26671,0.26079,0.25487,0.24893,0.24298,0.23702,0.23106,0.22508,0.2191,0.21311,0.20711,0.2011,0.19509,0.18907,0.18304,
0.177,0.17096,0.16491,0.15886,0.1528,0.14673,0.14066,0.13458,0.1285,0.12241,0.11632,0.11022,0.10412,0.09802,0.09191,0.0858,0.07968,
0.07356,0.06744,0.06132,0.0552,0.04907,0.04294,0.03681,0.03067,0.02454,0.01841,0.01227,0.00614,0,-0.00614,-0.01227,-0.01841,
-0.02454,-0.03067,-0.03681,-0.04294,-0.04907,-0.0552,-0.06132,-0.06744,-0.07356,-0.07968,-0.0858,-0.09191,-0.09802,-0.10412,
-0.11022,-0.11632,-0.12241,-0.1285,-0.13458,-0.14066,-0.14673,-0.1528,-0.15886,-0.16491,-0.17096,-0.177,-0.18304,-0.18907,
-0.19509,-0.2011,-0.20711,-0.21311,-0.2191,-0.22508,-0.23106,-0.23702,-0.24298,-0.24893,-0.25487,-0.26079,-0.26671,-0.27262,
-0.27852,-0.28441,-0.29028,-0.29615,-0.30201,-0.30785,-0.31368,-0.3195,-0.32531,-0.33111,-0.33689,-0.34266,-0.34842,-0.35416,
-0.3599,-0.36561,-0.37132,-0.37701,-0.38268,-0.38835,-0.39399,-0.39962,-0.40524,-0.41084,-0.41643,-0.422,-0.42756,-0.43309,
-0.43862,-0.44412,-0.44961,-0.45508,-0.46054,-0.46598,-0.4714,-0.4768,-0.48218,-0.48755,-0.4929,-0.49823,-0.50354,-0.50883,
-0.5141,-0.51936,-0.52459,-0.5298,-0.535,-0.54017,-0.54532,-0.55046,-0.55557,-0.56066,-0.56573,-0.57078,-0.57581,-0.58081,-0.5858,
-0.59076,-0.5957,-0.60062,-0.60551,-0.61038,-0.61523,-0.62006,-0.62486,-0.62964,-0.63439,-0.63912,-0.64383,-0.64851,-0.65317,
-0.65781,-0.66242,-0.667,-0.67156,-0.67609,-0.6806,-0.68508,-0.68954,-0.69397,-0.69838,-0.70275,-0.70711,-0.71143,-0.71573,-0.72,
-0.72425,-0.72846,-0.73265,-0.73682,-0.74095,-0.74506,-0.74914,-0.75319,-0.75721,-0.7612,-0.76517,-0.7691,-0.77301,-0.77689,
-0.78074,-0.78456,-0.78835,-0.79211,-0.79584,-0.79954,-0.80321,-0.80685,-0.81046,-0.81404,-0.81758,-0.8211,-0.82459,-0.82805,
-0.83147,-0.83486,-0.83822,-0.84155,-0.84485,-0.84812,-0.85136,-0.85456,-0.85773,-0.86087,-0.86397,-0.86705,-0.87009,-0.87309,
-0.87607,-0.87901,-0.88192,-0.8848,-0.88764,-0.89045,-0.89322,-0.89597,-0.89867,-0.90135,-0.90399,-0.9066,-0.90917,-0.91171,
-0.91421,-0.91668,-0.91911,-0.92151,-0.92388,-0.92621,-0.92851,-0.93077,-0.93299,-0.93518,-0.93734,-0.93946,-0.94154,-0.94359,
-0.94561,-0.94759,-0.94953,-0.95144,-0.95331,-0.95514,-0.95694,-0.9587,-0.96043,-0.96212,-0.96378,-0.96539,-0.96698,-0.96852,
-0.97003,-0.9715,-0.97294,-0.97434,-0.9757,-0.97703,-0.97832,-0.97957,-0.98079,-0.98196,-0.98311,-0.98421,-0.98528,-0.98631,
-0.9873,-0.98826,-0.98918,-0.99006,-0.9909,-0.99171,-0.99248,-0.99321,-0.99391,-0.99456,-0.99518,-0.99577,-0.99631,-0.99682,
-0.99729,-0.99772,-0.99812,-0.99848,-0.9988,-0.99908,-0.99932,-0.99953,-0.9997,-0.99983,-0.99992,-0.99998,-1,-0.99998,-0.99992,
-0.99983,-0.9997,-0.99953,-0.99932,-0.99908,-0.9988,-0.99848,-0.99812,-0.99772,-0.99729,-0.99682,-0.99631,-0.99577,-0.99518,
-0.99456,-0.99391,-0.99321,-0.99248,-0.99171,-0.9909,-0.99006,-0.98918,-0.98826,-0.9873,-0.98631,-0.98528,-0.98421,-0.98311,
-0.98196,-0.98079,-0.97957,-0.97832,-0.97703,-0.9757,-0.97434,-0.97294,-0.9715,-0.97003,-0.96852,-0.96698,-0.96539,-0.96378,
-0.96212,-0.96043,-0.9587,-0.95694,-0.95514,-0.95331,-0.95144,-0.94953,-0.94759,-0.94561,-0.94359,-0.94154,-0.93946,-0.93734,
-0.93518,-0.93299,-0.93077,-0.92851,-0.92621,-0.92388,-0.92151,-0.91911,-0.91668,-0.91421,-0.91171,-0.90917,-0.9066,-0.90399,
-0.90135,-0.89867,-0.89597,-0.89322,-0.89045,-0.88764,-0.8848,-0.88192,-0.87901,-0.87607,-0.87309,-0.87009,-0.86705,-0.86397,
-0.86087,-0.85773,-0.85456,-0.85136,-0.84812,-0.84485,-0.84155,-0.83822,-0.83486,-0.83147,-0.82805,-0.82459,-0.8211,-0.81758,
-0.81404,-0.81046,-0.80685,-0.80321,-0.79954,-0.79584,-0.79211,-0.78835,-0.78456,-0.78074,-0.77689,-0.77301,-0.7691,-0.76517,
-0.7612,-0.75721,-0.75319,-0.74914,-0.74506,-0.74095,-0.73682,-0.73265,-0.72846,-0.72425,-0.72,-0.71573,-0.71143,-0.70711,
-0.70275,-0.69838,-0.69397,-0.68954,-0.68508,-0.6806,-0.67609,-0.67156,-0.667,-0.66242,-0.65781,-0.65317,-0.64851,-0.64383,
-0.63912,-0.63439,-0.62964,-0.62486,-0.62006,-0.61523,-0.61038,-0.60551,-0.60062,-0.5957,-0.59076,-0.5858,-0.58081,-0.57581,
-0.57078,-0.56573,-0.56066,-0.55557,-0.55046,-0.54532,-0.54017,-0.535,-0.5298,-0.52459,-0.51936,-0.5141,-0.50883,-0.50354,
-0.49823,-0.4929,-0.48755,-0.48218,-0.4768,-0.4714,-0.46598,-0.46054,-0.45508,-0.44961,-0.44412,-0.43862,-0.43309,-0.42756,
-0.422,-0.41643,-0.41084,-0.40524,-0.39962,-0.39399,-0.38835,-0.38268,-0.37701,-0.37132,-0.36561,-0.3599,-0.35416,-0.34842,
-0.34266,-0.33689,-0.33111,-0.32531,-0.3195,-0.31368,-0.30785,-0.30201,-0.29615,-0.29028,-0.28441,-0.27852,-0.27262,-0.26671,
-0.26079,-0.25487,-0.24893,-0.24298,-0.23702,-0.23106,-0.22508,-0.2191,-0.21311,-0.20711,-0.2011,-0.19509,-0.18907,-0.18304,
-0.177,-0.17096,-0.16491,-0.15886,-0.1528,-0.14673,-0.14066,-0.13458,-0.1285,-0.12241,-0.11632,-0.11022,-0.10412,-0.09802,
-0.09191,-0.0858,-0.07968,-0.07356,-0.06744,-0.06132,-0.0552,-0.04907,-0.04294,-0.03681,-0.03067,-0.02454,-0.01841,-0.01227,
-0.00614,0,0.00614,0.01227,0.01841,0.02454,0.03067,0.03681,0.04294,0.04907,0.0552,0.06132,0.06744,0.07356,0.07968,0.0858,
0.09191,0.09802,0.10412,0.11022,0.11632,0.12241,0.1285,0.13458,0.14066,0.14673,0.1528,0.15886,0.16491,0.17096,0.177,0.18304,
0.18907,0.19509,0.2011,0.20711,0.21311,0.2191,0.22508,0.23106,0.23702,0.24298,0.24893,0.25487,0.26079,0.26671,0.27262,0.27852,
0.28441,0.29028,0.29615,0.30201,0.30785,0.31368,0.3195,0.32531,0.33111,0.33689,0.34266,0.34842,0.35416,0.3599,0.36561,0.37132,
0.37701,0.38268,0.38835,0.39399,0.39962,0.40524,0.41084,0.41643,0.422,0.42756,0.43309,0.43862,0.44412,0.44961,0.45508,0.46054,
0.46598,0.4714,0.4768,0.48218,0.48755,0.4929,0.49823,0.50354,0.50883,0.5141,0.51936,0.52459,0.5298,0.535,0.54017,0.54532,0.55046,
0.55557,0.56066,0.56573,0.57078,0.57581,0.58081,0.5858,0.59076,0.5957,0.60062,0.60551,0.61038,0.61523,0.62006,0.62486,0.62964,
0.63439,0.63912,0.64383,0.64851,0.65317,0.65781,0.66242,0.667,0.67156,0.67609,0.6806,0.68508,0.68954,0.69397,0.69838,0.70275,
0.70711,0.71143,0.71573,0.72,0.72425,0.72846,0.73265,0.73682,0.74095,0.74506,0.74914,0.75319,0.75721,0.7612,0.76517,0.7691,
0.77301,0.77689,0.78074,0.78456,0.78835,0.79211,0.79584,0.79954,0.80321,0.80685,0.81046,0.81404,0.81758,0.8211,0.82459,0.82805,
0.83147,0.83486,0.83822,0.84155,0.84485,0.84812,0.85136,0.85456,0.85773,0.86087,0.86397,0.86705,0.87009,0.87309,0.87607,0.87901,
0.88192,0.8848,0.88764,0.89045,0.89322,0.89597,0.89867,0.90135,0.90399,0.9066,0.90917,0.91171,0.91421,0.91668,0.91911,0.92151,
0.92388,0.92621,0.92851,0.93077,0.93299,0.93518,0.93734,0.93946,0.94154,0.94359,0.94561,0.94759,0.94953,0.95144,0.95331,0.95514,
0.95694,0.9587,0.96043,0.96212,0.96378,0.96539,0.96698,0.96852,0.97003,0.9715,0.97294,0.97434,0.9757,0.97703,0.97832,0.97957,
0.98079,0.98196,0.98311,0.98421,0.98528,0.98631,0.9873,0.98826,0.98918,0.99006,0.9909,0.99171,0.99248,0.99321,0.99391,0.99456,
0.99518,0.99577,0.99631,0.99682,0.99729,0.99772,0.99812,0.99848,0.9988,0.99908,0.99932,0.99953,0.9997,0.99983,0.99992,0.99998};
#endif
int FFTdotnum = 0;
int M = 0;//M 级
float data[MAX];
float brevdataRe[MAX];
float brevdataIm[MAX];
float magdata[MAX];
//获取FFT点数 和 待处理数据
void GetFFT_Dots()
{
unsigned int i = 0;
cout<<“Please enter the dot num of FFT:”;
cin>>FFTdotnum;
cout<<“Please enter the “<<FFTdotnum <<” datas”<<endl;
while(i<FFTdotnum)
{
cin>>data[i++];
}
}
//将输入数组 data[] 倒位排序存放至 bredata[]
//如输入数组下标为bit3 bit2 bit1 bit0 将其存放至 bit0 bit1 bit2 bit3 对应的新地址中
void FFT_brev(float* data,float* bredata,unsigned int Dotnums)
{
unsigned int i = 0,j = 0,k = 0,Dotnum = 1;
//log2N , 求N
for(i=0;Dotnum<Dotnums;i++)Dotnum = Dotnum<<1;
M = i;
for(i=0;i<Dotnums;i++)
{
k = 0;
for(j=0;j<M;j++)
{
if(i&(1<<j))k |= (1<<(M-1))>>j;
}
*(bredata+k) = *(data+i);
}
}
//FFT计算
void FFT_butterfly()
{
unsigned int m,n,k;//m级,每级下分n个Wn,每个Wn下有几次蝶形运算
unsigned int N,p;
float temR,temI,tempRp,tempIp;
for(m=0;m<M;m++)
{
N = 1<<m;//N = 2^m
for(n=0;n<N;n++)//每级下W因子的个数
{
p = (1<<(M-m-1));//p = 2^(M-m-1)同级不同旋转因子之间的下标间距
p = p*n;
p = p*(FFTNUM>>M);
for(k=n;k<FFTdotnum;k += 2*N)//计算相同W因子的所有蝶形
{
tempRp = brevdataRe[k];
tempIp = brevdataIm[k];
temR = brevdataRe[k+N]*cos_tab[p] + brevdataIm[k+N]*sin_tab[p];
temI = – brevdataRe[k+N]*sin_tab[p] + brevdataIm[k+N]*cos_tab[p];
brevdataRe[k+N] = tempRp – temR;
brevdataIm[k+N] = tempIp – temI;
brevdataRe[k] = tempRp + temR;
brevdataIm[k] = tempIp + temI;
}
}
}
}
int main()
{
unsigned int i = 0;
GetFFT_Dots();
FFT_brev(data,brevdataRe,FFTdotnum);
FFT_butterfly();
for(i=0;i<FFTdotnum;i++)cout<<i<<“: “<<brevdataRe[i]<<” “<<brevdataIm[i]<<endl;
while(1);
return 1;
}