matlabfilterfftlowpass-filter

From time domaine to frequency domain


I have a problem in my MATLAB program. I'm trying to find a cutoff frequency to create a low pass filter for compass data. I'm trying to go from the time domain to the frequency domain and find an Fc, so I used the FFT but it seems that's it's nor working.

This is what i have done:

dataset=xlsread('data.xlsx','Feuil1','A1:A751');
t=1:length(dataset);
z=abs(fft(dataset));
subplot(2,2,3)
plot(dataset)
title('dataNonFiltrer')
subplot(2,2,4)
plot(z)
title('frequenciel')

And i get this wish seems to be not correct:

enter image description here


Solution

  • You are just not plotting the data right.

    To plot the fft of a signal X, do (from the docs):

    Fs = 1000;   % Sampling frequency of your data. YOU NEED TO KNOW THIS, change             
    
    L = length(X);             % Length of signal
    Y = fft(X);
    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) 
    title('frequenciel X(t)')
    xlabel('f (Hz)')
    ylabel('|P1(f)|')