Need Help with FFT Analysis and Power Factor Calculation in MATLAB

13 次查看(过去 30 天)
Hello everyone,
I have a CSV file with two columns: "t" (time) and "i(t)" (current). I want to perform Fast Fourier Transform (FFT) analysis on the "i(t)" data to calculate the Total Harmonic Distortion (THD) and obtain information about power factor components, including displacement power factor and distortion power factor.
Here's what I need assistance with:
1. How can I read the CSV data in MATLAB with the "t" and "i(t)" column headers?
2. Calculate the FFT of the "i(t)" current data.
3. Determine the fundamental frequency and compute THD for the current signal.
4. Calculate the Displacement Power Factor (DPF) and Distortion Power Factor (DPFd).
I would appreciate any guidance or code snippets to help me achieve this analysis in MATLAB. Thank you in advance for your help!
Best regards.

回答(1 个)

Chunru
Chunru 2023-11-14
Here is the work flow:
1.Read the CSV data in MATLAB with the "t" and "i(t)" column header as a table
x = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1537480/data.csv", "VariableNamingRule", "preserve")
x = 2048×2 table
t i(t) ________ ________ 8e-06 0.044922 1.6e-05 0.050391 2.4e-05 0.050391 3.2e-05 0.050781 4e-05 0.050781 4.8e-05 0.053906 5.6e-05 0.053906 6.4e-05 0.041016 7.2e-05 0.041016 8e-05 0.046875 8.8e-05 0.046875 9.6e-05 0.080078 0.000104 0.080078 0.000112 0.10938 0.00012 0.10938 0.000128 0.13867
2. Calculate the FFT
Plot the data
figure
plot(x.t, x.("i(t)"))
Since your data is not uniformly sampled, we need an interpolation
ts = diff(x.t(1:2)); % sampling time based on 1st two points (adjust this if necessary)
t = x.t(1):ts:x.t(end); % uniform time points
t0 = x.t;
y0 = x.("i(t)");
% t0 need to be unique
[tu, ia] = unique(t0);
yu = y0(ia);
y = interp1(tu, yu, t); % interplate the data
hold on
plot(t, y);
legend("original", "interp")
3. Determine the fundamental frequency and compute THD for the current signal.
p = 20*log10(abs(fft(y))); % log scale in dB
figure
f = (0:length(p)-1)/ts;
plot(f, p);
xlim(f([1 50])); % zoom in first 0 50 bins
% find the peak
[pmax, imax] = max(p);
hold on
plot(f(imax), p(imax), 'r*')
% Harmonic freq
f(imax)
ans = 125000
4. Calculate the Displacement Power Factor (DPF) and Distortion Power Factor (DPFd).
Try out the rest with the definition of THD, DPF and DPFd

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by