YK Energy Device & Consulting EIS-DRT Analyzer

EIS-DRT-Excel-Analyzer

~ Empowering Engineers with Advanced DRT Analysis Beyond Corporate IT Security Constraints ~

1. Introduction: The Mission Behind This Project

Distribution of Relaxation Times (DRT) analysis is a powerful tool for deconvolving physical phenomena from Electrochemical Impedance Spectroscopy (EIS) data. While cloud-based analysis services exist, many engineers handling sensitive data face significant barriers due to corporate IT security policies that prohibit uploading data to external servers.

This project aims to "complete professional-grade DRT analysis entirely within local Excel environments." Provided as VBA code, this tool allows you to bypass strict software installation restrictions and conduct advanced analysis securely on your desktop without ever sending your confidential data outside your organization.

* Development Background: This VBA implementation was developed in collaboration with Google Gemini (AI). By feeding specialized electrochemical expertise into the AI, we achieved high-level matrix operation algorithms within the constraints of the Excel environment.
DRT Analysis Output Example

2. Usage

GitHub Repository: @ykusachi/Excel_DRT

You can copy the VBA source code or download template files from the link above.

Module Configuration

  • DRT_core.bas: The core DRT algorithm. Derives the distribution function from a single set of impedance data.
  • Z_summary.bas: Extension for batch processing of multiple measurement files.

Installation Guide (Windows / Mac)

Follow these steps to import the VBA modules into your Excel file on any OS:

  1. Open your Excel file and launch the Visual Basic Editor (VBE):
    • Windows: Alt + F11
    • Mac: Option + F11 (or via Tools > Macro > Visual Basic Editor)
  2. Import Files: Select "File" > "Import File..." from the VBE menu.
  3. Select the downloaded .bas files to load them.
  4. Run: Return to Excel and call the macros from the "Developer" tab (or Alt/Option + F8).

3. Detailed Analysis Features

A. Core Analysis (Single Sample)

Place your data (Column A: Frequency, B: Z', C: Z'') starting from row 2 and run the ActiveSheetDRT_all macro.

Sub ActiveSheetDRT_all()
    ' 1. Data Prep (Magnitude/Phase calculation)
    Call CalculateMagAndPhase
    
    ' 2. Numerical Inversion (Main Computation)
    Call RunDRT
    
    ' 3. Parameter Optimization (L-Curve Method)
    Call FindOptimalLambda_Normalized
    
    ' 4. Model Reconstruction and Validation
    Call CalculateImpedanceFromOptimalDRT
    
    ' 5. Visualization
    Call CreateColeColeComparisonChart_Styled_A7
    Call CreateDRTSpectrumChart_Styled_G7
End Sub
Data Layout

B. Option Feature (Batch Processing)

Designed for efficient processing of large datasets. By selecting multiple .z files via a dialog, the tool automates data extraction, continuous analysis, and comparison report generation.

* Important Note for Batch Processing:
To optimize efficiency, each dataset is assigned an individually optimized regularization parameter (λ). Please be aware that the final comparison graph may contain results calculated under different λ conditions.
* Flexibility: Currently configured for .z files, but the loading logic can be easily modified for CSV or other formats.
Summary Report Generation

4. Global Settings

Modify the constants at the top of the DRT_core module to control analysis behavior.

' 1. KK-Filter Threshold (%)
Public Const KK_THRESHOLD As Double = 3#

' 2. Lambda (λ) Scan Settings (10^0 to 10^-10)
Public Const LAMBDA_START_EXP As Double = 0#
Public Const LAMBDA_END_EXP As Double = 10#

' 3. DRT Spectrum Endpoint Trimming (Number of points to cut)
Public Const CUT_LOW_FREQ As Integer = 3
Public Const CUT_HIGH_FREQ As Integer = 0

5. Technical Deep Dive: Internal Processing

Step 1: Physical Consistency Verification (KK-Filter)

Verifies if EIS data is physically valid according to Kramers-Kronig relations. The tool checks the consistency of real and imaginary parts and excludes points where the deviation exceeds the KK_THRESHOLD (default 3%).

  • Setting the Threshold: 3% to 5% is standard. Use 5% for noisy data and 1% for high-precision laboratory measurements.
  • Why filter? Including points that violate KK relations due to drift or external noise can produce "ghost peaks" in the DRT spectrum.
KK Filtering

Step 2 & 3: Tikhonov Regularization and L-Curve Method

DRT calculation is an "ill-posed problem" where small noise can cause massive oscillations in the solution. We implement Tikhonov Regularization, adding a penalty term to ensure smoothness.

Auto-Optimization in VBA

Selecting the regularization strength "λ (lambda)" is critical for accurate results.

  • λ Scan & Computation Time: The tool scans from LAMBDA_START_EXP to LAMBDA_END_EXP. Expanding this range improves the chance of finding the absolute optimum but increases calculation time due to the heavy matrix operations performed at each step.
  • L-Curve Evaluation: Residuals and Penalty are calculated for each λ. The "elbow point" (point of maximum curvature) on the L-curve is automatically selected as the most balanced λ.
L-Curve Optimization

Step 4: Reconstruction and Validation

The tool back-calculates impedance from the derived DRT to compare with raw data.

Frequency Endpoint Trimming

Mathematical artifacts often appear as sharp spikes at frequency boundaries. These can be removed by adjusting:

  • Low-freq trim: Adjust CUT_LOW_FREQ (e.g., 3 cuts the last 3 low-frequency points).
  • High-freq trim: Adjust CUT_HIGH_FREQ for the high-frequency end.
Model Validation

6. References

7. License

This project is released under the MIT License. You are free to use, modify, and distribute it, provided the copyright notice is maintained.


EIS-DRT-Excel-Analyzer (日本語)

〜 企業のITセキュリティ制約を打破し、全てのエンジニアに高度なDRT解析を 〜

1. イントロダクション:本プロジェクトの「想い」

緩和時間分布(DRT)解析は、電気化学インピーダンス(EIS)データから物理現象を鮮やかに分離できる強力なツールです。現在、オンライン上でデータをアップロードして解析を行うクラウドサービスも存在しますが、機密情報を扱う多くのエンジニアにとって、外部サーバーへのデータアップロードは情報セキュリティ上の大きな障壁となっています。

本プロジェクトは、「ローカル環境のExcelだけで、専門ソフト並みの解析を完結させる」ことを目的としています。VBAコードとして提供されるため、IT部門による厳しいソフトウェアインストール制限を回避しつつ、機密データを一切外に出すことなく、あなたのデスクトップ上で安全に高度なDRT解析を行うことができます。

※ 開発の背景: 本ツールのVBA実装には、Google Gemini(AI)を活用しています。専門的な電気化学的知見をAIにフィードバックし、Excelという限定された環境下で高度な行列演算アルゴリズムを実現しました。
DRT解析の出力例

2. 使用方法 (Usage)

GitHub リポジトリ: @ykusachi/Excel_DRT

上記リンクより、VBAソースコードのコピーやテンプレートファイルのダウンロードが可能です。

モジュールの構成

  • DRT_core.bas:DRTのコアアルゴリズム。単一のインピーダンスデータから分布関数を導出します。
  • Z_summary.bas:複数ファイルの一括解析用拡張機能。

Excelへの導入手順 (Windows / Mac 共通)

  1. Visual Basic Editor (VBE) を起動:
    • Windows: Alt + F11
    • Mac: Option + F11
  2. ファイルのインポート: VBEメニュー「ファイル」>「ファイルのインポート...」から .bas を選択。
  3. 実行: Excelの「開発」タブまたは Alt/Option + F8 からマクロを呼び出し。

3. 解析機能の詳細

A. 解析コア機能(単体解析)

Sub ActiveSheetDRT_all()
    Call CalculateMagAndPhase
    Call RunDRT
    Call FindOptimalLambda_Normalized
    Call CalculateImpedanceFromOptimalDRT
    Call CreateColeColeComparisonChart_Styled_A7
    Call CreateDRTSpectrumChart_Styled_G7
End Sub

B. オプション機能(複数ファイル一括処理)

※一括処理時の注意点:
本機能では、計算効率化のため各データに対して個別に最適化された正則化パラメータ(λ)が自動選定されます。比較グラフには、λが異なる条件での解析結果が混在する可能性があることに留意してください。
サマリーレポート作成

4. 解析パラメータの詳細設定 (Global Settings)

' 1. KK-Filter Threshold (%)
Public Const KK_THRESHOLD As Double = 3#

' 2. Lambda (λ) Scan Settings (10^0 〜 10^-10)
Public Const LAMBDA_START_EXP As Double = 0#
Public Const LAMBDA_END_EXP As Double = 10#

' 3. DRT Spectrum Endpoint Trimming
Public Const CUT_LOW_FREQ As Integer = 3
Public Const CUT_HIGH_FREQ As Integer = 0

5. 技術解説

Step 1: 物理的整合性の検証 (KK-Filter)

偏差が KK_THRESHOLD を超える点を除外します。ノイズの多いデータでは5%、高精度な解析では1%程度に調整します。

Step 2 & 3: Tikhonov正則化とL-Curve法

LAMBDA_START_EXP から LAMBDA_END_EXP の範囲でλをスキャン。L-Curveの曲率が最大となるエルボー点を自動採用します。スキャン範囲を広げると計算時間は増えますが、最適解を見つけやすくなります。

Step 4: インピーダンス再構成と検証

低周波側のアーティファクトが気になる場合は CUT_LOW_FREQ の値を増やして調整します。