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)
Show older comments
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')
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Categories
Find more on Single-Rate Filters 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!