Effacer les filtres
Effacer les filtres

How to perform fft

3 vues (au cours des 30 derniers jours)
Efstathios Kontolatis
Efstathios Kontolatis le 23 Fév 2017
Réponse apportée : Rik le 23 Fév 2017
I have 1000 samples from an experiment with frequency Fs=67890 Hz. How can I perform fft on them? I followed the guide here https://uk.mathworks.com/help/matlab/ref/fft.html but it seems that the dominant frequency is zero which has no physical meaning.
These are my data
x =
0.3551
0.2308
0.3209
0.4527
0.4606
0.4511
0.4925
0.4769
0.5424
0.4698
0.4246
0.4502
0.5823
0.5451
0.4235
0.4062
0.3832
0.2749
0.1591
0.1889
0.4155
0.3840
0.3582
0.1852
0.2677
0.2454
0.2458
0.2100
0.1469
0.1186
0
0.4154
0.4807
0.4320
0.4072
0.3352
0.3357
0.2770
0.2801
0.3578
0.2703
0.3626
0.0998
0.3656
0.2590
0.4388
0.4144
0.2631
0
0.1076
0
0.4535
0.4626
0.4159
0.3686
0.4763
0.2582
0.2961
0.3691
0.3860
0.3875
0.4018
0.4292
0.3921
0.3128
0.4884
0.3153
0.2672
0.3448
0.3787
0.4799
0.3870
0.3534
0.3968
0.3006
0.3119
0.3585
0.1352
0.4154
0.3323
0.3733
0.3232
0.4116
0.3276
0.4852
0.3715
0.3991
0.3766
0.4866
0.3483
0.2736
0.3153
0.4049
0.3774
0.3071
0.3831
0.3992
0.3661
0.3337
0.1616
0.3305
0.4556
0.5053
0.4209
0.2868
0.2666
0.3057
0.4016
0.2579
0.4286
0.1672
0.4614
0.3814
0.4272
0.3374
0.4215
0.4788
0.3943
0.4097
0.3937
0.4230
0.4981
0.4821
0.1748
0.4015
0.5066
0.4959
0.4267
0.4692
0.3354
0.2919
0.5676
0.4875
0.4957
0.4122
0.5627
0.4573
0.3724
0.4320
0.4127
0.3655
0.3132
0.1982
0.2905
0.3757
0.5282
0.4584
0.4669
0.4059
0.3229
0.4696
0.3960
0.5024
0.4505
0.4084
0.4720
0.4251
0.3683
0.3791
0.3650
0.2426
0.3169
0.4405
0.4129
0.4839
0.3578
0.3550
0.4090
0.4063
0.4497
0.5195
0.4645
0.4514
0.4375
0.3405
0.5263
0.4195
0.3746
0.2887
0.4121
0.3987
0.4428
0.4065
0.3340
0.3511
0.3328
0.3698
0.4988
0.3478
0.2817
0.2795
0.4926
0.3976
0.3728
0.4816
0.4690
0.4328
0.6150
0.1455
0.3981
0.3184
0.4321
0.3678
0.3407
0.2930
0.3325
0.5747
0.5205
0.4418
0.4604
0.3597
0.3404
0.3153
0.5779
0.3666
0.3215
0.2842
0.2314
0.2940
0.3745
0.3215
0.2711
0.3004
0.3946
0.3942
0.3256
0.2587
0.3177
0.2474
0.2057
0.4025
0.4435
0.4262
0.3123
0.3033
0.3595
0.3224
0.5162
0.5210
0.5185
0.5082
0.5174
0.4634
0.4224
0.5525
0.4637
0.5132
0.5806
0.3519
0.5952
0.5103
0.4021
0.3890
0.3671
0.5863
0.3946
0.3198
0.1014
0.4934
0.4089
0.5890
0.4601
0.5628
0.5392
0.4553
0.4755
0.5468
0.4478
0.4900
0.3323
0.2200
0.4340
0.4119
0.4075
0.3577
0.5101
0.3585
0.3939
0.4366
0.3738
0.3934
0.4416
0.4464
0.3510
0.3791
0.4289
0.3966
0.3113
0.2998
0.4251
0.4033
0.3393
0.3843
0.4246
0.4224
0.4072
0.2900
0.4400
0.5314
0.4580
0.4382
0.4118
0.4298
0.5275
0.4492
0.4100
0.4098
0.4530
0.4531
0.4177
0.5175
0.2001
0.5330
0.4534
0.4613
0.0637
0.4619
0.5318
0.4129
0.3292
0.3293
0.4428
0.3560
0.4558
0.3736
0.2481
0.3881
0.3586
0.3284
0.0465
0.3070
0.4227
0.3891
0.3911
0.5650
0.3529
0.3481
0.3482
0.3682
0.5319
0.5387
0.1824
0.3062
0.4315
0.4625
0.3685
0.5253
0.4801
0.5584
0.4634
0.5326
0.4494
0.4534
0.4064
0.3226
0.1444
0.4603
0.4277
0
0.3656
0.4511
0.5926
0.4544
0.4301
0.3542
0.3607
0.3684
0.4694
0.5180
0.3940
0.4657
0.3901
0.4060
0.3740
0.3351
0.3571
0.3845
0.3225
0.4296
0.3675
0.4469
0.3926
0.3571
0.3877
0.2835
0.4564
0.4695
0.3038
0.4322
0.3454
0.4157
0.4131
0.3656
0.3244
0.3835
0.3835
0.3669
0.3769
0.3392
0.4072
0.4156
0.4026
0.4092
0.3624
0.4615
0.3921
0.4848
0.4077
0.2904
0.3404
0.3485
0.4472
0.4097
0.3488
0.3555
0.2958
0.1905
0.2594
0.5082
0.3526
0.5096
0.2486
0.3777
0.3662
0.4036
0.4170
0.4132
0.4760
0.4813
0.2767
0.4714
0.3762
0.3883
0.2067
0.1974
0.3166
0.3852
0.2576
0.3949
0.2443
0.3779
0.4300
0.3881
0.3786
0.3516
0.4147
0.3850
0.4277
0.4620
0.4737
0.4113
0.3448
0.3532
0.3431
0.2336
0.4660
0.4304
0.4478
0.2664
0.3472
0.3404
0.3530
0.5004
0.4685
0.4902
0.5056
0.4876
0.3388
0.3673
0.4873
0.3627
0.3553
0.3385
0.3725
0.5111
0.4345
0.3356
0.3316
0.3864
0.3736
0.3033
0.4409
0.4224
0.3873
0.3507
0.3317
0.3222
0.2853
0.3617
0.4143
0.4293
0.3870
0.3259
0.4120
0.3762
0.3981
0.4022
0.3711
0.3616
0.4801
0.3860
0.2593
0.5820
0.4110
0.4032
0.4109
0.3933
0.4776
0.2430
0.4151
0.4863
0.3633
0.1881
0.1723
0.4596
0.3971
0.3804
0.4301
0.2390
0.4319
0.3753
0.4073
0.4224
0.4255
0.4830
0.3504
0.3461
0.1993
0.4117
0.4678
0.4710
0.3577
0.3979
0.3993
0.3446
0.3214
0.3113
0.3695
0.3847
0.4664
0.4420
0.3579
0.5084
0.4741
0.4416
0.4036
0.3741
0.4747
0.5657
0.4787
0.4972
0.3841
0.2781
0.4447
0.5256
0.4557
0.4701
0.4399
0.3622
0.3493
0.3782
0.3784
0.6737
0.5224
0.4507
0.2935
0.4661
0.3368
0.3713
0.4094
0.3704
0.4510
0.3874
0.4808
0.3836
0.4163
0.2954
0.4038
0.3723
0.3454
0.3572
0.2956
0.3123
0.3045
0.3775
0.3586
0.3899
0.3283
0.2579
0.3975
0.3386
0.3333
0.3667
0.2439
0.3291
0.4948
0.4187
0.4469
0.3125
0.2881
0.1765
0.3667
0.4266
0.4227
0.4985
0.3694
0.3063
0.3647
0.3031
0.4227
0.4508
0.3426
0.2608
0.3380
0.4410
0.2822
0.3007
0.2079
0.3175
0.2548
0.2257
0.2664
0.2629
0.3153
0.2829
0.1878
0.2932
0.4240
0.3506
0.3450
0.3436
0.3147
0.4307
0.3297
0.3263
0.2626
0.3670
0.3903
0.3504
0.3635
0.3506
0.3645
0.3349
0.3742
0.4376
0.3087
0.1669
0.5031
0.4398
0.3169
0.1251
0.3737
0.4122
0.3529
0.3419
0.3728
0.3230
0.3516
0.3272
0.4056
0.4307
0.4187
0.3042
0.3735
0.3499
0.4240
0.1846
0.2853
0.2608
0.3536
0.3915
0.4461
0.4830
0.4267
0.2480
0.4508
0.1829
0.2214
0.3592
0.4563
0.2695
0.3125
0.2981
0.4959
0.3519
0.1361
0.3236
0.3682
0.3274
0.4352
0.3589
0.3794
0.3441
0.4345
0.3739
0.3811
0.3532
0.3125
0.4182
0.2854
0.3541
0.3988
0.4035
0.3540
0.3104
0.4531
0.5163
0.5809
0.3362
0.4588
0.4724
0.4871
0.4134
0.4033
0.3325
0.4309
0.3734
0.3137
0.3562
0.4370
0.2704
0.3935
0.3315
0.3020
0.3531
0.2427
0.3931
0.3654
0.3365
0.5205
0.3245
0.6086
0.4521
0.3837
0.4901
0.3527
0.4278
0.2909
0.3649
0.3479
0.2947
0.5558
0.4566
0.5902
0.4304
0.5311
0.5395
0.3745
0.5311
0.3001
0.4030
0.4117
0.3925
0.4652
0.3820
0.2739
0.4634
0.3541
0.3096
0.3282
0.3180
0.2612
0.2147
0.4373
0.4462
0.4324
0.4857
0.2976
0.3247
0.3276
0.3106
0.5885
0.5510
0.3492
0.3284
0.4325
0.4530
0.5664
0.5522
0.4787
0.4568
0.4210
0.5093
0.4775
0.4069
0.4151
0.4295
0.4312
0.3926
0.3863
0.3583
0.4121
0.3848
0.3773
0.3826
0.3374
0.3023
0.3368
0.4261
0.2167
0.4879
0.3032
0.2540
0.5302
0.4484
0.4872
0.3173
0.3800
0.4337
0.3698
0.3272
0.2498
0.3854
0.4042
0.4299
0.4018
0.3248
0.3756
0.3824
0.4029
0.4295
0.3573
0.3036
0.0557
0.4097
0.5186
0.4060
0.3733
0.2700
0.4013
0.2437
0.4369
0.3374
0.3853
0.4096
0.3145
0.3664
0.4738
0.2346
0.3548
0.2804
0.4698
0.4039
0.4628
0.4387
0.3089
0.3981
0.4727
0.4335
0.3591
0.4623
0.3922
0.4100
0.3585
0.4101
0.3834
0.2742
0.2886
0.4118
0.4812
0.4434
0.4607
0.3134
0.0859
0.1066
0.3441
0.2788
0.3310
0.4330
0.3551
0.4324
0.4427
0.3585
0.4497
0.1920
0.3622
0.4184
0.4762
0.4427
0.4545
0.4054
0.4440
0.3977
0.5034
0.5101
0.3951
0.5061
0.4242
0.4591
0.5080
0.4194
0.6229
0.3667
0.4874
0.4718
0.4996
0.2885
0.4989
0.5071
0.4529
0.5001
0.4165
0.4620
0.4430
0.3566
0.3709
0.4315
0.4694
0.3501
0.3343
0.4227
0.3484
0.3737
0.1854
0.4691
0.4328
0.4059
0.4462
0.4397
0.3578
0.3274
0.4586
0.4864
0.5225
0.3509
0.4212
0.4003
0.4854
0.1942
0.4785
0.4362
0.4213
0.4979
0.4989
0.3758
0.4904
0.6655
0.4860
0.4498
0.4712
0.3502
0.3666
0.3871
0.5061
0.3993
0.2872
0.3147
0.3531
0.4126
0.4546
0.4136
0.4674
0.4634
0.4877
0.4136
0.3401
0.4442
0.3997
0.3753
0.4675
0.3769
0.3556
0.3799
0.5048
0.3805
0.4656
0.4621
0.3986
0.2977
0.3280
0.4630
0.4375
0.3109
0.3265
0.4582
0.4432
0.3801
0.4558
0.4408
0.4279
0.3974
0.3856
0.4107
0.4463
0.4646
0.3674
0.4938
0.3389
0.4625
0.3187
0.3233
0.4389
0.3224
0.3140
0.4371
0.3664
0.4664
0.4350
0.4211
0.3415
and here is the code I have used for the fft
fs=67890;
T = 1/fs; % Sampling period
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
y = fft(x);
P2 = abs(y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = fs*(0:(L/2))/L;
subplot(2,1,1), plot(t,x),title('original data'),ylabel('x'),xlabel('t')
subplot(2,1,2), plot(f,P1),title('fft'),ylabel('magnitude'),xlabel('frequency')
This gives me this image
Hope it's clear
  5 commentaires
Adam
Adam le 23 Fév 2017
So just do what Rik Wisselink suggests to zero-centre your data or simply remove the 0-frequency component from the final result and plot it without if you just want to look at the frequency spectrum.
Efstathios Kontolatis
Efstathios Kontolatis le 23 Fév 2017
Yes indeed that worked. Thank you very much. I would have accepted the answer if I knew how to do it.

Connectez-vous pour commenter.

Réponse acceptée

Rik
Rik le 23 Fév 2017
[moved from comments]
To remove the 0Hz-component from the analysis, use y=fft(x-mean(x));

Plus de réponses (1)

Pooja Patel
Pooja Patel le 23 Fév 2017
  • amp1 = abs(fft(x1)); %Retain Magnitude
  • % amp11 = amp1(1:Nsamps1/2); %Discard Half of Points
  • % f11 = Fs*(0:Nsamps1/2-1)/Nsamps1; %Prepare freq data for plot
  • f11 = 0:(fs1/Nsamps1):1000; %Prepare freq data for plot
  • amp11 = amp1(1:length(f11)); % keep data till 1kHz
  • plot(f11,amp11);

Catégories

En savoir plus sur Parametric Spectral Estimation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by