# Impedance calculation using FFT from time, voltage and current battery data

27 views (last 30 days)
ekagra gupta on 23 Aug 2022
Commented: ekagra gupta on 30 Aug 2022
Hello,
I have battery pulse test and pseudo OCV measurements (time, current and voltage) in time domain and I want to obtain plot similar to EIS in freuqnecy domain using Fourier Transform.
Is it possible? If yes, then please explain the approach
Thankyou
ekagra gupta on 23 Aug 2022
? I know using FFT but it would be great if someone would rpovide some code to follow up

Mathieu NOE on 24 Aug 2022
hello
should be possible using tfestimate function
alternative (older) code :
x and y are your time domain data (x = input of the system , y = output)
you need to specify the fft buffer length, sampling freq, type of window and overlap (if you want)
%%%%%%%%%%%%%%%%%%%%%%%
function [Txy,Cxy,f] = mytfe_and_coh(x,y,nfft,Fs,window,noverlap)
% Transfer Function and Coherence Estimate
% compute PSD and CSD
window = window(:);
n = length(x); % Number of data points
nwind = length(window); % length of window
if n < nwind % zero-pad x , y if length is less than the window length
x(nwind)=0;
y(nwind)=0;
n=nwind;
end
x = x(:); % Make sure x is a column vector
y = y(:); % Make sure y is a column vector
k = fix((n-noverlap)/(nwind-noverlap)); % Number of windows
% (k = fix(n/nwind) for noverlap=0)
index = 1:nwind;
Pxx = zeros(nfft,1);
Pyy = zeros(nfft,1);
Pxy = zeros(nfft,1);
for i=1:k
xw = window.*x(index);
yw = window.*y(index);
index = index + (nwind - noverlap);
Xx = fft(xw,nfft);
Yy = fft(yw,nfft);
Xx2 = abs(Xx).^2;
Yy2 = abs(Yy).^2;
Xy2 = Yy.*conj(Xx);
Pxx = Pxx + Xx2;
Pyy = Pyy + Yy2;
Pxy = Pxy + Xy2;
end
% Select first half
if ~any(any(imag([x y])~=0)) % if x and y are not complex
if rem(nfft,2) % nfft odd
select = [1:(nfft+1)/2];
else
select = [1:nfft/2+1]; % include DC AND Nyquist
end
Pxx = Pxx(select);
Pyy = Pyy(select);
Pxy = Pxy(select);
else
select = 1:nfft;
end
Txy = Pxy ./ Pxx; % transfer function estimate
Cxy = (abs(Pxy).^2)./(Pxx.*Pyy); % coherence function estimate
f = (select - 1)'*Fs/nfft;
end
ekagra gupta on 30 Aug 2022
No thank you! Got it covered.
Thank you for ,your efforts and time

### Categories

Find more on Spectral Measurements 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!

Translated by