Problem with FFT plot
17 views (last 30 days)
Show older comments
Rikos Verikokos
on 4 Jun 2015
Commented: Star Strider
on 9 Jun 2015
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).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150851/image.jpeg)
The problem is that, when i try to apply fft to my data, i'm taking this waveform as a result.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150852/image.jpeg)
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!
0 Comments
Accepted Answer
Star Strider
on 5 Jun 2015
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
More Answers (2)
Joseph Cheng
on 5 Jun 2015
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])
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!