Core Code

Posted by Fang Zhou on September 11, 2018

MFC

  • This software is based on VC6.0 and MFC. It is too difficult to learn MFC. Maybe I can use Visual Studio to modify it in later.
  • The core code is the module named Calculate Power. I find the core algorithm. Lissajous method is used here.

Code (Prevent invalid input)


int index1, index2, index;
	for (int i = 0; i < 32780; i++)
	{
		if (Data1[i] != 0) 
			index1 = i;   
		if (Data2[i] != 0) 
			index2 = i;
	}
	
	if (index1 < index2)
	{
		index = index1 - 5;
	}
	else
	{
		index = index2 - 5;
	}

Code (Five point smooth)


Data1_b[0] = (((69) * Data1[0]) + (4 * Data1[1]) + ((-6) * Data1[2]) + (4 * Data1[3]) + ((-1)* Data1[4])) / 70;
Data1_b[1] = (((2) * Data1[1]) + (27 * Data1[2]) + ((12) * Data1[3]) + ((-8) * Data1[4]) +((2) * Data1[5])) / 35;
Data1_b[index-1] = (((2) * Data1[index-4]) + ((-8) * Data1[index-3]) + ((12) * Data1[index-2]) + ((27) * Data1[index-1]) + (1 * Data1[index])) / 35;
Data1_b[index] = (((-1) * Data1[index-4]) + (4 * Data1[index-3]) + ((-6) * Data1[index-2]) + ((4) * Data1[index-1]) + ((69) * Data1[index])) / 70;

Code (Lissajous)


double answer = 0;
	for (int j = start; j <= end; j++)
	{
		answer += 0.5 * (Data2_c[j + 1] + Data2_c[j]) * (Data1_c[j+1] - Data1_c[j]);
	}
	// *C
	answer *= Capacitance;
	// f
	index = end - start;
	if (Time ==0)
	{
		m_frequency = 1 / (index * Time_saved_1);
	}
	else
	{
		
		m_frequency = 1 / (index * Time); //time is the interval of 2 sampling point, multiply a number of sampling point
	}
	m_voltage5 = answer; //displat power for one cycle
	m_frequency *= 1000;
	// answer
	answer *= m_frequency;
	m_power = answer;
	m_frequency *= 1;

	
	m_voltage = max1;
	m_voltage2 = max2; 
	m_voltage3 = 2 * max2; 
	m_voltage4 = 2 * max1;
	
	return answer;