Error/Mismatch in determing impedance using fft in simulink imported data.

7 次查看(过去 30 天)
Hello Everyone
I need to calculate the impedance of a more or less complex circuit using FFT. I have implemented the circuit in simulink and saved the voltage and current in the workapace using To Workspace block. However, after performing fft , I didnt quite get the expected result. Now to check if my code was right, I was testing it on a simple circuit. I have implemented a simple RC circuit . The model is attached. To determine impedance I am using the theory Z(w)=fft(voltage)/fft(current). R=Real (Z(w), X=Imag(Z(w)).
Now, The snapshot of the circuit--
The code I am using-
clc
% clear
Time = out.tout;
Load_Voltage = out.V_L;
Load_Current = out.I_L;
Fs = 1 / mean(diff(Time));
N = length(Load_Voltage);
fft_Load_Voltage = fft(Load_Voltage);
fft_Load_Current = fft(Load_Current);
fft_Load_Voltage_single_sided = fft_Load_Voltage(1:N/2+1);
fft_Load_Current_single_sided = fft_Load_Current(1:N/2+1);
frequencies = Fs * (0:(N/2)) / N;
frequency_of_interest =13.56e6;
[~, index] = min(abs(frequencies - frequency_of_interest));
Z1 = fft_Load_Voltage_single_sided(index) / fft_Load_Current_single_sided(index);
R1 = real(Z1);
X1 = imag(Z1);
fprintf('R: %.2f ohms, X: %.2f ohms\n', R1, X1);
I have set the value of the resistor as 30 and the value of capacitor such as it would exibit -50 ohm at 13.56 Mhz, which is the driving frequency. But the results are off. The result I get is: R: 25.79 ohms, X: -37.52 ohms.
What is the problem here? Is it the code or anything with the simulink model. However if its just a resistive circuit the code gives correct result. This a very important step in a much bigger project. It is crucial.
Your help will be really appreciated.
Thank You.

采纳的回答

Sayan
Sayan 2024-5-28
Hi Md. Golam,
You do not need to use the powergui block here, as the block is only required in the case of solving Specialized Power System blocks. I could resolve the issue by setting the solver type to "Fixed-step". The "Variable-step" solver does not compute the value of the signal at a regular time interval. For FFT analysis, a fixed-step size ensures uniform sampling intervals, which is a prerequisite for standard FFT algorithms. I have got the expected value of resistance and capacitive impedence, as shown below.
I am attaching the updated model here. You can know more about the comparison between "Fixed-step" and "Variable-step" solver in the following documentation.
Hope this resolves your issue.
  5 个评论
Sayan
Sayan 2024-5-28
编辑:Sayan 2024-5-28
resample internally takes care of the interpolation. Please look at the part of the documentation where an example is shown to resample a non uniformally spaced data.
Md. Golam Zakaria
Md. Golam Zakaria 2024-5-28
@Sayan I have tried interpolation on the original concept of mine and its working. I will surely try resampling . Maybe it will give me more accurate results. Thank you for this. You have helped me big time.

请先登录,再进行评论。

更多回答(1 个)

Pat Gipper
Pat Gipper 2024-5-28
@Md. Golam Zakaria You can use the variable step solver and force it to output at fixed intervals by putting a "Sample time" value other than -1 into the "To Workspace" blocks of your simulation as shown in the image below. I tend to use a workspace variable instead of a fixed number for flexibility.

类别

Help CenterFile Exchange 中查找有关 Variable Initialization 的更多信息

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by