Pregunta

This is my code:

    T      
    F = 1/T                    
    y
    L = length(y)
    Y=fft(y); 
    f=(0:F:(L-1)*F)
    plot(f, Y)

T is the sampling time (with its value), F is the frequency and y is the discrete signal. Is it the correct way to compute DFT using Matlab? I haven't passed F or T to the function so I'm not sure if the results Y correspond to their respective multiple frequencies of F stored in f.

¿Fue útil?

Solución

F = 1/T
L = length(y)   

t = linspace(0,L/F,L);
NFFT = 2^nextpow2(L);
f = F/2*linspace(0,1,NFFT/2+1);

fft_y = fft(y, NFFT)/L;

magnitude_y = = 2*abs(fft_y(1:NFFT/2+1));

plot(f, magnitude_y);

This is the correct way.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top