correct way for zero padding

10 views (last 30 days)
Kutru biladi
Kutru biladi on 31 Aug 2015
Edited: per isakson on 31 Aug 2015
Here in the code below, I am taking fft of my data and plotting it. Moreover, I am doing zero padding by multiplying the signal length by 1000.
Is it the correct way for Zero padding? Moreover, am I defining frequency axes correctly? I am not getting desired output. Thanks everyone in advance
% second-order butterworth
[b, a] = butter(2, [w1 w2], 'bandpass');
load('fb2030'); % loading the data
x = fb2030(30,:);
% filtering
y_filt = filter(b,a,x); % filtering the received signal
nfft = length(y_filt)*1000; %%%%Zero Padding
res = fft(y_filt,nfft)/ nfft; % normalizing the fft
%
f = fs/2*linspace(0,1,nfft/2+1); % choosing correct frequency axes
res = res(1:nfft/2+1); % amplitude of fft(taking the half length of nfft)
figure,plot(f,2*abs(res));
xlabel('Frequency in MHz');ylabel('amp')
  1 Comment
dpb
dpb on 31 Aug 2015
By nfft = length(y_filt)*1000; you've caused a length of 1000X the actual length of your signal so only a small fraction N/(N*1000+N) or just under 0.1% of the signal being transformed is nonzero.
The typical zero-padding is to the next power of 2 over the length but that is mostly a remnant of years ago when compute power was much less and the difference in speed of the algorithm was a serious concern. Now if the signal is of sufficient length to have reasonable resolution, you may well do without padding at all.
But see
doc fft
doc nextpow2
for sample of doing a PSD

Sign in to comment.

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!