Problem with FFT plot

조회 수: 7 (최근 30일)
Rikos Verikokos
Rikos Verikokos 2015년 6월 4일
댓글: Star Strider 2015년 6월 9일
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!

채택된 답변

Star Strider
Star Strider 2015년 6월 5일
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
Rikos Verikokos
Rikos Verikokos 2015년 6월 9일
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!
Star Strider
Star Strider 2015년 6월 9일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Joseph Cheng
Joseph Cheng 2015년 6월 5일
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
Rikos Verikokos
Rikos Verikokos 2015년 6월 6일
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!

댓글을 달려면 로그인하십시오.


Ayush
Ayush 2015년 6월 7일
편집: Ayush 2015년 6월 7일
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;

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by