一、变换目标
x=2*sin(2*pi*50*t); 采样率为1000;
二、测试函数
#include "dsp_fft.h"
float32_t test_out[1024];
float32_t test_in[2048];
void fft_test(void)
{
u16 i;
for(i=0;i<1024;i++)
{
test_in[i*2+1]=0;
test_in[i*2]=arm_sin_f32(2*3.1415926*50*i/1000);
}
arm_cfft_f32(&arm_cfft_sR_f32_len1024,test_in,0,1);
arm_cmplx_mag_f32(test_in,test_out,1024);
for(i=0;i<1024;i++)
{
printf("%f\r\n",test_out[i]);
}
}
三、主函数
/*
昆明电器科学研究所 张恩寿 2019年5月3日
*/
#include "bitband.h"
#include "led_config.h"
#include "systick.h"
#include "usart.h"
#include "spi_flash.h"
#include "tft.h"
#include "key_lookup.h"
#include "dsp_fft.h"
int main(void)
{
systick_config(120);
nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
usart0_init(115200);
led_init();
fft_test();
while(1)
{
led_on();
delay_nms(600);
led_off();
delay_nms(600);
}
}
四、MATLAB函数
stm32=[1.705632
1.707621
1.713326
1.722719
1.735882
1.752857
1.773772
1.798508
1.827277
1.860163
1.897144
1.938122
1.983548
2.033568
2.088088
2.147741
2.212042
2.282177
2.357983
2.439880
2.528092
2.623763
2.726846
2.838429
2.959060
3.089876
3.231769
3.386125
3.554645
3.738804
3.940831
4.163391
4.409548
4.683141
4.989015
5.332843
5.721903
6.166427
6.678069
7.273537
7.975621
8.815111
9.837244
11.108480
12.732266
14.879780
17.852674
22.240526
29.369764
42.978416
79.265205
478.406281
120.296638
53.772808
34.764549
25.759335
20.505369
17.062328
14.631233
12.823098
11.425245
10.312147
9.404791
8.650594
8.014164
7.469474
6.998009
6.586292
6.223259
5.900481
5.611870
5.352154
5.117285
4.903747
4.708768
4.529855
4.365328
4.213433
4.072542
3.941772
3.819881
3.706118
3.599553
3.499597
3.405564
3.316926
3.233330
3.154626
3.079564
3.008623
2.941279
2.877166
2.816226
2.757876
2.702428
2.649343
2.598507
2.549876
2.503153
2.458415
2.415564
2.374239
2.334496
2.296287
2.259437
2.223906
2.189626
2.156370
2.124491
2.093456
2.063578
2.034624
2.006721
1.979478
1.953124
1.927659
1.902704
1.878604
1.855249
1.832461
1.810496
1.788850
1.767703
1.747423
1.727579
1.708428
1.689857
1.671444
1.653469
1.635973
1.618953
1.602362
1.586097
1.570187
1.554554
1.539359
1.524696
1.510090
1.495952
1.482038
1.468630
1.455292
1.442373
1.429402
1.416936
1.404837
1.392874
1.381115
1.369549
1.358197
1.347302
1.336454
1.325581
1.315329
1.304817
1.294665
1.284861
1.275251
1.265608
1.256245
1.247059
1.238021
1.229096
1.220244
1.211625
1.203201
1.195096
1.186803
1.178958
1.171129
1.163197
1.155283
1.147813
1.140400
1.133089
1.126058
1.118900
1.111673
1.105019
1.098120
1.091466
1.085091
1.078551
1.071986
1.065795
1.059625
1.053377
1.047395
1.041494
1.035593
1.029878
1.024193
1.018570
1.013009
1.007612
1.002152
0.996941
0.991575
0.986392
0.981311
0.976263
0.971295
0.966458
0.961598
0.956707
0.951966
0.947264
0.942690
0.938204
0.933678
0.929323
0.924682
0.920126
0.916139
0.911875
0.907646
0.903809
0.899788
0.895552
0.891553
0.887700
0.883872
0.880002
0.875981
0.872332
0.868851
0.865340
0.861670
0.857843
0.854081
0.850627
0.847250
0.843765
0.840376
0.836955
0.833661
0.830501
0.827214
0.823917
0.820735
0.817528
0.814454
0.811420
0.808434
0.805541
0.802449
0.799689
0.796649
0.793619
0.790753
0.788025
0.785206
0.782519
0.779524
0.776883
0.774462
0.771012
0.769007
0.766530
0.763897
0.761283
0.758819
0.756306
0.753913
0.751347
0.748840
0.746699
0.744211
0.741727
0.739418
0.737209
0.735040
0.732558
0.730283
0.728240
0.725993
0.723771
0.721577
0.719450
0.717269
0.715411
0.713178
0.711292
0.709138
0.707122
0.705133
0.703167
0.701193
0.699128
0.697467
0.695514
0.693550
0.691697
0.689743
0.687987
0.686206
0.684359
0.682701
0.680823
0.678866
0.677327
0.675707
0.673972
0.672177
0.670639
0.669043
0.667313
0.665721
0.664093
0.662472
0.661024
0.659392
0.657797
0.656169
0.654634
0.653742
0.651563
0.650713
0.648990
0.647301
0.645788
0.644544
0.643261
0.641753
0.640270
0.638897
0.637779
0.636631
0.635227
0.633571
0.631935
0.630659
0.629513
0.628341
0.627070
0.625723
0.624517
0.623289
0.622184
0.620807
0.619635
0.618524
0.617261
0.616258
0.615209
0.614018
0.612788
0.611625
0.610524
0.609360
0.608311
0.607415
0.606179
0.605185
0.604235
0.603130
0.602274
0.601421
0.601594
0.597894
0.597486
0.596657
0.595789
0.594790
0.593812
0.592877
0.591959
0.591096
0.590282
0.589291
0.588338
0.587446
0.586829
0.585701
0.584922
0.583953
0.583245
0.582365
0.581520
0.580735
0.579857
0.579073
0.578256
0.577496
0.576744
0.575828
0.575108
0.574449
0.573607
0.572776
0.572119
0.571443
0.570637
0.569990
0.569224
0.568439
0.568052
0.567243
0.566562
0.565957
0.564962
0.564719
0.564005
0.563458
0.562361
0.562072
0.561498
0.560724
0.560078
0.559464
0.558953
0.558364
0.557838
0.557270
0.556499
0.556054
0.555684
0.554750
0.554127
0.554070
0.553466
0.552812
0.552444
0.551826
0.551389
0.550832
0.550366
0.549975
0.549426
0.548704
0.548041
0.547540
0.547265
0.547165
0.546898
0.546341
0.545814
0.545422
0.545012
0.544678
0.544218
0.543789
0.543685
0.543140
0.542412
0.542347
0.541979
0.541500
0.541217
0.540830
0.540534
0.540150
0.539848
0.539538
0.539094
0.538843
0.538627
0.538177
0.537981
0.537553
0.537185
0.538064
0.537052
0.536660
0.536361
0.536123
0.535908
0.535709
0.535438
0.535166
0.534928
0.534751
0.534503
0.534289
0.534147
0.533761
0.533774
0.533463
0.533187
0.532870
0.533066
0.532658
0.532622
0.532482
0.532273
0.532217
0.531993
0.531831
0.531887
0.531600
0.531534
0.531389
0.531378
0.531215
0.531120
0.531018
0.530859
0.530862
0.530849
0.530626
0.530647
0.530542
0.530367
0.530766
0.530657
0.530118
0.530341
0.530322
0.530254
0.530158
0.530267
0.530247
0.530418
0.530243
0.530267
0.530159
0.530254
0.530319
0.530341
0.530118
0.530657
0.530766
0.530368
0.530544
0.530647
0.530622
0.530849
0.530861
0.530859
0.531019
0.531120
0.531217
0.531376
0.531390
0.531534
0.531599
0.531886
0.531831
0.531994
0.532217
0.532273
0.532487
0.532622
0.532654
0.533066
0.532869
0.533188
0.533459
0.533774
0.533759
0.534147
0.534290
0.534503
0.534754
0.534929
0.535165
0.535437
0.535709
0.535910
0.536121
0.536361
0.536662
0.537051
0.538084
0.537180
0.537554
0.537981
0.538176
0.538626
0.538844
0.539094
0.539539
0.539848
0.540145
0.540534
0.540828
0.541217
0.541501
0.541979
0.542349
0.542412
0.543142
0.543685
0.543789
0.544218
0.544678
0.545012
0.545421
0.545815
0.546338
0.546900
0.547164
0.547265
0.547538
0.548041
0.548707
0.549426
0.549976
0.550367
0.550832
0.551389
0.551827
0.552444
0.552811
0.553465
0.554068
0.554127
0.554749
0.555684
0.556053
0.556499
0.557271
0.557837
0.558364
0.558953
0.559465
0.560078
0.560723
0.561498
0.562072
0.562360
0.563459
0.564005
0.564718
0.564962
0.565958
0.566561
0.567250
0.568052
0.568441
0.569224
0.569989
0.570637
0.571444
0.572119
0.572779
0.573608
0.574452
0.575108
0.575828
0.576744
0.577495
0.578256
0.579073
0.579858
0.580734
0.581520
0.582366
0.583244
0.583952
0.584922
0.585702
0.586829
0.587447
0.588338
0.589290
0.590281
0.591096
0.591958
0.592881
0.593813
0.594789
0.595788
0.596658
0.597486
0.597896
0.601594
0.601422
0.602273
0.603137
0.604234
0.605182
0.606179
0.607414
0.608311
0.609360
0.610525
0.611624
0.612789
0.614020
0.615208
0.616255
0.617261
0.618522
0.619634
0.620813
0.622184
0.623287
0.624517
0.625723
0.627071
0.628335
0.629513
0.630659
0.631935
0.633570
0.635226
0.636632
0.637779
0.638897
0.640271
0.641753
0.643262
0.644545
0.645788
0.647304
0.648990
0.650711
0.651563
0.653743
0.654633
0.656168
0.657796
0.659389
0.661023
0.662470
0.664091
0.665728
0.667311
0.669045
0.670639
0.672178
0.673972
0.675707
0.677327
0.678865
0.680823
0.682700
0.684359
0.686205
0.687987
0.689745
0.691697
0.693555
0.695514
0.697467
0.699128
0.701191
0.703166
0.705136
0.707123
0.709139
0.711292
0.713176
0.715411
0.717268
0.719450
0.721578
0.723770
0.725990
0.728240
0.730280
0.732558
0.735039
0.737210
0.739421
0.741726
0.744214
0.746700
0.748840
0.751348
0.753914
0.756306
0.758819
0.761282
0.763900
0.766530
0.769007
0.771012
0.774464
0.776884
0.779525
0.782519
0.785204
0.788025
0.790752
0.793620
0.796650
0.799689
0.802453
0.805540
0.808432
0.811420
0.814456
0.817528
0.820734
0.823916
0.827211
0.830501
0.833660
0.836955
0.840374
0.843765
0.847249
0.850627
0.854083
0.857843
0.861666
0.865340
0.868847
0.872332
0.875984
0.880002
0.883872
0.887700
0.891552
0.895552
0.899787
0.903809
0.907644
0.911875
0.916138
0.920125
0.924687
0.929322
0.933678
0.938206
0.942694
0.947263
0.951977
0.956706
0.961596
0.966457
0.971296
0.976263
0.981312
0.986391
0.991578
0.996941
1.002149
1.007612
1.013012
1.018570
1.024192
1.029877
1.035598
1.041494
1.047396
1.053377
1.059625
1.065795
1.071985
1.078551
1.085090
1.091463
1.098128
1.105018
1.111673
1.118900
1.126059
1.133089
1.140401
1.147813
1.155287
1.163197
1.171131
1.178958
1.186803
1.195096
1.203205
1.211625
1.220243
1.229096
1.238019
1.247059
1.256249
1.265607
1.275248
1.284861
1.294665
1.304817
1.315328
1.325581
1.336455
1.347302
1.358196
1.369548
1.381121
1.392875
1.404837
1.416936
1.429404
1.442373
1.455292
1.468632
1.482039
1.495952
1.510090
1.524696
1.539361
1.554554
1.570187
1.586097
1.602361
1.618953
1.635972
1.653469
1.671444
1.689857
1.708426
1.727579
1.747422
1.767703
1.788850
1.810496
1.832461
1.855249
1.878604
1.902704
1.927657
1.953124
1.979480
2.006721
2.034626
2.063578
2.093448
2.124491
2.156369
2.189626
2.223907
2.259438
2.296289
2.334496
2.374237
2.415564
2.458418
2.503153
2.549876
2.598506
2.649346
2.702428
2.757876
2.816226
2.877167
2.941279
3.008625
3.079564
3.154626
3.233330
3.316925
3.405563
3.499598
3.599552
3.706121
3.819881
3.941767
4.072544
4.213431
4.365324
4.529853
4.708769
4.903748
5.117286
5.352153
5.611871
5.900481
6.223258
6.586293
6.998009
7.469474
8.014163
8.650593
9.404791
10.312144
11.425244
12.823097
14.631233
17.062326
20.505369
25.759335
34.764549
53.772816
120.296646
478.406219
79.265205
42.978424
29.369764
22.240528
17.852673
14.879777
12.732265
11.108480
9.837243
8.815109
7.975622
7.273535
6.678069
6.166427
5.721903
5.332841
4.989015
4.683140
4.409548
4.163389
3.940831
3.738807
3.554645
3.386127
3.231769
3.089876
2.959060
2.838427
2.726846
2.623765
2.528092
2.439873
2.357983
2.282176
2.212042
2.147743
2.088089
2.033571
1.983547
1.938120
1.897144
1.860163
1.827277
1.798507
1.773772
1.752860
1.735882
1.722718
1.713326
1.707621
];
fs=1000;
N=1024;
n=0:N-1;
t=0:1/fs:1-1/fs;
f=n*fs/N;
x=2*sin(2*pi*50*t);
y=fft(x,N);
subplot(211)
plot(f,abs(y)),title('MATLAB计算结果'),xlabel('频率'),ylabel('幅值'),grid;
subplot(212)
plot(f,stm32),title('GD32F303计算结果'),xlabel('频率'),ylabel('幅值'),grid;
五、结果
|