How can I get proper length of FFT

19 Ansichten (letzte 30 Tage)
Byeongoh Min
Byeongoh Min am 13 Dez. 2018
Bearbeitet: 昊 王 am 8 Dez. 2020
I'm trying to transforming an already know signal from time domain to frequency domain using fftfunction in MATLAB.
And I got different values of amplitude whenever I change the value(nfft) of length of signal.
I'm therefore wondering if there is a rule to choose the length of signal when calculating FFT.
From I understand the amplitude of signal should be same when it is on the time domain and frequency doamin.
am I wrong?
I have an acoustic signal got from a sensor and need to analyze it particularly SPL
I want to transform it into frequency domain using fftfunction in MATLAB. And I don't know how can I choose the length of signal.
Could somebody please help?
This is my code below
[y,Fs] = audioread('AA.wav')
%% Implementation FFT
t=linspace(0,length(y)/Fs,length(y));
nfft=512;
f=linspace(0,Fs,nfft);
g=abs(fft(y,nfft));
F2=f(1:nfft/2)
G2=g(1:nfft/2)
%% ploting FFT
figure(1)
plot(F2,G2)
xlabel('Frequency')
ylabel('Amplitude')
legend('FFT for SPL');
  4 Kommentare
Byeongoh Min
Byeongoh Min am 13 Dez. 2018
y is very huge as compare to nfft almost 800,000
Star Strider
Star Strider am 13 Dez. 2018
From the documentation, the input can be:
  • Data Types: double | single | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical
The output will then be:
  • If X is of type single, then fft natively computes in single precision, and Y is also of type single. Otherwise, Y is returned as type double.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Star Strider
Star Strider am 13 Dez. 2018
To have the correct amplitudes, scale the fft by dividing it by the length of the original signal. The ‘nfft’ argument (usually greater than the length of the original signal) will increase the frequency resolution, so some of the amplitudes may be slightly different. If you use a one-sided fft, multiply the resulting amplitudes by 2.
x = your_signal;
t = your_time_vector;
Fs = 1/mean(diff(t)); % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
N = length(x);
NFFT = 2^nextpow2(N);
FTx = fft(x, NFFT) / N;
Fv = linepace(0, 1, fix(N/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(FTx(Iv))*2)
grid
  1 Kommentar
昊 王
昊 王 am 8 Dez. 2020
Bearbeitet: 昊 王 am 8 Dez. 2020
> From I understand the amplitude of signal should be same when it is on the time domain and frequency doamin
I also think so, So can you explain why this sentence doesn't apply here?
Not from the perspective of matlab code, but the perspective of signal and system.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Measurements and Spatial Audio finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by