1
$\begingroup$

Let me ask about FFT, i have data sample from sensor, source of frequency from generator is 5 Hz, i want to extract the data with FFT but why i cannot find the 5 Hz frequency from source. This is my list program

Fs = 5;               %sampling frequency 
T = 1; 
L = 250;              % Length of signal 
t = (0:L-1)*T; 
time = VarName1;       % sampling time 
signal = VarName2;     % signal data in Time-Domain  

figure(1);
plot(signal);
title('Sensor Signal')

Y = fft(signal);

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;
figure(2);
plot(f,P1); 
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')

data sensor sample

signal sensor and result FFT

please your help for solve the problem, thank you very much,

1.6, 1.4, 1.8, 1.8, 1.4, 1.6, 1.4, 1.2, 2, 1.6, 1.8, 1.8, 1.4, 1.2, 1.8, 1.2, 2.2, 2, 1.4, 1.4, 1.4, 1.4, 1.8, 1.8, 1.6, 1.8, 1.4, 1.2, 1.6, 1.2, 1.8, 1.6, 1.2, 1.4, 1.2, 1, 1.6, 1.4, 1.4, 1.2, 0.8, 0.6, 1.2, 0.2, 1, 1, 0.4, 0.2, 0.2, 0, 0.4, 0, 0, 0, -0.4, -0.6, -0.2, -0.2, 0, -0.2, -0.6, -0.8, -0.6, -0.6, -0.2, -0.4, -0.4, -0.2, -1.4, -1, -0.4, -0.6, -0.2, -0.2, -0.8, -0.8, -0.4, -0.6, -0.2, 0, -0.4, 0, -0.4, -0.2, 0, 0.2, 0.6, 0.4, -0.2, 0.4, 0, 0.4, 0.4, 1, 0.6, 1.2, 0.6, 1, 1.4, 1.2, 1.4, 1.8, 1.2, 1.4, 1.4, 1.6, 2, 1.8, 1.6, 1.6, 1.4, 1.8, 1.8, 1.8, 2.2, 2.2, 1.4, 1.6, 1.6, 1.4, 2, 1.8, 1.4, 1.6, 1.2, 1.4, 1.4, 1.6, 1.6, 1.6, 1, 1, 1.2, 0.4, 1.2, 0.8, 0.6, 0.8, 0.4, 0.2, 0.6, 0.2, 0.4, 0.2, -0.2, -0.4, -0.2, -0.6, 0, -0.4, -1, -1.2, -1, -1.2, -0.6, -1, -1, -1.2, -1.6, -1.4, -1.4, -1.4, -1, -1.4, -1.8, -1.4, -1.6, -1.8, -1.4, -1.2, -1.4, -1.2, -1.4, -1.2, -1.4, -1, -0.8, -0.6, -1, -0.8, -1, -0.2, -0.2, 0, 0, 0.2, -0.2, 0, 0.2, 0.6, 0.6, 1.2, 0.4, 1, 0.6, 1.2, 1.4, 1.4, 1.4, 2, 1.2, 1.6, 1.6, 1.8, 2.2, 2.4, 2, 2.4, 2, 2, 2.6, 2, 2.6, 2.8, 2.2, 2.4, 2.4, 2, 3, 2.6, 2.4, 2.4, 2.2, 2.2, 2.6, 2.6, 2, 2, 2.2, 1.8, 2, 2, 2, 1.8, 1.6, 1.6, 1.6, 1.2, 1.6, 1.4, 1.4, 1, 1.4, 1, 1.2, 1.2, 0.6, 0.2, 0.2, 0.2, 0.8, 0.4, 0.6, 0.2, 0.2, -0.6,

Regards Ridwan

$\endgroup$

2 Answers 2

2
$\begingroup$

If your sampling frequency is 5Hz (Which I don't think is!) and the signal contains a known frequency of 5Hz. So, the sampled signal will have aliasing for sure.

You are correctly mapping your positive FFT spectrum from 0 to 2.5Hz, because digital frequency of sampled signal can only map from $[-f_s/2, f_s/2]$ which is $[-2.5hz, 2.5hz]$.

The question is where do you want to see your 5 Hz in this. You can only see a high DC which is actually the negative folded image of the 5Hz tone at $f_s$. And, you can actually see a peak very close to DC.

Based on the Plots you have shown :

The plot of time domain data and assuming you have injected a 5Hz tone, I think the sampling frequency is close to 500Hz and not 5Hz. Simply, because you have ~2.5 cycles of 5Hz sinusoidal in 250 samples. 5Hz sinusoidal wave will take 1 second for 5 cycles, hence ~2.5 cycles of such wave will take 0.5 second. 250 samples/0.5 second means 500 samples/second. Hence, your sampling frequency is 500 Hz.

And, if you are taking 250 length FFT, frequency resolution will be of : $$\frac{2\pi}{250} = \frac{2}{250}.\frac{f_s}{2} = 2Hz$$ Hence, your 5Hz tone will be seen as a peak between $2^{nd}$ and $3^{rd}$ coefficient of the 250-Point DFT, which you are able to see.

MATLAB Simulation showing your situation:

fd = 5;             % data tone of 0.25Hz   
fs = 500;           % sampling frequency of 5Hz
Ts = 1/fs;
n_samps = 250;      % Number of samples
time = n_samps/fs;  % duration of data collection (0.5 secs)
n = linspace(0,time-Ts,n_samps); % sample points in the duration [0sec, 0.5sec)

% Carrier Frequency fc = 5Hz + a slow linear ramp as it seems from the
% time-domain plot you have attached.
signal = (n/250 + sin(2*pi*fd*n));

% AWGN Noise added 
signal = awgn(signal, 15);
figure(1)
plot(signal)

Y = fft(signal);
figure(2)
plot(5/n_samps * (0:1:n_samps/2-1), (abs(Y(1:length(Y)/2))));

MATLAB Plot

The other small peaks are most probably being generated due the harmonics which are present as a consequence of clipping in sampled data due to fixed bit-width ADC. If you lower your amplitude a little to accommodate your sinusoidal wave within the dynamic range of ADC, these small peaks might go away.

Adding analysis of the time-domain samples you have pasted :

Assumption : Sampling Frequency = 500Hz

I have plotted FFT of the samples centered around 0 Hz(DC). And, based on number of samples (256) and assumed $f_s = 500Hz$, frequency spacing between 2 FFT samples is $\frac{f_s}{n_samps} = \frac{500}{256} = 1.9531$. Since 5Hz is not an integral multiple of this spacing, therefore, you will see the tone energy spread around into 1.9531*2Hz and 1.9531*3Hz i.e. 2nd and 3rd FFT coefficient.

You are also seeing a strong peak at DC (0Hz) because your sinusoid of 5Hz is having an amplitude shift of a non-zero value.

You can see that your tone is not missing at all. It is present right where is should be.

MATLAB Code to plot the signal and it's DFT with correct $f_spacing$ is as follows:

plot(500/256*(-128:127), abs(fftshift(fft(x))))

toneTime

toneFFT

$\endgroup$
13
  • $\begingroup$ thank you for your answe, but for the time of sample, in my data result 0, but time base is 1.34 s, how corelation with fft? $\endgroup$
    – Ridwan
    Apr 8, 2020 at 6:10
  • 1
    $\begingroup$ @Ridwan I could not understand your question. Are you saying that the duration of data collection was 1.34 sec or the time of starting data collection is 1.34 sec ? Can you please elaborate? $\endgroup$
    – DSP Rookie
    Apr 8, 2020 at 6:15
  • $\begingroup$ in my picture data collected from osiloscope, for column time (column 1), values is 0, but there are information about time base, what the meaning? $\endgroup$
    – Ridwan
    Apr 8, 2020 at 6:44
  • 1
    $\begingroup$ You can go through the article here to understand time-base. electronicsclub.info/cro.htm $\endgroup$
    – DSP Rookie
    Apr 8, 2020 at 8:25
  • 1
    $\begingroup$ @Ridwan Can you please upvote/accept the answer if it answered your doubt or if it was helpful? Thanks 😊. $\endgroup$
    – DSP Rookie
    Apr 10, 2020 at 17:21
0
$\begingroup$

Your FFT appears to be for a sampling frequency of 5 Hz. I estimate from your time domain data, if what we see there is a 5 Hz sinusoid, that your sampling frequency $F_s$ is actually closer to 500 Hz given by 1 cycle = 100 samples, so 100 samples/cycle * 5 cycles/sec = 500 samples/sec.

Given the length of 250 samples with no further windowing, the frequency resolution of your DFT would be 2 Hz (500 Hz/ 250 samples).

$\endgroup$
1
  • $\begingroup$ thank you for your answer $\endgroup$
    – Ridwan
    Apr 8, 2020 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.