FFT to get noise

12 views (last 30 days)
Felifa
Felifa on 20 Mar 2017
Commented: Adam on 21 Mar 2017
Hello,
Can anybody explain how the fft is done in case of data points? I am meassuring 50Samples per second , with 50Hz for 1 second. Well, I got a Little help from an user, but I do not understand what was done in the code. the code Looks like this:
Fs = 50; %Sampling Frequency
T = 1/Fs;
L = 50; %Signal length
Y = fft(voltage);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
I don't understand why the code Looks like this? It seems, that the fft is done for half of the signal. Can anybody give me an example please how it is done for the whole Signal?

Accepted Answer

Adam
Adam on 20 Mar 2017
The fft is done on the whole signal:
Y = fft( voltage );
but this gives a 2-sided spectrum of positive and negative frequencies. For analysis in the frequency domain people usually just want to look at the positive frequencies in the first half of the result.
doc fft
gives examples. It's always a good idea to read the help!
  1 Comment
Felifa
Felifa on 20 Mar 2017
I've read the description. The Point is that I don't understand what is done in these lines. For example, why is this done: P2= abs(Y/L),? Could you please discribe them for me? For my case the discription is not very unseful, in my Point of view...

Sign in to comment.

More Answers (1)

Felifa
Felifa on 21 Mar 2017
So, I got to an explanation by myself:
Fs = 50; %Sampling Frequency
T = 1/Fs;
L = 50; %Signal length
Y = fft(voltage);
P2 = abs(Y/L); %creates a vector with real- and imaginary part, detects value and Phase and abs creates the spectrum of frequencies
P1 = P2(1:L/2+1); % eliminates the negative part
P1(2:end-1) = 2*P1(2:end-1); %positive and negative part of the spectrum "get together" at 0Hz, so they do not need to be multiplied by 2
f = Fs*(0:(L/2))/L; % frequencyvector, a spectrum is not timereferenced but frequencyreferenced. The frequencyvector is created until the half of the sampling frequency, sampling frequencies above are not representable.
plot(f,P1)
Please correct me if I'm wrong :D
  1 Comment
Adam
Adam on 21 Mar 2017
P2 = abs(Y/L)
is giving you the spectrum. The fft result, Y, is complex as you note, but for analysis in the frequency domain we are rarely interested in the complex signal, we wish to look at the power or magnitude spectrum telling us the relative power at the different frequencies, hence the abs.
The division by L and the doubling of the positive frequency powers is all concerned with getting the scaling correct and retaining the full power of the signal. For purely looking at relative contributions at different frequencies it doesn't matter, but if you are applying a filter and converting back to the time domain or some other kind of quantitative analysis then the correct scaling does matter.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!