Peak interpolation in frequency domain
Mostrar comentarios más antiguos
Hi Everyone,
I am trying to do some peak interpolation in the freq domain.. I am zero padding already in the time domain however trying to get the peaks centered more around the correct bin. Any suggestions on how to do this with my current code?
Thanks!
Mike
Fs =5000; % Sampling frequency
x=data; %Truncated to increase bin width for testing
T = 1/Fs; % Sampling period
L = length(x); % Length of signal
t = (0:L-1)*T; % Time vector
x = x-mean(x); %subtract DC signal component
%DFT without window or Interpolation
xdft = fft(x);
xdft = xdft(1:length(x)/2+1);
xdft = xdft/length(x);
xdft(2:end-1) = 2*xdft(2:end-1);
freq = 0:Fs/length(x):Fs/2;
%Add Hanning Window without zero padding
nfft = 2^nextpow2(L); % Transform length
y_HannWnd = x.*hanning(L);
Ydft_HannWnd = fft(y_HannWnd,nfft);%/L;
Ydft_HannWnd = Ydft_HannWnd(1:L/2+1);
Ydft_HannWnd(2:end-1) = 2*Ydft_HannWnd(2:end-1);
P2H = abs(Ydft_HannWnd/L);
P1H = P2H(1:L/2+1);
P1H(2:end-1) = 2*P1H(2:end-1);
f = Fs*(0:(L/2))/L;
% %Hanning window with zero padding
%
% lpad = 2*length(x);
%
% xpad = padarray(x,lpad);
%
% Lp = length(xpad);
%
%
% nfftpad = 2^nextpow2(Lp); % Transform length
%
%
% y_HannWndpad = x.*hanning(L);
%
%
% Ydft_HannWndpad = fft(y_HannWndpad,nfftpad)/Lp;
%
%
%
% Ydft_HannWndpad = Ydft_HannWndpad(1:(Lp)/2+1);
% Ydft_HannWndpad(2:end-1) = 2*Ydft_HannWndpad(2:end-1);
%
% P2Hpad = abs(Ydft_HannWndpad/Lp);
% P1Hpad = P2Hpad(1:(Lp)/2+1);
% P1Hpad(2:end-1) = 2*P1Hpad(2:end-1);
% fpad = Fs*(0:(Lp/2))/Lp;
%Hanning window with zero padding
lpad = 10*length(x);
xpad = padarray(x,lpad);
Lp = length(xpad);
nfftpad = 2^nextpow2(Lp); % Transform length
y_HannWndpad = x.*hanning(L);
Ydft_HannWndpad = fft(y_HannWndpad,lpad);
Ydft_HannWndpad = Ydft_HannWndpad(1:(lpad)/2+1);
Ydft_HannWndpad(2:end-1) = 2*Ydft_HannWndpad(2:end-1);
P2Hpad = abs(Ydft_HannWndpad/lpad);
P1Hpad = P2Hpad(1:(lpad)/2+1);
P1Hpad(2:end-1) = 2*P1Hpad(2:end-1);
fpad = Fs*(0:(lpad/2))/lpad;
%% Zero Padding for Interpolation no Hanning window
lpad = 4*length(x);
xdftpad = fft(x,lpad);
xdftpad = xdftpad(1:lpad/2+1);
xdftpad = xdftpad/length(x);
xdftpad(2:end-1) = 2*xdftpad(2:end-1);
freqpad = 0:Fs/lpad:Fs/2;
%Plot time-domain signal
subplot(6,1,1);
plot(t, x);
ylabel('Amplitude'); xlabel('Time (secs)');
axis tight;
title('Shaker Input Signal');
subplot(6,1,2);
%plot(freq,abs(xdft));
title('DFT no padding or Hann')
xlabel('t (milliseconds)')
ylabel('X(t)')
%Hold on
subplot(6,1,3);
plot(freqpad,abs(xdftpad),'c')
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
%ylim([0,2000]);
subplot(6,1,4);
plot(f,P1H,'r')
title('Hann FFT')
xlabel('f (Hz)')
ylabel('|P1(f)|')
%ylim([0,2000]);
subplot(6,1,5);
plot(fpad,P1Hpad,'g')
title('Hann plus zero padding dFT')
xlabel('f (Hz)')
ylabel('|P1(f)|')
%ylim([0,2000]);
subplot(6,1,6);
plot(freq,abs(Ydft_HannWnd),'r')
title('Hann FFT')
xlabel('f (Hz)')
ylabel('|P1(f)|')
%ylim([0,2000]);
Respuestas (0)
Categorías
Más información sobre Signal Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!