Error/Mismatch in determing impedance using fft in simulink imported data.
8 次查看(过去 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--
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1703056/image.png)
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.
2 个评论
Pat Gipper
2024-5-22
编辑:Pat Gipper
2024-5-22
The model you attached and the picture that you show is a series RL circuit, with R = 50 Ohms and L = 0.587 uH.
采纳的回答
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1705121/image.png)
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 个评论
更多回答(1 个)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1705356/image.jpeg)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Switches and Breakers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!