Applying zero padding and windowing in my code
Show older comments
Hi,
I have the following working code perfoming FFT analysis. I am still learning mathlab and signal processing however, I have been reading that in order to get a better FFT output one must apply zero padding and windowing.
I have come up with the following code with the help of online tutorials and this forum. The code is giving me what I want which is frequency components in the signal however i don't think it is achieving this doing zero padding and windowing.
My question when is it necessary to perform zero padding and windowing on the signal? and how can incorporate it in my code?
[D,S,R] = xlsread('test data.csv');
t = D(:,1);
v = D(:,2);
figure
plot(t, v); % plot time domain signal
grid
xlabel('Time')
ylabel('Voltage')
Signal = D(:,2);
Ts = 0.00005; % Sampling Interval (seconds)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz) half of the sampling rate of a discrete signal processing system
N = length(Signal);
meanSignal = mean(Signal); % ‘Signal’ Mean
FTSignal = fft(Signal-meanSignal)/N; % Normalised Fourier Transform Of Baseline-Corrected ‘Signal’
Fv = linspace(0, 1, fix(numel(FTSignal)/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
[pks,locs] = findpeaks(abs(FTSignal(Iv))*2, 'MinPeakHeight',0.044);
figure
plot(Fv, abs(FTSignal(Iv))*2)
grid
xlabel('Frequency(Hz)')
ylabel('Amplitude')
plotIdx = 1:Iv(max(locs));
figure
plot(Fv(plotIdx), abs(FTSignal(Iv(plotIdx)))*2)
hold on
plot(Fv(plotIdx(locs)), pks, '^r', 'MarkerFaceColor','r')
title('FFT for Power Analysis')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
xlswrite('myfile.xls',Fv')
xlswrite('myfile2.xls',abs(FTSignal(Iv))*2')
hold off
Accepted Answer
More Answers (0)
Categories
Find more on Fourier Analysis and Filtering 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!