# Why does the fft function cut in half the amplitude of my signal?

9 ビュー (過去 30 日間)
Claudio Gerosa 2024 年 3 月 20 日
コメント済み: Paul 2024 年 3 月 21 日
Hi, I have a question I would like to submit. I'm working on a project for uni in which i have to measure vibrations using an accelerometer. Now what I do is that I process the acquired datas using the fft function, in order to gain information about the frequency and the amplitude of the signal. The problem that I'm facing is that, by looking at the signal you can see that it has an amplitude of approximatively 40 g, but when I plot the Fourier Transform, it shows a maximum amplitude of about 20 g, which is half the amplitude of the original signal. Is there something that I'm missing?
This is the code that I'm using to plot the Fourier Transform:
N=numel(data);
freq=[0:N-1]/N*dq.Rate;
X=2*fft(data)/N;
X(1)=X(1)/2;
Xamp=abs(X);
figure()
plot(freq,Xamp);
Data is the acquired signal, and dq.Rate is the sampling frequency.
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Paul 2024 年 3 月 21 日

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

### 回答 (2 件)

Hassaan 2024 年 3 月 20 日
N = numel(data);
freq = [0:N-1] / N * dq.Rate;
X = fft(data);
% Apply the window correction if you used a window function
% e.g., for a Hann window: window_correction = sum(hann(N))^2;
% X = X / window_correction;
% Doubling the FFT values, except for the DC and Nyquist (if N is even)
X = X / N;
X(2:end-1) = 2 * X(2:end-1);
% If N is even, the last element is the Nyquist frequency and should not be doubled
if mod(N, 2) == 0
X(end) = X(end) / 2;
end
Xamp = abs(X);
figure();
plot(freq, Xamp);
xlabel('Frequency (Hz)');
ylabel('Amplitude (g)');
title('Amplitude Spectrum');
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
• Technical Services and Consulting
• Embedded Systems | Firmware Developement | Simulations
• Electrical and Electronics Engineering
Feel free to contact me.
##### 0 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

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

Chunru 2024 年 3 月 20 日

Note that a sinosoidal signal can be expressed as:
FFT of (normalized by N) will have a peak at f0 with amplitude of 1 (similar for negative freq as well). The half is evident from the above equation.
A = 1; % amplitude
f0 = 1/16; % normalized freq
data = cos(2*pi*f0*(0:127))
data = 1×128
1.0000 0.9239 0.7071 0.3827 0.0000 -0.3827 -0.7071 -0.9239 -1.0000 -0.9239 -0.7071 -0.3827 -0.0000 0.3827 0.7071 0.9239 1.0000 0.9239 0.7071 0.3827 0.0000 -0.3827 -0.7071 -0.9239 -1.0000 -0.9239 -0.7071 -0.3827 -0.0000 0.3827
N=numel(data);
dq.Rate = 1;
freq=[0:N-1]/N*dq.Rate;
X=fft(data)/N;
X(1)=X(1)/2;
Xamp=abs(X);
figure()
plot(freq,Xamp);
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Paul 2024 年 3 月 20 日
The code in the question has a multiplication by 2:
X=2*fft(data)/N;

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

### カテゴリ

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

### Community Treasure Hunt

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

Start Hunting!

Translated by