Import Text Data and Plot FFT

Hi, I'm very new to MatLab and don't know too much. I need to take a series of data from a text file and plot the Fourier Transform. The sample rate is 100samples/second or deltaT = 0.01. Thank you for your help.

回答 (3 件)

Image Analyst
Image Analyst 2016 年 10 月 16 日

0 投票

Attach your text data file. Otherwise, try csvread(), dlmread(), importdata(), load(), textscan(), readtable(), or similar routines.

4 件のコメント

TheNewGuy
TheNewGuy 2016 年 10 月 16 日
Here's the text file
Image Analyst
Image Analyst 2016 年 10 月 16 日
OK, fine. But what did you try? Did you try this:
data = importdata('p1.txt');
spectrum = fft(data);
??? I'm assuming you did because I told you to already. So, what question do you still have? You forgot to tell us.
Image Analyst
Image Analyst 2016 年 10 月 16 日
Here is some more complete code:
data = importdata('p1.txt')
spectrum = fft(data);
deltaT = 0.01;
numElements = length(spectrum)
indexOf0 = numElements / 2
shiftedSpectrum = fftshift(abs(spectrum));
f = (1 / deltaT) * linspace(-numElements/2, numElements/2, numElements);
plot(f, shiftedSpectrum, 'b.-', 'LineWidth', 2, 'MarkerSize', 16);
grid on;
title('Spectrum of Data', 'FontSize', fontSize);
xlabel('Frequency', 'FontSize', fontSize);
ylabel('Power', 'FontSize', fontSize);
% Make bolder y axis
line([indexOf0, indexOf0], ylim, 'Color', 'k', 'LineWidth', 3);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
TheNewGuy
TheNewGuy 2016 年 10 月 16 日
Sorry, I just wasn't sure overall how to make the FFT using the text file. I had tried the import function, but my plot was blank. Your code helps, thank you.

サインインしてコメントする。

dang khoa tran
dang khoa tran 2019 年 12 月 17 日

0 投票

Hello, so do you have any idea to do inverse FFT using the text file?
Thank you

1 件のコメント

Image Analyst
Image Analyst 2019 年 12 月 17 日
Use ifft and ifftshift.

サインインしてコメントする。

dang khoa tran
dang khoa tran 2019 年 12 月 18 日

0 投票

Thank you for your reply. But then I do this, it still shows the same result as that when doing with "fft and fftshift"
My case is : There is a variation of electric filed amplitude along the propagation distance. And I want to transform this into the variation along the time domain so that I can get the "pulse duration". So do you have any idea?
Below is the attactment of the text file.

カテゴリ

ヘルプ センター および File ExchangeFourier Analysis and Filtering についてさらに検索

質問済み:

2016 年 10 月 16 日

回答済み:

2019 年 12 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by