What is the x-axis in fft() command?

55 ビュー (過去 30 日間)
Jaya Sodhani
Jaya Sodhani 2022 年 6 月 21 日
編集済み: Star Strider 2022 年 6 月 21 日
y=audioread('speech.wav');
subplot(2,3,1);
plot(y);
xlabel('Samples');
ylabel('Magnitude');
title('Speech signal');
%Taking FFT
fft_sig=fft(y,256);
abs_val=abs(fft_sig);
subplot(2,3,2);
plot(abs_val);
When I give the command plot(abs_val), what will the x-axis of my graph represent according to my code?

採用された回答

Star Strider
Star Strider 2022 年 6 月 21 日
編集済み: Star Strider 2022 年 6 月 21 日
The x-axis will be frequency, that being defined as cycles/(time unit of the original independent varialble). If that is in seconds, the frequency will be in Hz.
The best way to do that is:
[y,Fs] = audioread('speech.wav'); % Return Sampling Frequency As The Second Output
L = size(y,1);
Fn = Fs/2; % Nyquist Frequency
tv = linspace(0, L-1, L)/Fs; % Time Vector
One way to compute the frequency vector:
Fv = linspace(0, 1, fix(length(fft)/2)+1)*Fn; % One-Sided 'fft'
Iv = 1:numel(Fv); % Index Vector
The fft result to be plotted would then use ‘Fv’ and ‘Iv’ to create an equal-length fft vector.
Use the fftshift function to create a two-sided fft result, then:
Fv = linspace(-Fs/2, Fs/2-Fs/length(s), length(s)); % Two-Sided 'fft': EVEN 'length(s)' (Asymmetric)
Fv = linspace(-Fs/2, Fs/2, length(s)); % Two-Sided 'fft': ODD 'length(s)' (Symmetric)
.

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by