I have measurements of time and current which were made with a digital oscilloscope. When I import them in MATLAB and plot them my sinewave is pretty much like my the waveform I saw in the oscilloscope and in the excel file (time domain).
The problem is that, when i try to apply fft to my data, i'm taking this waveform as a result.
I think, that i should see my only harmonic in 50Hz, since there is a 50Hz sinewave taken as an input. Instead I'm taking a nearly zero harmonic. I think that I probably haven't understood something quite well here and I'm getting really confused about my problem.Can anyone help me?
Here is my code:
t=xlsread('C:\Users\Riko\Documents\MATLAB\Meas_V5_L2','A2:A10001');
I=xlsread('C:\Users\Riko\Documents\MATLAB\Meas_V5_L2','C2:C10001');
figure(1)
plot(t,I,'r');
xlabel('time (s)')
ylabel('current(A)')
grid on
N = 2^nextpow2(length(I));
Y = fft(I,N);
Fs = 5000; %Sampling frequency z
f = Fs/2*linspace(0,1,N);
p = abs(Y)/N; %Power of signal figure(2)
plot(f,p)
Thanks, in advance!

 Accepted Answer

I would change the plot to:
semilogy(f,p)
axis([0 50 ylim])
Looking closely at the plot, it seems to be relatively ‘clean’ and without significant noise, so the other peaks may be too low amplitude to see easily. Taking the log will probably allow you to see them. You may want to expand the x axis limits in the axis call beyond 50 Hz once you see the semilogy plot.

13 Comments

Rikos Verikokos
Rikos Verikokos on 5 Jun 2015
Edited: Rikos Verikokos on 5 Jun 2015
I tried your solution, it didn't work. The plot changed, but it's not what i expected to see. Any other idea?
Thanks a lot.
I don’t have your data, so I can’t experiment with it.
I have no other ideas, other than to see if changing the limits of the x axis displayed (up to but not beyond the Nyquist frequency) and letting you see more of your signal will work.
Consider that what you ‘expected to see’ may not be in your signal to begin with. Your signal looks like a pure sine curve with very small amplitude random noise. The fft should give a single spike with a very small or zero d-c offset. The random noise will likely display as a very small, broadband horizontal line only slightly above the d-c offset.
Just what do you expect to see?
It would be nice to have your data so we can analyse it to see what the problem is.
I am not a ‘member’ of dropbox. I can’t use it.
Use the ‘paperclip’ (or ‘staple’) icon next to the ‘Help’ button above the window to attach your file here instead.
Here is my data again (attached)!
There is a peak at 40-60 Hz and a small secondary peak at about 16 KHz, but otherwise it’s all ‘1/f’ noise, as is to be expected with real-world data. (This code is essentially the same as that used in the documentation for the fft function in MATLAB.)
What were you expecting?
My code:
[d,s,r] = xlsread('Rikos Verikokos Meas_V5_L2.xls');
Time = d(:,1);
Vph = d(:,2);
Iph = d(:,3);
N = size(d,1);
Ts = mean(diff(Time));
Fs = 1/Ts;
Fn = Fs/2;
FVph = fft(Vph)/N;
Fv = linspace(0, 1, fix(N/2)+1)*Fn;
Fi = 1:length(Fv);
figure(1)
semilogy(Fv, abs(FVph(Fi)))
grid
axis([0 2E+4 ylim])
xlabel('Frequency (Hz)')
title('V_{ph} (V)')
FIph = fft(Iph)/N;
Fv = linspace(0, 1, fix(N/2)+1)*Fn;
Fi = 1:length(Fv);
figure(2)
semilogy(Fv, abs(FIph(Fi)))
grid
axis([0 2E+4 ylim])
xlabel('Frequency (Hz)')
title('I_{ph} (A)')
FPph = fft(Vph.*Iph)/N;
Fv = linspace(0, 1, fix(N/2)+1)*Fn;
Fi = 1:length(Fv);
figure(3)
semilogy(Fv, abs(FPph(Fi)))
grid
axis([0 2E+4 ylim])
title('Power (VA)')
xlabel('Frequency (Hz)')
I expected to see something like that:
It's not the y axis that I care (Normalized Amplitude or not), is the harmonics and their position. According to literature I should see something like the waveform above. And I can't see it.
It seems you have a much purer, harmonic-free signal than the literature reports. Those peaks are simply not in your signal.
I will leave it to you to discover the differences between your experimental set-up and that described in the literature, since they produced quite different results.
Note that the y-axis in the literature figure is also a log scale, since dB=10*log10(ampitude^2).
Thank you very much for your help! I see what I can do with my experimental set-up, maybe it's something wrong with the oscilloscope I don't know.
Appreciate your help!
My pleasure!
I doubt the problem is with your oscilloscope, since it’s just doing your signal acquisition, and it seems to be working well. It’s possible that a higher sampling frequency would let you see the harmonics you expect, but since I don’t know what experiment you’re doing, that’s the only suggestion I have.
Not all literature reports are reproducible. If your experimental setup is the same as that reported in the literature, and you cannot reproduce the literature results, that itself may be significant.
I made it! Just changed the plot settings and my main harmonic is at ~50Hz (which is realistic if you consider that a real voltage supply usually doesn't have exactly 50Hz freq.).
there is my code:
[d,s,r] = xlsread('C:\Users\Riko\Documents\MATLAB\Meas_V5_L5');
Time = d(:,1);
Vph = d(:,2);
Iph = d(:,3);
N = 2^nextpow2(size(d,1));
Ts = mean(diff(Time));
Fs = 1/Ts;
Fn = Fs/2;
figure(1)
plot(Time,Iph)
xlabel('Time (sec)')
ylabel('Current (A)')
title('Current-Time diagramm')
FIph = fft(Iph,N)/size(d,1);
Fv = Fs/2*linspace(0,1,N/2+1);
Fi = 1:length(Fv);
figure(2)
plot(Fv, 2*abs(FIph(Fi)),'r')
grid
axis([0 2E+4 ylim])
xlabel('Frequency (Hz)')
ylabel('I_{ph} (A)')
title('FFT analysis')
You've been really helpful! Thanks a lot!
As always, my pleasure!

Sign in to comment.

More Answers (2)

I totally agree you really need to explain what you want to see. here is a quick sample using the multitude of FFT examples out there on the internet.
f = 50; %frequency of sinewave
fs=50000; %sampling frequency
x = -.025:1/fs:.025;
y = 2.25*sin(2*pi*f*(x+.007))+.1*rand(size(x))-.2;
figure(1),subplot(1,3,1),plot(x,y); %mimic of your example
title(['Sine Wave f=', num2str(f), 'Hz']);
xlabel('Time(s)');
ylabel('Amplitude');
NFFT=2.^nextpow2(numel(y));
Y=fftshift(fft(y,NFFT));
fVals=fs*(-NFFT/2:NFFT/2-1)/NFFT;
subplot(1,3,2),plot(fVals,abs(Y),'b');
title('Double Sided FFT - with FFTShift');
xlabel('Frequency (Hz)')
ylabel('|DFT Values|');
xlim([-100 100])
NFFT=2.^nextpow2(numel(y)*10); %10x to "increase" the spectral resolution
Y=fftshift(fft(y,NFFT));
fVals=fs*(-NFFT/2:NFFT/2-1)/NFFT;
subplot(1,3,3),plot(fVals,abs(Y),'b');
title('Double Sided FFT - with FFTShift "increase in spectral resolution"');
xlabel('Frequency (Hz)')
ylabel('|DFT Values|');
xlim([-100 100])

1 Comment

When I run your example, I observe the two harmonics with the highest amplitude, at 50Hz (since you plot a double-sided fft).This is because, your sinewave frequency is 50Hz. When I run my code, I expect to see my main harmonic at 50 Hz, but I'm seeing the plot that I posted above. And I don't know why is this happening.
Appreciate your help!

Sign in to comment.

Ayush
Ayush on 7 Jun 2015
Edited: Ayush on 7 Jun 2015

0 votes

Refer to this link : fft
Alternatively, i simulated your code using t as simple sine wave. either try to load I individually and check its output, as it could be a case your variable I being filled of dummy value. use clc;clear;

Community Treasure Hunt

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

Start Hunting!