0
$\begingroup$

I sampled a 50Hz sine wave (its not perfectly a sine wave, it's a data coming from current sensor using Arduino).

Using real time graphing technique by sending the data from Arduino to the PC I managed to reconstruct the signal as attached here enter image description here

The second experiment I logged my data into an SD card, my sampling rate was 5000 and when I tried to reconstruct the signal in MATLAB, I got this graph which doesn't construct the original signal back, but rather its strange as bellow:

enter image description here

Notice the maximum values for the both graphs.

Why the signal is not correctly reconstructed? I sampled it at 5000 Hz which is almost 10 times the original signal frequency and it meets Nyquist criteria ... And as a result of wrongly constructed signal the FFT is indicating the frequency of zero not 50 Hz.

The MATLAB code

filename = 'C:\Users\Sabir\Desktop\internship Sri Wawasan\testFFT.csv';

% thee file

fid = fopen(filename,'rt');
[data]=textscan(fid, ' %f',...%the values of the sensors as cell array 
       'delimiter',',')  ;                        
fclose(fid);

sensorMatrix=cell2mat(data);

% the values of the sensors as matrix

%taking some point from the sensors matrix

y=sensorMatrix(1:3000,1);% array of one chanel 

 plot (y)

L=length(y)

Fs = 5000;                    % Sampling frequency

T = 1/Fs;                     % Sample time              % Length of signal

t = (0:L-1)*T;                % Time vector

plot(Fs*t,y)

and finally here is the FFT, it has 100 Hz and 150 Hz components

enter image description here

$\endgroup$
  • $\begingroup$ Your signal might have a fundamental frequency of 50Hz, but it can also contain higher frequencies (see Fourier series), since you signal has some characteristics of triangle wave it will contain a lot of higher frequencies. $\endgroup$ – fibonatic Mar 25 '15 at 13:16
  • $\begingroup$ Your Matlab graph looks completely fine to me. The x-axis is in samples, which makes a period of about 100 samples, which is correct since your sampling rate is 100 times the main signal frequency. The voltage range is also consistent with the previous plot. Btw., for spectral analysis, don't use fft, use pwelch and friends. $\endgroup$ – A. Donda Mar 25 '15 at 16:43
  • $\begingroup$ @fibonatic I analysed the signal using FFT, and that is correct, it has 100 Hz and 150 Hz (2nd and 3rd harmonics), but the current shape of the wave indicates lower frequency component ~2Hz and one of the reasons maybe is due to the sensor I am using, it may have some noise. If you by any chance interested here is a discussion about the issue sensors point of view openenergymonitor.org/emon/node/10382#comment-29040 $\endgroup$ – Sabir Moglad Mar 27 '15 at 1:33
  • $\begingroup$ hey @A. Donda why should I use pwelch and not fft I may post the fft analysis in an answer since I can't post a picture in a comment $\endgroup$ – Sabir Moglad Mar 27 '15 at 1:37
  • $\begingroup$ Sabir, spectral estimation via simple Fourier Transform has many drawbacks, the most obvious can be seen in your plot: Around each peak you have many sidelobes. This method is called the periodogram, and there are several improvements upon the periodogram. See en.wikipedia.org/wiki/Spectral_density_estimation#Techniques and follow the links on the periodogram and Welch's method. $\endgroup$ – A. Donda Mar 27 '15 at 15:53
2
$\begingroup$

You do have zeroth frequency in your signal indeed. If you don't, your signal would be centered around zero volts. Zeroth frequency is a DC component.

If you want to measure the frequency of an AC component, center the signal around zero volts (subtract the mean). By the way, FFT is not a good instrument to measure frequency of an arbitrary signal because it uses a fixed set of harmonics, which may or may not coincide with your signal (and FFT will give you a maximum on a nearest one).

$\endgroup$
  • $\begingroup$ Man you are the best! I know I was missing something : ) thanks buddy everything is fine right now! I couldn't vote up because I don't have enough reputation! $\endgroup$ – Sabir Moglad Mar 25 '15 at 6:34
  • $\begingroup$ No problem, glad I could help. $\endgroup$ – Yuri Nenakhov Mar 25 '15 at 6:37
  • $\begingroup$ @SabirMoglad you posted the question. you don't need reputation. If it was helpful mark this answer as the solution. No reputation required $\endgroup$ – andrew Mar 27 '15 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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