# Improve Motor Efficiency with Optimized Control Parameters

Since R2023b

This example shows how to improve the efficiency of a permanent magnet synchronous motor (PMSM) drive using an optimal field-oriented controller (FOC). The FOC has been designed to minimize the motor losses. You can download this model in MATLAB® or access it from MATLAB Central File Exchange and GitHub®.

### Example Overview

In this example, you learn how to:

• Determine the open-loop frequency response of the PMSM drive.

• Check the stability margins.

• Determine the optimal d-axis and q-axis currents that minimize the motor losses when delivering a commanded torque and speed.

For more information, follow these steps to explore the Simulink™ model that opens or see Motor Efficiency Improvements With Optimized Control Parameters (MATLAB Central File Exchange).

Clone the up-to-date repository in the current folder using the gitclone function.

gitclone("https://github.com/mathworks/pmsm-drive-optimization");

### Open Project

After you use the gitclone function, MATLAB creates a new folder in the current folder. This example uses projects to manage the supporting files. Open the PmsmDriveOptimization project file. If you have any projects open, MATLAB closes them before loading this project. Configuring the project environment takes several minutes because the model has hundreds of supporting files.

openProject("pmsm-drive-optimization");

### Explore Project

#### Drive System

The top-level model includes the PMSM drive with FOC that connects to a mechanical load. A test scenario simulates the motor power losses for both unoptimized and optimized controllers.

The drive parameterizes a 70 kW (maximum power), 150 Nm (maximum torque) motor suitable for an electric vehicle powertrain. The supply is a direct-current (DC) source of 500 V.

#### PMSM Field-Oriented Controller System

Look under the mask of the PMSM Controller subsystem. This subsystem models the architecture of the FOC. The FOC comprises an outer loop of speed control and an inner loop of current control. The outer loop determines the current references for the inner loop.

#### Motor Loss Map

The motor losses depend on the d-axis current, q-axis current, and rotor speed. The motor losses are a combination of copper losses and iron losses.

#### Optimal Field Currents

To compute the optimal d-axis and q-axis current references that minimize the motor losses use the ControllerOptimization.mlx file. The optimal field currents and motor losses are functions of the rotor speed and reference torque.

#### PMSM Frequency Response Estimation

The FreqResponseAnalysis.mlx file allows you to perform a frequency response estimation of the inner current control loop and the outer velocity control loop of the FOC. You can then assess the stability margin and speed of the two closed loops from the resulting Bode plot of the inner and outer open-loop transfer functions. You can iteratively adjust the gains of the controllers in the SystemParams.m script to achieve the desired stability margins.

This figure shows the Bode diagram of the inner control loop of the FOC. The FOC achieves a good stability in closed loop, with a phase margin above 60 degrees and a bandwidth above 5500 rad/s.

#### Power Losses for Step Load

The test scenario is a reference speed of 3000 rpm and a torque load that steps from 0 Nm to 50 Nm at 0.1 seconds. To run this test scenario and plot the results, at the MATLAB® Command Window, run:

plotSystemLossesOriginalAndOptimal;

The power loss in the PMSM drive with the optimal FOC are lower than the losses in the same PMSM drive with the unoptimized FOC.

To find the latest examples from the MathWorks Simscape Team, see MathWorks Simscape Team on MATLAB Central.