Domanda

I have two Signals: a noisy Input-Signal and a filtered OutputSignal. The Noise-Filter has been implemented with a Kalman-Filter.

Please click on the link below to see the signals!

As I see it, the Signals have two main Frequencies: first of all the big waves with a period of about 75 units and the small noise with a period of 4-5 units. The implemented filter only reduces the noise with small wavelengths.

For a presentation I want to visualize the spectrum of the two signals to show the influence of the filter on different wavelengths.

I tried to use the Matlab Fourier-Function 'fft' but the result did not represent the two frequencies at all. I also tried the MatlabTool 'sptool' without convincing results. The online Tool 'Fourier Calculator from sooeet' gave different results but not what I expected either. I tried all these tool but the spectrums always looked completely random and noisy.

What I would like to see is a spectrum composed of low frequencies and high frequencies (as you see in the linked picture), but all of the algorithms/tools tested looked totally different:

I outlined my expectations on the linked picture below.

the two signals and my expectation of the spectrum

Perhaps somebody knows a tool that can calculate the frequencies like this.

The values of the Signals are:

   -0.0823
   -0.2204
   -0.0970
   -0.1723
   -0.5056
   -0.2664
   -0.4280
   -0.2442
   -0.2904
   -0.6514
   -0.7039
   -0.6013
   -0.5876
   -0.6501
   -0.8850
   -0.6061
   -0.7922
   -0.7860
   -0.7300
   -0.9097
   -0.6734
   -0.2516
   -0.6025
   -0.0040
   -0.3505
   -0.0618
   -0.2220
   -0.1041
   -0.0215
    0.0490
    0.0018
    0.0878
   -0.2293
    0.2410
    0.0657
    0.3257
    0.0826
    0.3924
    0.3064
    0.3345
    0.7688
    1.0730
    0.2063
    0.7171
    0.3272
    0.4987
    0.4019
    0.5663
    0.6382
    0.5370
    0.4147
    0.6068
    0.2181
    0.2454
    0.2029
    0.1753
    0.0018
    0.0644
    0.1498
   -0.0313
   -0.0415
   -0.1254
    0.2691
    0.3785
    0.0608
    0.2413
    0.2164
    0.2247
    0.0968
    0.1985
    0.2755
    0.1995
    0.3376
    0.1872
    0.1262
   -0.0419
   -0.2308
    0.0048
    0.0579
   -0.0625
   -0.1756
    0.0075
   -0.0790
   -0.2651
   -0.0291
   -0.1313
   -0.2738
   -0.4048
   -0.3443
   -0.3889
   -0.6654
   -0.4471
   -0.4641
   -0.3966
   -0.4480
   -0.0957
   -0.1514
   -0.5184
   -0.2632
   -0.3455
   -0.5005
   -0.2175
   -0.2515
   -0.2996
   -0.1989
   -0.3179
    0.1894
    0.0282
   -0.3516
   -0.0274
   -0.2997
    0.2925
    0.3074
    0.2470
    0.1185
    0.2817
    0.1456
    0.2326
    0.1424
    0.3457
    0.3262
    0.2793
    0.3235
    0.1701
    0.2401
    0.2372
    0.0883
    0.1992
    0.2818
    0.0423
    0.6161
    0.4469
    0.5074
    0.5558
    0.6857
    0.6317
    0.4676
    0.3587
    0.4891
    0.2760
    0.3660
    0.3490
    0.1351
    0.1628
    0.2769
    0.1409
    0.1632
    0.1190
    0.5887
    0.1945
    0.0592
    0.0377
    0.2261
   -0.2178
    0.0442
   -0.4583
   -0.5077
   -0.4960
   -0.0434
   -0.3791
   -0.3672
   -0.4118
   -0.5115
   -0.3916
   -0.3545
   -0.2559
   -0.3569
   -0.3129
   -0.3004
   -0.2316
   -0.3691
   -0.3324
   -0.2454
   -0.2001
   -0.2204
   -0.2280
   -0.3068
   -0.2990
    0.1794
   -0.1716
   -0.0941
    0.2398
    0.1337
    0.0755
    0.2363
    0.0564
    0.1874
    0.3280
    0.1725
    0.4464
    0.1402
   -0.0018
    0.2718
    0.2061
    0.1836
    0.1328
    0.0092
    0.0355
    0.1673
    0.1444
    0.1378
    0.1587
    0.2226
    0.2634
    0.0417
   -0.0195
    0.0539
    0.3441
    0.1436
    0.5122
    0.3686
    0.3828
    0.3396
    0.3270
    0.4811
    0.2049
    0.2682
    0.3395
    0.3420
    0.3748
    0.3716
    0.3894
   -0.1382
   -0.1493
   -0.0868
   -0.1573
   -0.1433
   -0.2175
   -0.1783
   -0.0486
   -0.2032
   -0.2025
   -0.4589
   -0.7354
   -0.3886
   -0.0840
   -0.4575
   -0.3431
   -0.5350
   -0.5113
   -0.2056
   -0.4737
    0.0260
   -0.5121
   -0.1551
   -0.4069
   -0.3807
   -0.3347
   -0.3512
   -0.3180
   -0.8291
   -0.7202
   -0.5020
    0.1250
   -0.0141
    0.0628
   -0.1551
    0.2211
    0.2363
    0.1585
    0.1450
    0.2387
    0.2360
    0.1590
    0.4279
    0.3582
    0.5718
    0.5606
    0.6549
    0.6370
    0.4914
    0.5626
    0.4162
    0.4844
    0.3744
    0.2757
    0.2870
    0.0700
    0.1728
    0.1208
    0.2915
    0.1573
    0.0115
    0.0417
    0.1508
   -0.0295
   -0.0418
   -0.0973
    0.0187
   -0.2198
   -0.1375
   -0.1966
   -0.1350
   -0.1431
    0.3301
    0.5742
    0.4036
    0.2187
    0.3555
    0.2794
    0.3918
    0.3747
    0.4528
    0.4688
    0.4248
    0.3225
    0.6267
    0.1959
    0.1700
    0.3745
    0.3708
    0.3530
    0.3271
    0.0849
    0.1610
    0.2170
    0.0304
    0.3133
    0.0956
    0.0871
   -0.0735
    0.0496
   -0.0564
   -0.0361
    0.0938
    0.0518
   -0.1462
   -0.6120
   -0.3321
   -0.2617
   -0.3187
    0.0405
    0.0438
   -0.2559
    0.2186
   -0.0834
    0.3523
    0.2136
    0.4076
    0.2963
    0.5153
    0.4901
    0.3855
    0.5180
    0.4889

and:

   -0.0268
   -0.0662
   -0.0602
   -0.0847
   -0.2213
   -0.2482
   -0.3227
   -0.3156
   -0.3219
   -0.4480
   -0.5627
   -0.6124
   -0.6395
   -0.6753
   -0.7778
   -0.7565
   -0.7962
   -0.8198
   -0.8138
   -0.8659
   -0.8218
   -0.6378
   -0.6112
   -0.3874
   -0.3333
   -0.1998
   -0.1578
   -0.0941
   -0.0246
    0.0454
    0.0755
    0.1197
    0.0375
    0.1270
    0.1332
    0.2221
    0.2039
    0.2902
    0.3242
    0.3550
    0.5231
    0.7548
    0.6308
    0.6958
    0.6060
    0.5869
    0.5351
    0.5484
    0.5831
    0.5749
    0.5249
    0.5505
    0.4376
    0.3578
    0.2832
    0.2192
    0.1146
    0.0597
    0.0534
   -0.0064
   -0.0509
   -0.1083
   -0.0115
    0.1088
    0.0970
    0.1489
    0.1807
    0.2068
    0.1813
    0.1937
    0.2286
    0.2286
    0.2741
    0.2566
    0.2194
    0.1309
   -0.0040
   -0.0271
   -0.0218
   -0.0543
   -0.1150
   -0.0961
   -0.1063
   -0.1751
   -0.1453
   -0.1529
   -0.2054
   -0.2896
   -0.3319
   -0.3759
   -0.5006
   -0.5188
   -0.5316
   -0.5122
   -0.5092
   -0.3820
   -0.2980
   -0.3590
   -0.3223
   -0.3224
   -0.3773
   -0.3245
   -0.2942
   -0.2880
   -0.2500
   -0.2625
   -0.1002
   -0.0292
   -0.1092
   -0.0669
   -0.1300
    0.0205
    0.1430
    0.2139
    0.2185
    0.2708
    0.2591
    0.2736
    0.2492
    0.2958
    0.3231
    0.3251
    0.3385
    0.2935
    0.2796
    0.2668
    0.2052
    0.1949
    0.2167
    0.1533
    0.3012
    0.3617
    0.4280
    0.4936
    0.5856
    0.6342
    0.6096
    0.5463
    0.5367
    0.4539
    0.4183
    0.3855
    0.2880
    0.2231
    0.2155
    0.1680
    0.1426
    0.1122
    0.2541
    0.2347
    0.1727
    0.1168
    0.1395
    0.0078
   -0.0041
   -0.1813
   -0.3335
   -0.4413
   -0.3603
   -0.4008
   -0.4218
   -0.4472
   -0.4956
   -0.4873
   -0.4626
   -0.4051
   -0.3918
   -0.3656
   -0.3405
   -0.2976
   -0.3122
   -0.3131
   -0.2851
   -0.2484
   -0.2280
   -0.2167
   -0.2371
   -0.2526
   -0.1016
   -0.1038
   -0.0833
    0.0442
    0.1048
    0.1265
    0.1926
    0.1771
    0.2037
    0.2684
    0.2614
    0.3449
    0.3014
    0.2131
    0.2344
    0.2284
    0.2151
    0.1868
    0.1221
    0.0809
    0.0961
    0.1030
    0.1082
    0.1207
    0.1535
    0.1938
    0.1489
    0.0910
    0.0706
    0.1558
    0.1558
    0.2816
    0.3306
    0.3702
    0.3822
    0.3829
    0.4324
    0.3734
    0.3448
    0.3454
    0.3462
    0.3577
    0.3653
    0.3768
    0.2040
    0.0633
   -0.0221
   -0.1069
   -0.1611
   -0.2210
   -0.2466
   -0.2142
   -0.2347
   -0.2457
   -0.3381
   -0.5021
   -0.5065
   -0.3966
   -0.4315
   -0.4168
   -0.4681
   -0.4982
   -0.4138
   -0.4362
   -0.2818
   -0.3443
   -0.2742
   -0.3065
   -0.3255
   -0.3261
   -0.3326
   -0.3268
   -0.4980
   -0.5957
   -0.5933
   -0.3700
   -0.2374
   -0.1086
   -0.0872
    0.0515
    0.1593
    0.2087
    0.2329
    0.2751
    0.2993
    0.2844
    0.3584
    0.3879
    0.4785
    0.5406
    0.6151
    0.6605
    0.6387
    0.6388
    0.5833
    0.5589
    0.5000
    0.4188
    0.3596
    0.2412
    0.1871
    0.1327
    0.1549
    0.1326
    0.0696
    0.0347
    0.0497
    0.0046
   -0.0317
   -0.0752
   -0.0654
   -0.1352
   -0.1585
   -0.1927
   -0.1942
   -0.1939
   -0.0276
    0.1899
    0.3003
    0.3163
    0.3672
    0.3736
    0.4100
    0.4267
    0.4610
    0.4884
    0.4900
    0.4514
    0.5218
    0.4271
    0.3402
    0.3418
    0.3438
    0.3409
    0.3309
    0.2409
    0.1972
    0.1853
    0.1156
    0.1612
    0.1267
    0.0991
    0.0249
    0.0117
   -0.0307
   -0.0533
   -0.0223
   -0.0085
   -0.0633
   -0.2651
   -0.3250
   -0.3407
   -0.3652
   -0.2546
   -0.1607
   -0.1880
   -0.0476
   -0.0409
    0.1103
    0.1784
    0.2922
    0.3365
    0.4381
    0.5014
    0.5063
    0.5467
    0.5613

Thanks in advance!

È stato utile?

Soluzione

You can display the data in a way that makes the effect of the filter more clear.

Try the following alternatives:

Nt = length(signal1); % same as for signal2
Nf=2^nextpow2(Nt);
f = [0:Nf/2]/Nf;
spec1 = fft(signal1,Nf);
spec2 = fft(signal2,Nf);

(1) log/abs combination:

figure
semilogy(f,abs(spec1(1:Nf/2+1)))
hold on
semilogy(f,abs(spec2(1:Nf/2+1)),'g')
axis tight

(2) ratio:

figure
plot(f,abs(spec2(1:Nf/2+1))./abs(spec1(1:Nf/2+1)))
axis tight

Results are shown in the plots below:

enter image description here

Note that the signals with periodicity 75 and 5 time units should show up at ~0.013 and 0.2 frequency units, respectively.

Altri suggerimenti

If you have MATLAB's Signal Processing Toolbox, or if you're using the free MATLAB clone Octave, you can save yourself a lot of grief and use the periodogram function - this takes care of all the nasty details of using an FFT to produce a power spectrum (windowing, FFT, magnitude calculation, etc) - it will even do the plotting for you.

The typical function for calculating spectra is pwelch from the signal processing toolbox. Typical usage is:

[PSD_x, F] = pwelch(x, hann(nfft), nfft/2, nfft, fsample);
loglog(F, PSD_x)

This gives you a statistically correct estimate of the real PSD, which a standard FFT does not give you. It works by dividing your data x into several windows of length nfft, applies a proper window function and then calculates the average of the FFTs of all the windows, with proper scaling. Since these windows are usually close to zero at their ends, you typically use half-overlapping windows (this is the third argument nfft/2) so that all data is used more or less equally. The units in output are amplitude squared per hertz, so if x is a voltage, the units are V^2/Hz. In some fields it is more common to plot the linear spectral density, which simply the square root of the PSD, which in this case would be in V/sqrt(Hz).

Choosing the right value of nfft is bit of an art, but this can be understood using the following equations: If the number of averages is navg, the total time of your data is t_total = t_window * (navg + 1) / 2 ~= navg * t_window / 2, where t_window is the time of a single fourier window, and nfft = t_window * fsample. The obtained frequency resolution df is simply the inverse of the window length: df = 1 / t_window.

Using these equations, you can find relations between 3 important properties: the number of averages navg, which you typically want to be between 10 and 50 or so, the frequency resolution df, which should follow from the typical frequencies of your problem, and t_total, which determines the total amount of data that you either have available or that you should measure. If you know 2 out of these 3 properties, the third one follows.

These images show the FFT-computed spectra of the raw signal and the Kalman filtered signal. Since the OP didn't give a sampling rate, the FFTs were done with an arbitrary sampling rate of 5486 Hz.

There's a prominent peak at 75 Hz in both signals (although the actual frequency of these peaks depends on the sampling rate), and a lower noise floor on the Kalman filtered signal, as expected.

FFT spectrum of raw signal - linear amplitude FFT spectrum of Kalman filtered signal - linear amplitude

The decibel graphs below show similar features.

FFT spectrum of raw signal - log amplitude FFT spectrum of Kalman filtered signal - log amplitude

FFT calculations and graphs done with Sooeet.com FFT

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top