Skip to content
forked from whhxp/getPF

powerFactor calculation by using inducedVoltage and exciting current

Notifications You must be signed in to change notification settings

POLYU-EMLAB/getPF

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

getPF

powerFactor calculation by using inducedVoltage and exciting current

电机设计中,功率因数可以认为是感应电压和电流的相位差$\theta$。 那么$$ Power Factor = cos(\theta)$$

废话不多说,上代码: Matlab1代码来源于ilovematlab论坛

fs=100;N=1024;   %采样频率和数据点数
n=0:N-1;t=n/fs;   %时间序列
y1=cos(2*pi*15*t+pi/4);%函数1
y2=cos(2*pi*40*t);%函数2
X1=fft(y1);
X2=fft(y2);
mag1=abs(X1);mag2=abs(X2);%幅频特性
f=n*fs/N;
X1_max=max(mag1);X2_max=max(mag2);
flag1=find(mag1==X1_max);flag2=find(mag2==X2_max);%找到最大值点
pha1=angle(X1(flag1));pha2=angle(X2(flag2));%对该点的fft值求角度
pha=pha1-pha2;
fft_pha=abs(pha);
subplot(2,2,1);plot(f,y1);%函数1模型
subplot(3,2,2);plot(f,y2);%函数2模型
subplot(2,2,3);plot(f,mag1);%函数1幅频特性
subplot(2,2,4);plot(f,mag2);%函数1幅频特性
disp(fft_pha);disp(fft_pha/pi*180);%所求弧度或角度

由于这个结果需要在没有matlab环境的地方调用,所以我只好又用C++写了一份。 C++

typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;

    CArray volArray(voltageC, lineCount);
    CArray curArray(currentC, lineCount);
    volArray = fft(volArray);
    curArray = fft(curArray);
    CArray magVoltage(lineCount);
    CArray magCurrent(lineCount);
    magVoltage = std::abs(volArray);
    magCurrent = std::abs(curArray);
    printArray("Voltage", magVoltage);
    printArray("Current", magCurrent);
    int volFlag = 0;
    int curFlag = 0;
    float max = round(magVoltage[0].real() * 1e6) / 1e6;
    volFlag = 0;
    for (unsigned int i = 0; i < magVoltage.size(); i++)
    {
        float tmp = round(magVoltage[i].real() * 1e6) / 1e6;
        if (tmp > max)
        {
            max = tmp;
            volFlag = i;
        }
    }
    double phaVol = std::arg(volArray[volFlag]);
    float maxC = round(magCurrent[0].real() * 1e6) / 1e6;
    curFlag = 0;
    for (unsigned int i = 0; i < magCurrent.size(); i++)
    {
        float tmp = round(magCurrent[i].real() * 1e6) / 1e6;
        if (tmp > maxC)
        {
            maxC = tmp;
            curFlag = i;
        }
    }
    double phaCur = std::arg(curArray[curFlag]);
    PF = cos(phaVol - phaCur);

About

powerFactor calculation by using inducedVoltage and exciting current

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 99.6%
  • QMake 0.4%