FFT example Syntax what does it means P1(2:end-1) = 2*P1(2:end-1); ?

137 ビュー (過去 30 日間)
Andrea Ciufo
Andrea Ciufo 2017 年 2 月 23 日
コメント済み: John D'Errico 2022 年 3 月 2 日
In the Matlab example for the FFT they describe how to plot the FFT.
"Compute the Fourier transform of the signal.
Y = fft(X);
Compute the two-sided spectrum P2. Then compute the single-sided spectrum P1 based on P2 and the even-valued signal length L.
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
Why P1(2:end-1)= 2*P1(2:end-1)? What does it means (2:end-1)? I tried to deduce creating other example with some matrix, but i don't understand Why (1:L/2+1)?
_ Define the frequency domain f and plot the single-sided amplitude spectrum P1. The amplitudes are not exactly at 0.7 and 1, as expected, because of the added noise. On average, longer signals produce better frequency approximations. _
f = Fs*(0:(L/2))/L;
plot(f,P1)
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
This is my first time I approach to the FFT, and I have a civil engineer background, so is my first time with signal analysis, never studied Signal Theory before.
My interest for the FFT is to define the best low pass filter (example apply a butterworth but I don’t know how to choose the filter order and cutoff frequency.
Thanks in advance :)
  2 件のコメント
Aniket Agrawal
Aniket Agrawal 2021 年 5 月 18 日
I also have same doubt pls answer if u got this.

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

回答 (3 件)

Jonas
Jonas 2021 年 5 月 18 日
編集済み: Jonas 2021 年 5 月 18 日
P1(2:end-1)= 2*P1(2:end-1)
means that all values of the spectrum get doubled because of the conversion from two sided spectrum (which is symmetrical and has half signal frequency amplitude at positive and negative frequency) to one sided spectrum, which adds the spectrum amplitude of negative frequencies to the amplitude of the positive frequencies. the first value is not doubled, because it is the DC value (the mean of the signal, frequency 0Hz) which occurs only once in the spectrum and has already the true amplitude. the last spectrum frequency (index end) is also not doubled because it occurs also only once in the spectrum
e.g. the spectrum's x axis for the fft output is [0 1 2 -3 -2 1] Hz and we want a full one sided spectrum and we catch the amplitudes with index 1 to 4 (which is (1:L/2+1) by the way) which are the amplitudes of frequencies 0 1 2 -3. first and last frequency occur only once so we dont double them. want the tutorial does not say is that the default output of fft does not have the 0 frequency in the center like we want to see that for a two sided spectrum, the desired view is achieved with a fftshift(), which circularily shifts the frequency by half the entries, which results into the order of [-3 -2 -1 0 1 2], but since you would then have to find the index of frequency zero and double the right half of the values and matlab wants to avoid unnecessary steps and does not want to shift and truncate the left half afterwards. so the tutorial is fast but too fast to understand that correctly
the decision which filter you should choose depends fully on your signal and what frequencies are interesting at the end
  4 件のコメント
Jonas
Jonas 2021 年 5 月 20 日
no, you don't need to subtract 3 dB afterwards. is there a reason why you think that is necessary? it's ok to calculate the dB from the doubled spectrum because the two sided spectrum shows only half the amplitude at the frequencies (e.g. two sided spectrum of a 5Hz sine with amplitude 1 will give you anplitude 0.5 at -5 and +5 Hz, by doubling it and using only one side you then get amplitude 1 at +5Hz which is the correct amplitude)

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


Waldemiro Kubucama
Waldemiro Kubucama 2021 年 12 月 14 日
Means that it initializes from column 2 to the second-to-last column (end-1)

Nidhi Singh
Nidhi Singh 2022 年 3 月 2 日
編集済み: Nidhi Singh 2022 年 3 月 2 日
How can I substrate that 0 Hz dc value it shows a very high amplitude. Actually I tried to substrate the mean of the signal from orginal one and than did fft. But didn't get appropriate results.
  1 件のコメント
John D'Errico
John D'Errico 2022 年 3 月 2 日
Please don't ask a question as an answer to another question. And this has nothing to do with the original question.

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

Community Treasure Hunt

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

Start Hunting!

Translated by