Hi. Could you give me some advice on how to import some txt data in MAtlab and perform FFT on the data?
3 ビュー (過去 30 日間)
古いコメントを表示
I have a table of data exported from MSC Adams, where the first column is made of times and the second column is made of values of transfer function in time domain at the corresponding time in the corresponding row.
" MODEL_1"
"Time " "FDT "
0.000000e+00 2.918822e+01
4.460465e-02 2.952445e+01
1.000000e-01 2.976704e+01
2.000000e-01 2.982938e+01
2.590536e-01 2.988694e+01
3.000000e-01 2.996875e+01
4.000000e-01 2.994583e+01
4.704487e-01 2.983204e+01
5.000000e-01 2.934951e+01
6.000000e-01 2.964530e+01
6.634901e-01 2.973104e+01
7.000000e-01 2.951014e+01
7.328785e-01 2.983790e+01
8.000000e-01 2.992458e+01
9.000000e-01 3.001759e+01
9.375308e-01 2.983417e+01
9.968824e-01 2.973568e+01
1.000000e+00 2.969204e+01
1.096917e+00 2.974050e+01
1.100000e+00 2.974179e+01
1.200000e+00 2.924196e+01
1.300000e+00 2.975878e+01
1.357244e+00 2.995943e+01
1.389154e+00 2.979626e+01
1.400000e+00 2.994488e+01
1.500000e+00 2.987601e+01
1.525189e+00 2.994929e+01
1.600000e+00 2.993304e+01
1.700000e+00 2.929264e+01
1.800000e+00 2.962498e+01
1.883121e+00 2.948703e+01
1.900000e+00 2.971055e+01
1.974141e+00 3.000537e+01
2.000000e+00 2.987244e+01
2.050593e+00 3.003002e+01
2.100000e+00 3.003315e+01
2.126852e+00 2.982030e+01
2.200000e+00 2.956299e+01
2.264333e+00 2.935844e+01
2.300000e+00 2.968497e+01
2.400000e+00 2.943462e+01
2.500000e+00 2.972935e+01
2.600000e+00 3.001699e+01
2.700000e+00 2.977874e+01
2.727725e+00 2.998265e+01
2.800000e+00 2.986634e+01
2.825530e+00 2.944201e+01
2.900000e+00 2.935445e+01
2.928584e+00 2.964895e+01
3.000000e+00 2.956931e+01
3.100000e+00 2.988075e+01
3.126939e+00 2.984458e+01
3.170451e+00 3.003163e+01
3.200000e+00 2.982598e+01
3.225748e+00 3.000402e+01
3.300000e+00 3.001243e+01
3.400000e+00 2.952440e+01
3.500000e+00 2.956726e+01
3.525302e+00 2.930500e+01
3.600000e+00 2.964499e+01
3.635287e+00 2.956201e+01
3.700000e+00 2.970561e+01
3.800000e+00 3.004416e+01
3.850949e+00 2.994689e+01
3.894347e+00 2.972264e+01
3.900000e+00 2.972237e+01
4.000000e+00 2.974802e+01
4.053587e+00 2.976616e+01
4.100000e+00 2.949139e+01
4.200000e+00 2.950337e+01
4.300000e+00 2.996706e+01
4.400000e+00 2.979852e+01
4.500000e+00 2.994891e+01
4.600000e+00 2.956984e+01
4.645289e+00 2.937391e+01
4.679644e+00 2.964808e+01
4.700000e+00 2.933518e+01
4.754876e+00 2.958101e+01
4.782554e+00 2.937809e+01
4.800000e+00 2.975573e+01
4.900000e+00 2.976671e+01
4.986240e+00 3.005392e+01
5.000000e+00 3.007472e+01
I'd like to have the frequency domain transfer function by performing FFT in Matlab. I tried to get a vector from the txt values, in order to perform the FFT. I am not able to get a vector from the txt file. Even if i manage to get the vector, as you can see, the data is not sampled at equally spaced times. Is there a way to perform FFT in Matlab anyway?
Thank you for your consideration.
0 件のコメント
採用された回答
John D'Errico
2018 年 5 月 24 日
Read this to learn to format code. Then apply it to your data, so it will appear as you want it.
As far as reading it into MATLAB, just use textread. Or edit the file, and delete the first few non-numeric lines if that seems too difficult. Then you can just use load on the modified version.
Sorry though, you cannot apply fft to scattered samples. That does not mean you cannot compute a Fourier transform, merely that fft does not serve the purpose. Instead, you could do some reading, here for example:
The point is, you can learn to use linear algebra to compute a Fourier transform. Or you can interpolate the data to be uniformly spaced, then use fft. So you might use interp1 with the spline method.
0 件のコメント
その他の回答 (1 件)
Vilnis Liepins
2018 年 5 月 25 日
編集済み: Vilnis Liepins
2018 年 5 月 28 日
Hi Angelo,
If the above recommendations do not help you to get the DFT of your data then you could explore one more option - applying the function 'nedft' available on fileexchange:
For this code you need to select number of DFT frequencies, estimate the upper frequency in your data and generate the frequency vector covering all the frequencies in range, including negative frequencies. The code example for data 'model_1' size (83x2) could be:
N=2000; %The lenght of DFT
NF=40; %The Nyquist rate (Hz), Assumption that the data is bounded by upper frequency NF/2
fr=NF*[-ceil((N-1)/2):floor((N-1)/2)].'/N; % Cover uniformly the frequency range ]-NF/2,NF/2] Hz
[dft_est,amp_est,it]=nedft(model_1(:,2),model_1(:,1),fr); % Calculate DFT of data in 'model_1' by applying function 'nedft'
semilogy(fr,abs(amp_est)) % Plot amplitude estimate in the log scale as the data has a large peak on 0 frequency
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/188785/image.png)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Fourier Analysis and Filtering についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!