フィルターのクリア

How to determine and adjust the x axis after taking the 1D FFT?

28 ビュー (過去 30 日間)
L'O.G.
L'O.G. 2022 年 12 月 19 日
回答済み: Paul 2022 年 12 月 19 日
I am trying to take an FFT, but have trouble figuring out the x axis. The time vector is of length N = 100000. The vector has uniformly spaced time points, i.e. dt = t(2)-t(1). How do I find out what the values of f should be? And how can I change the spacing df?

採用された回答

Star Strider
Star Strider 2022 年 12 月 19 日
I usually do something like this —
t = linspace(0, 100, 10000); % Time Vector
s = sum(sin([1 5 10 15 20 25 30 35 40 45].'*2*pi*t)); % Signal (Here A Vector)
figure
plot(t, s)
grid
xlabel('Time')
ylabel('Amplitude')
L = numel(t); % Length Of The Signal Vector
dt = t(2)-t(1); % Sampling Time Increment
Fs = 1/dt; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
NFFT = 2^nextpow2(L); % For Efficiency
FTs = fft(s(:).*hamming(L),NFFT)/L; % Fourier Transform (Windowing Not Required, Shown For Information)
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector For One-Sided Fourier Transform Plot
Iv = 1:numel(Fv); % Index Vector (For Convenience)
figure
plot(Fv, abs(FTs(Iv))*2) % Multiply By 2 To Correct For Energy Division Between Positive And Negative Frequencies
grid
xlabel('Frequency (Units)')
ylabel('Magnitude (Units)')
I am not certain what you are doing, however something like this should work.
.
  4 件のコメント
L'O.G.
L'O.G. 2022 年 12 月 19 日
Thank you so much!
Star Strider
Star Strider 2022 年 12 月 19 日
As always, my pleasure!

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

その他の回答 (1 件)

Paul
Paul 2022 年 12 月 19 日
Hi L'O.G.
Let Y be the output of fft (with or without zero padding)
Let NFFT = numel(Y)
Let Ts = dt = t(2) - t(1) and Fs = 1/Ts.
Then the frequency vector that corresponds to the values in Y is given by
f = (0: (NFFT-1))/NFFT*C
where the proportionality constant C is often one of:
C = 1 % cycle/sample
C = 2*pi % rad/sample
C = Fs % cycle/sec, i.e. Hz
C = 2*pi/Ts % = 2*pi*Fs rad/sec.
If Y is the output of fftshift, then f is
f = (-(NFFT-1)/2 : (NFFT-1)/2)/NFFT*C % N odd
f = ((-NFFT/2) : (NFFT/2-1))/NFFT*C % N even

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by