I have an excel data of time vs voltage plot of a signal and have to plot a fft for the same. the excitation frequency is 50khz, but the fft peak is arriving at 35khz. how do i fix this?

4 views (last 30 days)
the matlab code is mentioned below
if true
% code
end
[D,T] = xlsread('50KHZ.xlsx');
F = D(:,2); % Data Channel
Ts = 8e-4; % Sampling Interval (s)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % excitation Frequency
LF = size(F,1); % Length of Data Vector
T = linspace(0,1,LF)*Ts; % Create Time Vector
figure(1) % Plot Data
plot(T, F)
grid
xlabel('Time')
ylabel('Voltage')
FF = fft(F)/LF; % Fourier Series of Data, Freq Vector
Fv = linspace(0,1,fix(LF/2)+1)*Fn;
Iv = 1:length(Fv); % Index Vector
figure(2) % Plot FFT
plot(Fv, abs(FF(Iv)))
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')

Accepted Answer

Star Strider
Star Strider on 30 Apr 2016
I recognise that code (thank you for quoting it). The only problem may be that your sampling interval, ‘Ts’ is incorrect.
Assuming that ‘D(:,1)’ is your time vector (I don’t know if it is), see if changing the ‘Ts’ assignment to:
Ts = mean(diff(D(:,1))); % Sampling Interval (s)
produces the correct plot.
If ‘D(:,1)’ is your time vector, also change the ‘T’ assignment to:
T = D(:,1);
NOTE This is obviously UNTESTED CODE. I don’t see any typographical errors.
  2 Comments
RADHIKA V
RADHIKA V on 1 May 2016
thank you. I made the changes as suggested by you, but I'm still unable to get the peak at exact 50khz value , but at 52.5khz or at a slightly different value.
Star Strider
Star Strider on 1 May 2016
My pleasure.
When I add a findpeaks call (in R2016a, since findpeaks has had some version changes recently):
[pks,frqs] = findpeaks(abs(FF(Iv)), Fv, 'MinPeakHeight',1.5);
I get:
pks =
1.5734
1.6382
frqs =
50000 55000
So one of them is exact. It’s just the second-highest, not the maximum peak.
Your signal is a combination (‘heterodyne’) of several frequencies. That’s clear just by looking at it. Sampled signals also ‘heterodyne’ with the sampling frequency of the ADC (which is a highly nonlinear process), so such apparent inaccuracies are relatively frequent. There are likely actual frequency components at 55000 Hz as well, whether specifically intended to be part of the signal, or due to heterodyning during its creation.
Adding:
axis([0 1E+5 ylim])
after the figure(2) plot call expands the principal peak region.
You could experiment by zero-padding the signal (with the nextpow2 function) to increase its frequency resolution. See this documentation for fft for an illustration.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!