how to get fft of a signal?

16 visualizaciones (últimos 30 días)
Laxmi kc
Laxmi kc el 16 de Oct. de 2017
Editada: dpb el 16 de Oct. de 2017
I loaded a signal in Matlab as shown in figure.I was expecting to get harmonics/spikes but got the output as shown in figure.My code is as follows:
a = load('pulsetrain3.txt');
T = a(:,1);
E = a(:,2);
subplot(2,1,1);
plot(T,E);
c = fft(a);
b = abs(c);
subplot(2,1,2);
plot(b);

Respuesta aceptada

dpb
dpb el 16 de Oct. de 2017
Editada: dpb el 16 de Oct. de 2017
c = fft(a);
takes the fft of both columns independently and then when you plot() that you get both plots on the same axis. The dt will be a single spike and much larger magnitude than the spectrum of the signal so that's what is visible in the plot.
Use
Y=fft(E);
instead.
I recommend
doc fft % study example for computing/plotting a one-sided PSD
Apropos may also be the nearly simultaneous question <sampling-frequency-in-fft-analysis>
ADDENDUM
Your data are grossly over-sampled for the actual frequency content it appears...
I built a little routine from the fft example
>> type psdfft
function psd=psdfft(y,Fs)
L=length(y);
NFFT = 2^nextpow2(L);
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
psd=2*abs(Y(1:NFFT/2+1));
plot(f,psd)
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
>>
As other poster notes, you also have a mean that is significant in comparison to the amplitude and there's a very abrupt end to the recorded signal so I used a Hamming window and with those--
>> T=t(end); Fs=1/T;
>> figure
>> psdfft(hamming(length(e)).*detrend(e),Fs);
>> set(gca,'xscale','log','yscale','log')
>>
A couple peaks around 10^4 which given sample rate of 10^11 is many orders of magnitude less, there's mostly just noise elsewhere and it takes log scale both axes to see anything at all...
If I just decimate the input signal, downsampling by 128,
>> es=e(1:128:end);
>> Fse=Fs/128;
>> psdfft(detrend(es),Fse);
the result is
If you downspace the x axes on the above figure you'll see when you get the two axes ranges to overlay that the peaks are in the same place; simply owing to not having all the extra sampling in the signal the resolution is better for the actual significant energy content.
You can do similar thing by averaging the fft of the sampled signal over multiple shorter windows to improve the estimation of the energy actually in the signal.
  1 comentario
dpb
dpb el 16 de Oct. de 2017
Editada: dpb el 16 de Oct. de 2017
[converted OP Answer to comment ... dpb]
I tried using fft(E)but it didnt make any difference. I have attached the txt file can you kindly suggest how I can get desired output?

Iniciar sesión para comentar.

Más respuestas (1)

Honglei Chen
Honglei Chen el 16 de Oct. de 2017
The first figure is your signal, which has a DC component. You may want to remove that before running the FFT, like
c = fft(detrend(E))
HTH

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by