Student Lounge

Sharing technical and real-life examples of how students can use MATLAB and Simulink in their everyday projects #studentsuccess

Modeling and Simulation of a Modern HVAC System

In this blog, I am thrilled to introduce the outstanding work of Selim Karaoglu, who was a student at Cologne University of Applied Sciences at the time he entered and won our inaugural Sustainability and Renewable Energy Challenge, part of the MathWorks Challenge Projects program!
Selim’s project, a sophisticated Simulink® simulation of an advanced HVAC system tailored for a typical 4-room apartment in Germany, addresses thermal dynamics and air quality management to ensure the comfort of a family of four. Selim’s work explores innovative methods to make a sustainable living environment.
Since winning the challenge, Selim has made the transition from academia to the professional world, where he is now making his mark as a software engineer.
Join me as we explore the details of Selim’s winning solution and celebrate his achievement in pushing the boundaries of energy efficiency and control engineering in residential HVAC systems.

A quote from Selim about his personal experience:

“Winning the 2023 MathWorks Sustainability and Renewable Energy Challenge was a pivotal moment in my journey towards promoting sustainability, particularly within the realm of HVAC (Heating, Ventilation, and Air Conditioning) systems. As the sole contributor to the project, I delved deep into the intricacies of renewable energy solutions, recognizing the critical role HVAC systems play in energy consumption and environmental impact. I got the chance to further deepen my knowledge in the domain of thermodynamic system model and general control system design. Special thanks to Roberto Valenti from MathWorks, whose invaluable guidance enhanced our approach, emphasizing the significance of HVAC systems in achieving sustainable energy goals. Winning this esteemed challenge underscored the potential of innovative HVAC solutions to mitigate carbon emissions and foster a greener future. This experience has further fueled my commitment to advancing sustainable practices and technologies, driving positive change for generations to come.”
Take a look at the student’s submission GitHub repository open-in-matlab-online.gif.

Introduction and Motivation

The objective of the project was to simulate a contemporary HVAC system and develop a controller aimed at enhancing heating, cooling, ventilation, air quality, and energy efficiency, thereby contributing to the design and control of modern homes and buildings to preserve energy and promote healthy living environments.
The motivation behind the project stems from the societal imperative to construct buildings and homes that prioritize energy efficiency and the well-being of their occupants. This endeavor presents a significant challenge, necessitating the implementation of devices capable of effectively regulating air temperature, humidity, and quality while concurrently minimizing energy consumption. Central to this challenge is the development of systems and controllers capable of harmonizing these diverse objectives. Leveraging modeling, simulation, and control methodologies becomes crucial in the pursuit of optimized solutions.
Due to the varying implementations of HVAC systems across different countries, which are influenced by factors such as climate, cultural preferences, building codes, energy availability, economic considerations, etc., a decision was made to tailor the use case to the country of origin of the project worker, Germany. This approach ensures the development of the most optimal and realistic HVAC system design for this specific context.
Since 2020, Germany has pursued a dual strategy of transitioning to renewable energy while enhancing energy efficiency in residential buildings. This commitment is reflected in policies such as the Renewable Energy Sources Act and the Energy Saving Ordinance, which aim to increase renewable energy capacity and improve energy performance standards for buildings. By incentivizing investments in energy-saving measures and promoting the use of renewable energy technologies, Germany seeks to reduce both overall energy consumption and greenhouse gas emissions. Despite challenges such as retrofitting older buildings and addressing affordability concerns, Germany remains steadfast in its goal of achieving a sustainable and low-carbon energy future [1].

Main Part

The subsequent sections will delve into the project framework, the modeling and simulation of the apartment, the development of the HVAC system, and the obtained results.


In Germany, the housing landscape is predominantly characterized by a mix of rental apartments and single-family homes, with approximately 60% of the population residing in rented accommodations [2]. Single-family homes, including detached houses and semi-detached dwellings, also constitute a significant portion of the housing stock, accommodating a sizable segment of the population (ibid). The average household size in Germany has been gradually decreasing over time, currently standing at approximately 2.1 persons per household (ibid). The average size of apartments and the number of rooms vary depending on the region and type of accommodation. According to a study by Immowelt in 2021 [3], the average apartment size in Germany is approximately 87 square meters. The average number of rooms per apartment is around three to four rooms [1].
The most common type of apartments in Germany are multi-family houses, so called “Mehrfamilienhäuser”. These are apartment buildings with multiple units, typically ranging from two to several floors. Multi-family houses accommodate a significant portion of the population, particularly in urban areas (see Figure 1).
Figure 1: Typical German Apartment Block in Berlin-Neukölln, Germany[4]
Deriving from the mentioned facts it was decided on to model a 3-room apartment with an area of 108.8 m², which is located in the middle floor to additionally add complexity in forms of heat exchange with the apartment from below and above (see Figure 2). To add intricacy to the simulation, the apartment would accommodate a family of four, comprising two parents and two children. With each member having distinct daily routines, they would occupy different rooms at various times throughout the day. Specifically, the first and second bedrooms, along with the living room, would be equipped with climate control systems to regulate temperature and air quality (see Figure 3).
Figure 2: Layout of modelled apartment
To enhance the realism of the model, real outdoor temperatures were integrated, sourced from data provided by the German Meteorological Service. (see:
Following simplification were done for the model:
  • No open windows
  • No closed doors
  • No furniture
  • Constant value of air density at 20 °C
Figure 3: (left): Overview of climatized rooms, (right): Path of air flow by air handling unit. Fresh and new air gets introduced from bedroom 1, 2 and the living room and gets blown out from the bathroom and the kitchen.

Model & Simulation of Apartment

The model of the thermodynamic and moist air properties of the apartment can be obtained from Figure 4. As you can see the inputs of the system are the outside temperature T_OUT and the initial room temperature T_ENV. All rooms are connected via the moisture air and thermal domain nodes of Simscape™. In the thermal domain, the thermal masses of each room, including the room air mass, are linked via thermal resistances, simulating the walls that separate the rooms. This accounts for the heat transfer between the inner walls, outer walls, and windows of the apartment. In the moist air domain, the volumes of moist air in each room are interconnected, reflecting the assumption that all doors within the apartment are open during the simulation, facilitating optimal airflow.
Figure 4: Simulink model of apartment
The moisture in each room is variated in relations to the number of occupants in the room and the CO2 breathed out. Also the heat dissipation of each occupant is included in the simulation.

HVAC unit

To achieve optimal temperature and air quality control, a combination of a PI controller and Stateflow® control, supplemented by a lookup table was developed. The HVAC unit controls following system specifications for following variable in the:
  1. Temperature: Optimal temperature range is from 16 to 24.5 °C
  2. Humidity: Optimal humidity range is from 20 to 82 %
  3. Air-quality(quantified by CO2-levels in the air): CO2-levels should be kept under 2000 ppm
To ensure all these requirements are met, the system can be affected by following manipulated variables:
  1. Air flow: The amount of air introduced in and ejected out from the apartment.
  2. Heating power: The amount of heat introduced.
  3. Cooling power: The amount of cooling introduced.
The PI controller regulates the heating and cooling power supplied by the air conditioning units based on the targeted room temperature, while the Stateflow controller manages the airflow into and out of the space according to external temperature and humidity conditions. To fine-tune the PI controller, we utilized the PID Tuner app from the Control System Toolbox™, adjusting for a damped time response to achieve the quickest possible reaction time.The adjustment of the air handling unit control was based on the data presented in Figure 5, illustrating the optimal temperature and humidity range for human comfort.
Figure 5: Look-Up Table Data for Air Handler Unit Control[5]
Figure 6 displays the lookup table utilized for this purpose. When outdoor temperature and humidity levels deviate from the comfort zone, the air handling unit is deactivated to prevent mixing air masses with differing moist air properties, which could lead to humidity levels in the room air straying from the recommended comfort zone. To reinforce this requirement, a Stateflow safety control was implemented, deactivating the air conditioning units if indoor humidity levels exceed 85% (see Figure 7).
Figure 6: Lookup table parametrization
Figure 7: Stateflow logic for control of humidity levels


A simulation showcasing the hottest day in Cologne, Germany, in 2023 is presented (refer to the video object below). The PI controller effectively maintains the temperatures in bedroom 1, 2, and the living room at a near-constant reference temperature of 20°C. However, occasional temperature increases occur due to the dehumidifier. When humidity levels exceed the threshold, the controller is deactivated, leading to rising indoor temperatures influenced by the higher outdoor temperatures. The humidity levels in the three crucial rooms reach their maximum limit of 85%, while CO2 levels are mostly maintained below the threshold of 2000 ppm.


In conclusion, the development and simulation of a modern HVAC system for a German apartment, as part of the MathWorks Sustainability and Renewable Energy Challenge, exemplify the intersection of technology and sustainability. Through meticulous modeling and control design, the project aimed not only to optimize indoor comfort but also to minimize energy consumption and promote environmental responsibility. By leveraging advanced tools and methodologies provided by MathWorks, such as Simscape and Stateflow, Selim was able to create a comprehensive solution tailored to the specific context of energy-efficient building design in Germany. The results showcased the efficacy of the developed HVAC system in maintaining optimal indoor conditions while adhering to sustainability goals, as evidenced by simulations conducted under various environmental conditions. This project underscores the pivotal role of innovative HVAC solutions in mitigating climate change and advancing towards a greener future. Moving forward, the insights gained from this endeavor will continue to inform and inspire efforts to revolutionize building energy systems for enhanced sustainability worldwide.
[1] BMWK (2021). “Renewable Energy Sources Act.” Federal Ministry for Economic Affairs and Climate Action. [Online]. Available:
[2] Destatis (2022). “Housing and Real Estate.” Federal Statistical Office. [Online]. Available:
[3] Immowelt (2021). “Housing Price Development in Germany.” Immowelt AG. [Online]. Available:
[4] Guthmann Estate GmbH (2024). “Neukölln Nähe Tempelhofer Freiheit: Sehr gepflegtes Mehrfamilienhaus mit Remise.” Guthmann Estate GmbH [Online]. Available:
[5] Och, Fabian et. al (2017). ” Building and HVAC Simulation in MATLAB/Simulink – FFG Project SaLüH!.” MATLAB Expo 2017 [Online]. Available:

  • print


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.