├── .gitattributes ├── .gitignore ├── Microgrid_24h_Simulation.mdl ├── README.md ├── dataBase ├── Insolation1.mat ├── Insolation2.mat ├── Insolation3.mat ├── PowerAIntermediate.mat ├── PowerAMonsoon.mat ├── PowerAWinter.mat ├── PowerAllIntermediate.mat ├── PowerAllMonsoon.mat ├── PowerAllWinter.mat ├── PowerBIntermediate.mat ├── PowerBMonsoon.mat ├── PowerBWinter.mat ├── PowerCIntermediate.mat ├── PowerCMonsoon.mat ├── PowerCWinter.mat ├── PowerDIntermediate.mat ├── PowerDMonsoon.mat ├── PowerDWinter.mat ├── PowerEIntermediate.mat ├── PowerEMonsoon.mat ├── PowerEWinter.mat ├── PowerLHIntermediate.mat ├── PowerLHMonsoon.mat ├── PowerLHWinter.mat ├── PowerRHIntermediate.mat ├── PowerRHMonsoon.mat ├── PowerRHWinter.mat └── SampleT.mat ├── img ├── Battery.bmp ├── Light.bmp ├── Photo.bmp ├── Plug.bmp └── bhutan.jpg └── src ├── GraphsSim.m ├── IncCondSim.m ├── Main.m ├── PhotovoltaicSim.m ├── Supervision.m ├── iconRead.m └── mi_psbfft_scope_THD.m /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io 2 | 3 | ### Matlab ### 4 | ##--------------------------------------------------- 5 | ## Remove autosaves generated by the Matlab editor 6 | ## We have git for backups! 7 | ##--------------------------------------------------- 8 | 9 | # Windows default autosave extension 10 | *.asv 11 | 12 | # OSX / *nix default autosave extension 13 | *.m~ 14 | 15 | # Compiled MEX binaries (all platforms) 16 | *.mex* 17 | 18 | # Simulink Code Generation 19 | slprj/ 20 | 21 | 22 | ### OSX ### 23 | .DS_Store 24 | .AppleDouble 25 | .LSOverride 26 | 27 | # Icon must end with two \r 28 | Icon 29 | 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | 49 | 50 | ### Windows ### 51 | # Windows image file caches 52 | Thumbs.db 53 | ehthumbs.db 54 | 55 | # Folder config file 56 | Desktop.ini 57 | 58 | # Recycle Bin used on file shares 59 | $RECYCLE.BIN/ 60 | 61 | # Windows Installer files 62 | *.cab 63 | *.msi 64 | *.msm 65 | *.msp 66 | 67 | # Windows shortcuts 68 | *.lnk 69 | 70 | 71 | ### Linux ### 72 | *~ 73 | 74 | # KDE directory preferences 75 | .directory 76 | 77 | # Linux trash folder which might appear on any partition or disk 78 | .Trash-* 79 | 80 | 81 | -------------------------------------------------------------------------------- /Microgrid_24h_Simulation.mdl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/Microgrid_24h_Simulation.mdl -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 24 hours simulation of a microgrid 2 | This is a complete model of a microgrid including the power sources, their power electronics, a load and mains model using MatLab and Simulink. The model is based on Faisal Mohamed's master thesis, Microgrid Modelling and Simulation. 3 | 4 | ## What is a microgrid 5 | The microgrid simulated use a group of electricity sources and loads to work disconnected from any centralized grid (macrogrid) and function autonomously to provide power to its local area. The simulation models the microgrid at steady state to analyse their transient response to changing input. 6 | 7 | ## Purpose of this simulation 8 | Design tools are needed to build the prototype PV-microgrid at the College of Science and Technology in Bhutan. This project will be supporting this Microgrid at CST by proposing a design tool that can 9 | * Identify optimal microgrid structure and composition. 10 | * Give a full year simulation of the system, with measurements on load, production, voltage and frequency. 11 | * Give methods for simplifying the planning and resource-assessment phase. 12 | 13 | ## How to run 14 | Open the folder simulink-microgrid then open the simulink file 'Microgrid_24h_Simulation.mdl' and in the subfolder src open the file 'main.mat'. You can now, run the 'main.mat' file and follow the instructions (Be careful, you have to open the simulink before you can run the main file). 15 | 16 | ## Compiling 17 | The time of the compilation is greatly impacted by the performance of your computer. 18 | 19 | ## Supported operating systems 20 | Windows, Linux and Mac are supported by this simulation. When you run the 'main.mat' file, a popup box let you choose between different OS. 21 | 22 | ## Input Data of the simulink 23 | The different inputs data are located in the file simulink-microgrid/database. 24 | 25 | ## To Do 26 | 27 | - [x] The simulation crashes. 28 | - [ ] Enhance the readme 29 | * Explain how to run the simulation 30 | * Write about compiling 31 | * write about supported operating systems 32 | * Add usefull links to prior knowledge for this simulation, such as using excel and matlab together. 33 | - [x] Create a GUI in order to control and visualize the simulation 34 | - [x] Make the GUI dynamic 35 | - [ ] Implement the integration of a backup in the simulink 36 | - [ ] Create a wiki 37 | - [x] Testing 38 | * Run a complete simulation and analyse the results. 39 | - [x] Simulation crashed - find error 40 | - [ ] Add support for multi-core. 41 | - [x] Add OS X support 42 | - [ ] Run simulation on OS X 43 | - [ ] Check the name of the previous master thesis 44 | -------------------------------------------------------------------------------- /dataBase/Insolation1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/Insolation1.mat -------------------------------------------------------------------------------- /dataBase/Insolation2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/Insolation2.mat -------------------------------------------------------------------------------- /dataBase/Insolation3.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/Insolation3.mat -------------------------------------------------------------------------------- /dataBase/PowerAIntermediate.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerAIntermediate.mat -------------------------------------------------------------------------------- /dataBase/PowerAMonsoon.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerAMonsoon.mat -------------------------------------------------------------------------------- /dataBase/PowerAWinter.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerAWinter.mat -------------------------------------------------------------------------------- /dataBase/PowerAllIntermediate.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerAllIntermediate.mat -------------------------------------------------------------------------------- /dataBase/PowerAllMonsoon.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerAllMonsoon.mat -------------------------------------------------------------------------------- /dataBase/PowerAllWinter.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerAllWinter.mat -------------------------------------------------------------------------------- /dataBase/PowerBIntermediate.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerBIntermediate.mat -------------------------------------------------------------------------------- /dataBase/PowerBMonsoon.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerBMonsoon.mat -------------------------------------------------------------------------------- /dataBase/PowerBWinter.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerBWinter.mat -------------------------------------------------------------------------------- /dataBase/PowerCIntermediate.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerCIntermediate.mat -------------------------------------------------------------------------------- /dataBase/PowerCMonsoon.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerCMonsoon.mat -------------------------------------------------------------------------------- /dataBase/PowerCWinter.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerCWinter.mat -------------------------------------------------------------------------------- /dataBase/PowerDIntermediate.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerDIntermediate.mat -------------------------------------------------------------------------------- /dataBase/PowerDMonsoon.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerDMonsoon.mat -------------------------------------------------------------------------------- /dataBase/PowerDWinter.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerDWinter.mat -------------------------------------------------------------------------------- /dataBase/PowerEIntermediate.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerEIntermediate.mat -------------------------------------------------------------------------------- /dataBase/PowerEMonsoon.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerEMonsoon.mat -------------------------------------------------------------------------------- /dataBase/PowerEWinter.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerEWinter.mat -------------------------------------------------------------------------------- /dataBase/PowerLHIntermediate.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerLHIntermediate.mat -------------------------------------------------------------------------------- /dataBase/PowerLHMonsoon.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerLHMonsoon.mat -------------------------------------------------------------------------------- /dataBase/PowerLHWinter.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerLHWinter.mat -------------------------------------------------------------------------------- /dataBase/PowerRHIntermediate.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerRHIntermediate.mat -------------------------------------------------------------------------------- /dataBase/PowerRHMonsoon.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerRHMonsoon.mat -------------------------------------------------------------------------------- /dataBase/PowerRHWinter.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/PowerRHWinter.mat -------------------------------------------------------------------------------- /dataBase/SampleT.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/dataBase/SampleT.mat -------------------------------------------------------------------------------- /img/Battery.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/img/Battery.bmp -------------------------------------------------------------------------------- /img/Light.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/img/Light.bmp -------------------------------------------------------------------------------- /img/Photo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/img/Photo.bmp -------------------------------------------------------------------------------- /img/Plug.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/img/Plug.bmp -------------------------------------------------------------------------------- /img/bhutan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/img/bhutan.jpg -------------------------------------------------------------------------------- /src/GraphsSim.m: -------------------------------------------------------------------------------- 1 | 2 | %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | %%% %%% 4 | %%% SIMULATION VARIABLES GRAPHS %%% 5 | %%% %%% 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | 8 | % All voltages are RED colour 9 | % All currents are BLUE colour 10 | % All powers are BLACK colour 11 | 12 | %% PV ARRAY 13 | 14 | figure(1) 15 | % % Irradiance 16 | subplot(4,1,1); 17 | plot(t,Irr,'g','linewidth',2) 18 | grid on 19 | title('Irradiance') 20 | ylabel('[KW/m^2]','fontsize',12) 21 | % PV Array Voltage 22 | subplot(4,1,2); 23 | plot(t,Vpv,'r','linewidth',2) 24 | grid on 25 | title('PV Array Voltage') 26 | ylabel('[V]','fontsize',12) 27 | % PV Array Current 28 | subplot(4,1,3);plot(t,Ipv_array,'b','linewidth',2) 29 | grid on 30 | title('PV Array Current') 31 | ylabel('[A]','fontsize',12) 32 | % PV Array Power 33 | subplot(4,1,4); 34 | plot(t,Ppv/1000,'k','linewidth',2) 35 | grid on 36 | title('PV Array Power') 37 | ylabel('[kW]','fontsize',12) 38 | xlabel('Time [s]','fontsize',12) 39 | 40 | %% DCDC BOOST CONVERTER CONTROL 41 | 42 | figure(2) 43 | % Reference voltage 44 | subplot(2,1,1); 45 | plot(t,Vref,'r','linewidth',2) 46 | grid on 47 | title('Reference Voltage') 48 | ylabel('[V]','fontsize',12) 49 | % Delta 50 | subplot(2,1,2); 51 | plot(t,delta,'b','linewidth',2) 52 | grid on 53 | title('Delta') 54 | xlabel('Time [s]','fontsize',12) 55 | 56 | %% DC BUS PV SIDE 57 | 58 | figure(3) 59 | % DC Bus Voltage 60 | subplot(3,1,1); 61 | plot(t,Vbus,'r','linewidth',2) 62 | grid on 63 | title('DC Bus Voltage PV Side') 64 | ylabel('[V]','fontsize',12) 65 | % DC Bus Current 66 | subplot(3,1,2);plot(t,Ibus1,'b','linewidth',2) 67 | grid on 68 | title('DC Bus Current PV Side') 69 | ylabel('[A]','fontsize',12) 70 | % DC Bus Power 71 | subplot(3,1,3); 72 | plot(t,Pbus/1000,'k','linewidth',2) 73 | grid on 74 | title('DC Bus Power PV Side') 75 | ylabel('[kW]','fontsize',12) 76 | xlabel('Time [s]','fontsize',12) 77 | 78 | %% DC LOAD 79 | 80 | figure(4) 81 | % DC Load Voltage 82 | subplot(3,1,1) 83 | plot(t,Vload,'r','linewidth',2) 84 | grid on 85 | title('DC Load Voltage') 86 | ylabel('[V]','fontsize',12) 87 | % DC Load Current 88 | subplot(3,1,2) 89 | plot(t,Iload,'b','linewidth',2) 90 | grid on 91 | title('DC Load Current') 92 | ylabel('[A]','fontsize',12) 93 | % DC Load Power 94 | subplot(3,1,3) 95 | plot(t,Pload/1000,'k','linewidth',2) 96 | grid on 97 | title('DC Load Power') 98 | ylabel('[kW]','fontsize',12) 99 | xlabel('Time [s]','fontsize',12) 100 | 101 | %% DC BUS BATTERY SIDE 102 | 103 | figure(5) 104 | % DC to Battery Voltage 105 | subplot(3,1,1) 106 | plot(t,Vdc,'r','linewidth',2) 107 | grid on 108 | title('DC Bus Voltage Battery Side') 109 | ylabel('[V]','fontsize',12) 110 | % DC to Battery Current 111 | subplot(3,1,2) 112 | plot(t,Idc1,'b','linewidth',2) 113 | grid on 114 | title('DC Bus Current Battery Side') 115 | ylabel('[A]','fontsize',12) 116 | % DC to Battery Power 117 | subplot(3,1,3) 118 | plot(t,Pdc/1000,'k','linewidth',2) 119 | grid on 120 | title('DC Bus Power Battery Side') 121 | ylabel('[kW]','fontsize',12) 122 | xlabel('Time [s]','fontsize',12) 123 | 124 | %% BATTERY 125 | 126 | figure(6) 127 | % Battery SOC 128 | subplot(4,1,1) 129 | plot(t,SOC,'g','linewidth',2) 130 | grid on 131 | title('Battery SOC') 132 | ylabel('[%]','fontsize',12) 133 | % Battery Voltage 134 | subplot(4,1,2) 135 | plot(t,Vbat,'r','linewidth',2) 136 | grid on 137 | title('Battery Voltage') 138 | ylabel('[V]','fontsize',12) 139 | % Battery Current 140 | subplot(4,1,3) 141 | plot(t,Ibat,'b','linewidth',2) 142 | grid on 143 | title('Battery Current') 144 | ylabel('[A]','fontsize',12) 145 | % Battery Power 146 | subplot(4,1,4) 147 | plot(t,Pbat/1000,'k','linewidth',2) 148 | grid on 149 | title('Battery Power') 150 | ylabel('[kW]','fontsize',12) 151 | xlabel('Time [s]','fontsize',12) 152 | 153 | %% DCDC BIDIRECTIONAL CONVERTER CONTROL 154 | 155 | figure(7) 156 | % DC Bus Voltage Controller 157 | subplot(2,1,1) 158 | plot(t,Vdc_ref,'r','linewidth',2) 159 | grid on 160 | hold on 161 | plot(t,Vdc,'b','linewidth',2) 162 | ylabel('[V]','fontsize',12) 163 | legend('Reference','Real') 164 | title('DC Bus Controller') 165 | % Battery Current Controller 166 | subplot(2,1,2) 167 | plot(t,Ibat_ref,'r','linewidth',2) 168 | grid on 169 | hold on 170 | plot(t,Ibat,'b','linewidth',2) 171 | ylabel('[A]','fontsize',12) 172 | legend('Reference','Real') 173 | title('Battery Current Controller') 174 | xlabel('Time [s]','fontsize',12) 175 | 176 | %% AC LOAD 177 | 178 | figure(8) 179 | % AC Load Voltage 180 | subplot(2,1,1); 181 | plot(t,Vab,'r','linewidth',2) 182 | grid on 183 | hold on 184 | plot(t,Vbc,'b','linewidth',2) 185 | hold on 186 | plot(t,Vca,'g','linewidth',2) 187 | title('AC Load Voltage') 188 | ylabel('[V]','fontsize',12) 189 | % AC Load Current 190 | subplot(2,1,2); 191 | plot(t,Ia,'r','linewidth',2) 192 | hold on 193 | plot(t,Ib,'b','linewidth',2) 194 | hold on 195 | plot(t,Ic,'g','linewidth',2) 196 | grid on 197 | title('AC Load Current') 198 | ylabel('[A]','fontsize',12) 199 | xlabel('Time [s]','fontsize',12) 200 | 201 | figure(9) 202 | % Frequency 203 | subplot(2,1,1) 204 | plot(t,f_ref,'r','linewidth',2) 205 | grid on 206 | ylabel('[Hz]','fontsize',12) 207 | title('Frequency Reference') 208 | subplot(2,1,2) 209 | plot(t,fabc_real_fil,'b','linewidth',2) 210 | grid on 211 | ylabel('[Hz]','fontsize',12) 212 | title('Frequency') 213 | xlabel('Time [s]','fontsize',12) 214 | 215 | figure(10) 216 | % AC Load Active Power 217 | subplot(2,1,1); 218 | plot(t,Pacload/1000,'k','linewidth',2) 219 | grid on 220 | title('AC Load Active Power') 221 | ylabel('[kW]','fontsize',12) 222 | % AC Load Reactive Power 223 | subplot(2,1,2); 224 | plot(t,Qacload/1000,'k','linewidth',2) 225 | grid on 226 | title('AC Load Reactive Power') 227 | ylabel('[kVAr]','fontsize',12) 228 | xlabel('Time [s]','fontsize',12) 229 | 230 | %% INVERTER CONTROL 231 | 232 | figure(11) 233 | % Voltage and frequency references 234 | subplot(2,1,1) 235 | plot(t,Vabc_ref,'r','linewidth',2) 236 | grid on 237 | ylabel('[V]','fontsize',12) 238 | title('Voltage Reference') 239 | subplot(2,1,2) 240 | plot(t,f_ref,'b','linewidth',2) 241 | grid on 242 | ylabel('[Hz]','fontsize',12) 243 | title('Frequency Reference') 244 | xlabel('Time [s]','fontsize',12) 245 | 246 | figure(12) 247 | % Voltage Control Loop 248 | subplot(2,1,1) 249 | plot(t,vd,'b','linewidth',2) 250 | grid on 251 | hold on 252 | plot(t,vd_ref,'r','linewidth',2) 253 | ylabel('[V]','fontsize',12) 254 | legend('Real','Reference') 255 | title('Voltage Control Loop D Reference Frame') 256 | subplot(2,1,2) 257 | plot(t,vq,'b','linewidth',2) 258 | grid on 259 | hold on 260 | plot(t,vq_ref,'r','linewidth',2) 261 | ylabel('[V]','fontsize',12) 262 | legend('Real','Reference') 263 | title('Voltage Control Loop Q Reference Frame') 264 | xlabel('Time [s]','fontsize',12) 265 | 266 | figure(13) 267 | % Current Control Loop 268 | subplot(2,1,1) 269 | plot(t,id,'b','linewidth',2) 270 | grid on 271 | hold on 272 | plot(t,id_ref,'r','linewidth',2) 273 | ylabel('[A]','fontsize',12) 274 | legend('Real','Reference') 275 | title('Current Control Loop D Reference Frame') 276 | subplot(2,1,2) 277 | plot(t,iq,'b','linewidth',2) 278 | grid on 279 | hold on 280 | plot(t,iq_ref,'r','linewidth',2) 281 | ylabel('[A]','fontsize',12) 282 | legend('Real','Reference') 283 | title('Current Control Loop Q Reference Frame') 284 | xlabel('Time [s]','fontsize',12) 285 | 286 | %% DC BUS INVERTER SIDE 287 | 288 | figure(14) 289 | % DC Bus Voltage 290 | subplot(3,1,1); 291 | plot(t,Vdcinv1,'r','linewidth',2) 292 | grid on 293 | title('DC Bus Voltage Inverter Side') 294 | ylabel('[V]','fontsize',12) 295 | % DC Bus Current 296 | subplot(3,1,2);plot(t,Idcinv1,'b','linewidth',2) 297 | grid on 298 | title('DC Bus Current Inverter Side') 299 | ylabel('[A]','fontsize',12) 300 | % DC Bus Power 301 | subplot(3,1,3); 302 | plot(t,Pdcinv1/1000,'k','linewidth',2) 303 | grid on 304 | title('DC Bus Power Inverter Side') 305 | ylabel('[kW]','fontsize',12) 306 | xlabel('Time [s]','fontsize',12) 307 | 308 | %% SYSTEM POWERS 309 | 310 | figure(15) 311 | % PV Power 312 | subplot(4,1,1); 313 | plot(t,Ppv/1000,'k','linewidth',2) 314 | grid on 315 | title('PV Power') 316 | ylabel('[kW]','fontsize',12) 317 | % Battery Power 318 | subplot(4,1,2); 319 | plot(t,Pbat/1000,'k','linewidth',2) 320 | grid on 321 | title('Battery Power') 322 | ylabel('[kW]','fontsize',12) 323 | % DC Load Power 324 | subplot(4,1,3); 325 | plot(t,Pload/1000,'k','linewidth',2) 326 | grid on 327 | title('DC Load Power') 328 | ylabel('[kW]','fontsize',12) 329 | % AC Load Power 330 | subplot(4,1,4); 331 | plot(t,Pacload/1000,'k','linewidth',2) 332 | grid on 333 | title('AC Load Power') 334 | ylabel('[kW]','fontsize',12) 335 | xlabel('Time [s]','fontsize',12) 336 | 337 | %% LOAD POWERS 338 | 339 | figure(16) 340 | % DC Load Power 341 | subplot(2,1,1); 342 | plot(t,Pload/1000,'k','linewidth',2) 343 | grid on 344 | title('DC Load Power') 345 | ylabel('[kW]','fontsize',12) 346 | % AC Load Power 347 | subplot(2,1,2); 348 | plot(t,Pacload/1000,'k','linewidth',2) 349 | grid on 350 | title('AC Load Power') 351 | ylabel('[kW]','fontsize',12) 352 | xlabel('Time [s]','fontsize',12) 353 | 354 | %% GENERATION POWERS 355 | 356 | figure(17) 357 | % PV Power 358 | subplot(2,1,1); 359 | plot(t,Ppv/1000,'k','linewidth',2) 360 | grid on 361 | title('PV Power') 362 | ylabel('[kW]','fontsize',12) 363 | % Battery Power 364 | subplot(2,1,2); 365 | plot(t,Pbat/1000,'k','linewidth',2) 366 | grid on 367 | title('Battery Power') 368 | ylabel('[kW]','fontsize',12) 369 | xlabel('Time [s]','fontsize',12) 370 | -------------------------------------------------------------------------------- /src/IncCondSim.m: -------------------------------------------------------------------------------- 1 | function [delta,Vref,Ipv_prev_out,Vpv_prev_out] = IncCond(Ipv,Iprevious,Vpv,Vprevious,Vref_previous) 2 | 3 | % REFERENCE PAPERS: 4 | % Trishan Esram, Patrick L. Chapman, "Comparison of Photovoltaic Array 5 | % Maximum Power Tracking Techniques", IEEE Transactions on Energy 6 | % COnversion, vol. 22, issue 2, June 2007. 7 | % 8 | % M. Lokanadham, K. Vijaya Bhaskar, "Incremental Conductance Based Maximum 9 | % Power Point Tracking (MPPT) for Photovoltaic System" International 10 | % Journal of Engineering Research and Applications (IJERA), vol. 2, issue 11 | % 2, March-April 2012. 12 | 13 | 14 | % The followoing code is an algorithm for a Maximum Power Point Tracking 15 | % (MPPT) technique Incremental COnductance 16 | 17 | Vbus = 500; 18 | 19 | dI=Ipv-Iprevious; 20 | dV=Vpv-Vprevious; 21 | 22 | if (dV==0) 23 | if (dI==0) 24 | Vref=Vref_previous; 25 | else 26 | if (Ipv>0) 27 | Vref= Vpv+dV; 28 | else 29 | Vref= Vpv-dV; 30 | end 31 | end 32 | else 33 | if ((dI/dV)==(-Ipv/Vpv)) 34 | Vref=Vref_previous; 35 | else 36 | if ((dI/dV)>(-Ipv/Vpv)) 37 | Vref= Vpv+dV; 38 | else 39 | Vref= Vpv-dV; 40 | end 41 | end 42 | end 43 | Ipv_prev_out=Ipv; 44 | Vpv_prev_out=Vpv; 45 | 46 | delta=1-Vref/Vbus; 47 | 48 | end 49 | -------------------------------------------------------------------------------- /src/Main.m: -------------------------------------------------------------------------------- 1 | 2 | %%%%%%%%%%%%%%%% 3 | % Main program %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | %%%%%%%%%%%%%%%% 5 | 6 | % Construct a questdlg with two options 7 | choice = questdlg('Hello, please choose your Operating System?', ... 8 | 'Operating System', ... 9 | 'Mac','Windows','Linux',''); 10 | 11 | % Handle response 12 | global os 13 | switch choice 14 | case 'Mac' 15 | os = 1; 16 | case 'Windows' 17 | os = 2; 18 | case 'Linux' 19 | os=1; 20 | end 21 | 22 | % Create the data insolation to plot from excel 23 | SampleTime=0.1; 24 | xdiscretized=1:SampleTime:24; 25 | Insolation_data = normpdf(xdiscretized,12,1.7); % Normal law 26 | Ins_Monsoon=Insolation_data*3990; 27 | Ins_Intermediate=Insolation_data*4583; 28 | Ins_Winter=Insolation_data*4888; 29 | 30 | % Path choise according the OS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 31 | 32 | if os==1 33 | 34 | % Import data from the files for Mac % 35 | 36 | customerAllMonsoon=importdata('dataBase/PowerAllMonsoon.mat'); % Data from excel Block All 37 | customerAllIntermediate=importdata('dataBase/PowerAllIntermediate.mat'); % Data from excel Block All 38 | customerAllWinter=importdata('dataBase/PowerAllWinter.mat'); % Data from excel Block All 39 | 40 | customerDMonsoon=importdata('dataBase/PowerDMonsoon.mat'); % Data from excel Block D 41 | customerDIntermediate=importdata('dataBase/PowerDIntermediate.mat'); % Data from excel Block D 42 | customerDWinter=importdata('dataBase/PowerDWinter.mat'); % Data from excel Block D 43 | 44 | customerEMonsoon=importdata('dataBase/PowerEMonsoon.mat'); % Data from excel Block E 45 | customerEIntermediate=importdata('dataBase/PowerEIntermediate.mat'); % Data from excel Block E 46 | customerEWinter=importdata('dataBase/PowerEWinter.mat'); % Data from excel Block E 47 | 48 | customerCMonsoon=importdata('dataBase/PowerCMonsoon.mat'); % Data from excel Block C 49 | customerCIntermediate=importdata('dataBase/PowerCIntermediate.mat'); % Data from excel Block C 50 | customerCWinter=importdata('dataBase/PowerCWinter.mat'); % Data from excel Block C 51 | 52 | customerAMonsoon=importdata('dataBase/PowerAMonsoon.mat'); % Data from excel Block A 53 | customerAIntermediate=importdata('dataBase/PowerAIntermediate.mat'); % Data from excel Block A 54 | customerAWinter=importdata('dataBase/PowerAWinter.mat'); % Data from excel Block A 55 | 56 | customerBMonsoon=importdata('dataBase/PowerBMonsoon.mat'); % Data from excel Block B 57 | customerBIntermediate=importdata('dataBase/PowerBIntermediate.mat'); % Data from excel Block B 58 | customerBWinter=importdata('dataBase/PowerBWinter.mat'); % Data from excel Block B 59 | 60 | customerLHMonsoon=importdata('dataBase/PowerLHMonsoon.mat'); % Data from excel Block LH 61 | customerLHIntermediate=importdata('dataBase/PowerLHIntermediate.mat'); % Data from excel Block LH 62 | customerLHWinter=importdata('dataBase/PowerLHWinter.mat'); % Data from excel Block LH 63 | 64 | customerRHMonsoon=importdata('dataBase/PowerRHMonsoon.mat'); % Data from excel Block RH 65 | customerRHIntermediate=importdata('dataBase/PowerRHIntermediate.mat'); % Data from excel Block RH 66 | customerRHWinter=importdata('dataBase/PowerRHWinter.mat'); % Data from excel Block RH 67 | 68 | Time=importdata('dataBase/SampleT.mat'); % SampleT.mat Data from excel 69 | jpg=imread('img/bhutan.jpg'); 70 | 71 | elseif os==2 72 | 73 | % Import data from the files for Window % 74 | 75 | customerAllMonsoon=importdata('dataBase\PowerAllMonsoon.mat'); % Data from excel Block All 76 | customerAllIntermediate=importdata('dataBase\PowerAllIntermediate.mat'); % Data from excel Block All 77 | customerAllWinter=importdata('dataBase\PowerAllWinter.mat'); % Data from excel Block All 78 | 79 | customerDMonsoon=importdata('dataBase\PowerDMonsoon.mat'); % Data from excel Block D 80 | customerDIntermediate=importdata('dataBase\PowerDIntermediate.mat'); % Data from excel Block D 81 | customerDWinter=importdata('dataBase\PowerDWinter.mat'); % Data from excel Block D 82 | 83 | customerEMonsoon=importdata('dataBase\PowerEMonsoon.mat'); % Data from excel Block E 84 | customerEIntermediate=importdata('dataBase\PowerEIntermediate.mat'); % Data from excel Block E 85 | customerEWinter=importdata('dataBase\PowerEWinter.mat'); % Data from excel Block E 86 | 87 | customerCMonsoon=importdata('dataBase\PowerCMonsoon.mat'); % Data from excel Block C 88 | customerCIntermediate=importdata('dataBase\PowerCIntermediate.mat'); % Data from excel Block C 89 | customerCWinter=importdata('dataBase\PowerCWinter.mat'); % Data from excel Block C 90 | 91 | customerAMonsoon=importdata('dataBase\PowerAMonsoon.mat'); % Data from excel Block A 92 | customerAIntermediate=importdata('dataBase\PowerAIntermediate.mat'); % Data from excel Block A 93 | customerAWinter=importdata('dataBase\PowerAWinter.mat'); % Data from excel Block A 94 | 95 | customerBMonsoon=importdata('dataBase\PowerBMonsoon.mat'); % Data from excel Block B 96 | customerBIntermediate=importdata('dataBase\PowerBIntermediate.mat'); % Data from excel Block B 97 | customerBWinter=importdata('dataBase\PowerBWinter.mat'); % Data from excel Block B 98 | 99 | customerLHMonsoon=importdata('dataBase\PowerLHMonsoon.mat'); % Data from excel Block LH 100 | customerLHIntermediate=importdata('dataBase\PowerLHIntermediate.mat'); % Data from excel Block LH 101 | customerLHWinter=importdata('dataBase\PowerLHWinter.mat'); % Data from excel Block LH 102 | 103 | customerRHMonsoon=importdata('dataBase\PowerRHMonsoon.mat'); % Data from excel Block RH 104 | customerRHIntermediate=importdata('dataBase\PowerRHIntermediate.mat'); % Data from excel Block RH 105 | customerRHWinter=importdata('dataBase\PowerRHWinter.mat'); % Data from excel Block RH 106 | 107 | Time=importdata('dataBase\SampleT.mat'); % SampleT.mat Data from excel 108 | jpg=imread('img\bhutan.jpg'); 109 | 110 | end 111 | 112 | % linear regression with a polynomial approach for the Active power of the load 113 | 114 | % Block All (Monsoon)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 115 | 116 | p = polyfit(Time,customerAllMonsoon,10); % Data choice from pushbutton SEASONS 117 | yfit1 = polyval(p,Time); 118 | yfitdiscretized1=polyval(p,xdiscretized); 119 | 120 | % Delete values below zero for the final curve for the Active power of the load 121 | nrows = 1; 122 | ncols = (23/SampleTime)+1; 123 | newyfitdiscretized1=yfitdiscretized1; 124 | r=1; 125 | for c = 1:ncols 126 | 127 | if yfitdiscretized1(r,c)<0 128 | newyfitdiscretized1(r,c) = 0; 129 | else 130 | newyfitdiscretized1(r,c)= yfitdiscretized1(r,c); 131 | end 132 | end 133 | 134 | % Block All (Intermediate) 135 | p = polyfit(Time,customerAllIntermediate,10); % Data choice from pushbutton SEASONS 136 | yfit2 = polyval(p,Time); 137 | yfitdiscretized2=polyval(p,xdiscretized); 138 | 139 | % Delete values below zero for the final curve for the Active power of the load 140 | newyfitdiscretized2=yfitdiscretized2; 141 | r=1; 142 | for c = 1:ncols 143 | 144 | if yfitdiscretized2(r,c)<0 145 | newyfitdiscretized2(r,c) = 0; 146 | else 147 | newyfitdiscretized2(r,c)= yfitdiscretized2(r,c); 148 | end 149 | end 150 | 151 | % Block All (Winter)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 152 | 153 | p = polyfit(Time,customerAllWinter,10); % Data choice from pushbutton SEASONS 154 | yfit3 = polyval(p,Time); 155 | yfitdiscretized3=polyval(p,xdiscretized); 156 | 157 | % Delete values below zero for the final curve for the Active power of the load 158 | nrows = 1; 159 | ncols = (23/SampleTime)+1; 160 | newyfitdiscretized3=yfitdiscretized3; 161 | r=1; 162 | for c = 1:ncols 163 | 164 | if yfitdiscretized3(r,c)<0 165 | newyfitdiscretized3(r,c) = 0; 166 | else 167 | newyfitdiscretized3(r,c)= yfitdiscretized3(r,c); 168 | end 169 | end 170 | 171 | % Block D (Monsoon)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 172 | 173 | p = polyfit(Time,customerDMonsoon,10); % Data choice from pushbutton SEASONS 174 | yfit4 = polyval(p,Time); 175 | yfitdiscretized4=polyval(p,xdiscretized); 176 | 177 | % Delete values below zero for the final curve for the Active power of the load 178 | nrows = 1; 179 | ncols = (23/SampleTime)+1; 180 | newyfitdiscretized4=yfitdiscretized4; 181 | r=1; 182 | for c = 1:ncols 183 | 184 | if yfitdiscretized4(r,c)<0 185 | newyfitdiscretized4(r,c) = 0; 186 | else 187 | newyfitdiscretized4(r,c)= yfitdiscretized4(r,c); 188 | end 189 | end 190 | 191 | % Block D (Intermediate)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 192 | 193 | p = polyfit(Time,customerDIntermediate,10); % Data choice from pushbutton SEASONS 194 | yfit5 = polyval(p,Time); 195 | yfitdiscretized5=polyval(p,xdiscretized); 196 | 197 | % Delete values below zero for the final curve for the Active power of the load 198 | newyfitdiscretized5=yfitdiscretized5; 199 | r=1; 200 | for c = 1:ncols 201 | 202 | if yfitdiscretized5(r,c)<0 203 | newyfitdiscretized5(r,c) = 0; 204 | else 205 | newyfitdiscretized5(r,c)= yfitdiscretized5(r,c); 206 | end 207 | end 208 | 209 | % Block D (Winter)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 210 | 211 | p = polyfit(Time,customerDWinter,10); % Data choice from pushbutton SEASONS 212 | yfit6 = polyval(p,Time); 213 | yfitdiscretized6=polyval(p,xdiscretized); 214 | 215 | % Delete values below zero for the final curve for the Active power of the load 216 | nrows = 1; 217 | ncols = (23/SampleTime)+1; 218 | newyfitdiscretized6=yfitdiscretized6; 219 | r=1; 220 | for c = 1:ncols 221 | 222 | if yfitdiscretized6(r,c)<0 223 | newyfitdiscretized6(r,c) = 0; 224 | else 225 | newyfitdiscretized6(r,c)= yfitdiscretized6(r,c); 226 | end 227 | end 228 | 229 | % Block E (Monsoon)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 230 | 231 | p = polyfit(Time,customerEMonsoon,10); % Data choice from pushbutton SEASONS 232 | yfit7 = polyval(p,Time); 233 | yfitdiscretized7=polyval(p,xdiscretized); 234 | 235 | % Delete values below zero for the final curve for the Active power of the load 236 | nrows = 1; 237 | ncols = (23/SampleTime)+1; 238 | newyfitdiscretized7=yfitdiscretized7; 239 | r=1; 240 | for c = 1:ncols 241 | 242 | if yfitdiscretized7(r,c)<0 243 | newyfitdiscretized7(r,c) = 0; 244 | else 245 | newyfitdiscretized7(r,c)= yfitdiscretized7(r,c); 246 | end 247 | end 248 | 249 | % Block E (Intermediate)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 250 | 251 | p = polyfit(Time,customerEIntermediate,10); % Data choice from pushbutton SEASONS 252 | yfit8 = polyval(p,Time); 253 | yfitdiscretized8=polyval(p,xdiscretized); 254 | 255 | % Delete values below zero for the final curve for the Active power of the load 256 | newyfitdiscretized8=yfitdiscretized8; 257 | r=1; 258 | for c = 1:ncols 259 | 260 | if yfitdiscretized8(r,c)<0 261 | newyfitdiscretized8(r,c) = 0; 262 | else 263 | newyfitdiscretized8(r,c)= yfitdiscretized8(r,c); 264 | end 265 | end 266 | 267 | % Block E (Winter)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 268 | 269 | p = polyfit(Time,customerEWinter,10); % Data choice from pushbutton SEASONS 270 | yfit9 = polyval(p,Time); 271 | yfitdiscretized9=polyval(p,xdiscretized); 272 | 273 | % Delete values below zero for the final curve for the Active power of the load 274 | nrows = 1; 275 | ncols = (23/SampleTime)+1; 276 | newyfitdiscretized9=yfitdiscretized9; 277 | r=1; 278 | for c = 1:ncols 279 | 280 | if yfitdiscretized9(r,c)<0 281 | newyfitdiscretized9(r,c) = 0; 282 | else 283 | newyfitdiscretized9(r,c)= yfitdiscretized9(r,c); 284 | end 285 | end 286 | 287 | % Block C (Monsoon)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 288 | 289 | p = polyfit(Time,customerCMonsoon,10); % Data choice from pushbutton SEASONS 290 | yfit10 = polyval(p,Time); 291 | yfitdiscretized10=polyval(p,xdiscretized); 292 | 293 | % Delete values below zero for the final curve for the Active power of the load 294 | nrows = 1; 295 | ncols = (23/SampleTime)+1; 296 | newyfitdiscretized10=yfitdiscretized10; 297 | r=1; 298 | for c = 1:ncols 299 | 300 | if yfitdiscretized10(r,c)<0 301 | newyfitdiscretized10(r,c) = 0; 302 | else 303 | newyfitdiscretized10(r,c)= yfitdiscretized10(r,c); 304 | end 305 | end 306 | 307 | % Block C (Intermediate)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 308 | 309 | p = polyfit(Time,customerCIntermediate,10); % Data choice from pushbutton SEASONS 310 | yfit11 = polyval(p,Time); 311 | yfitdiscretized11=polyval(p,xdiscretized); 312 | 313 | % Delete values below zero for the final curve for the Active power of the load 314 | newyfitdiscretized11=yfitdiscretized11; 315 | r=1; 316 | for c = 1:ncols 317 | 318 | if yfitdiscretized11(r,c)<0 319 | newyfitdiscretized11(r,c) = 0; 320 | else 321 | newyfitdiscretized11(r,c)= yfitdiscretized11(r,c); 322 | end 323 | end 324 | 325 | % Block C (Winter)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 326 | 327 | p = polyfit(Time,customerCWinter,10); % Data choice from pushbutton SEASONS 328 | yfit12 = polyval(p,Time); 329 | yfitdiscretized12=polyval(p,xdiscretized); 330 | 331 | % Delete values below zero for the final curve for the Active power of the load 332 | nrows = 1; 333 | ncols = (23/SampleTime)+1; 334 | newyfitdiscretized12=yfitdiscretized12; 335 | r=1; 336 | for c = 1:ncols 337 | 338 | if yfitdiscretized12(r,c)<0 339 | newyfitdiscretized12(r,c) = 0; 340 | else 341 | newyfitdiscretized12(r,c)= yfitdiscretized12(r,c); 342 | end 343 | end 344 | 345 | 346 | % Block A (Monsoon)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 347 | 348 | p = polyfit(Time,customerAMonsoon,10); % Data choice from pushbutton SEASONS 349 | yfit13 = polyval(p,Time); 350 | yfitdiscretized13=polyval(p,xdiscretized); 351 | 352 | % Delete values below zero for the final curve for the Active power of the load 353 | nrows = 1; 354 | ncols = (23/SampleTime)+1; 355 | newyfitdiscretized13=yfitdiscretized13; 356 | r=1; 357 | for c = 1:ncols 358 | 359 | if yfitdiscretized13(r,c)<0 360 | newyfitdiscretized13(r,c) = 0; 361 | else 362 | newyfitdiscretized13(r,c)= yfitdiscretized13(r,c); 363 | end 364 | end 365 | 366 | % Block A (Intermediate)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 367 | 368 | p = polyfit(Time,customerAIntermediate,10); % Data choice from pushbutton SEASONS 369 | yfit14 = polyval(p,Time); 370 | yfitdiscretized14=polyval(p,xdiscretized); 371 | 372 | % Delete values below zero for the final curve for the Active power of the load 373 | newyfitdiscretized14=yfitdiscretized14; 374 | r=1; 375 | for c = 1:ncols 376 | 377 | if yfitdiscretized14(r,c)<0 378 | newyfitdiscretized14(r,c) = 0; 379 | else 380 | newyfitdiscretized14(r,c)= yfitdiscretized14(r,c); 381 | end 382 | end 383 | 384 | % Block A (Winter)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 385 | 386 | p = polyfit(Time,customerAWinter,10); % Data choice from pushbutton SEASONS 387 | yfit15 = polyval(p,Time); 388 | yfitdiscretized15=polyval(p,xdiscretized); 389 | 390 | % Delete values below zero for the final curve for the Active power of the load 391 | nrows = 1; 392 | ncols = (23/SampleTime)+1; 393 | newyfitdiscretized15=yfitdiscretized15; 394 | r=1; 395 | for c = 1:ncols 396 | 397 | if yfitdiscretized15(r,c)<0 398 | newyfitdiscretized15(r,c) = 0; 399 | else 400 | newyfitdiscretized15(r,c)= yfitdiscretized15(r,c); 401 | end 402 | end 403 | 404 | % Block B (Monsoon)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 405 | 406 | p = polyfit(Time,customerBMonsoon,10); % Data choice from pushbutton SEASONS 407 | yfit16 = polyval(p,Time); 408 | yfitdiscretized16=polyval(p,xdiscretized); 409 | 410 | % Delete values below zero for the final curve for the Active power of the load 411 | nrows = 1; 412 | ncols = (23/SampleTime)+1; 413 | newyfitdiscretized16=yfitdiscretized16; 414 | r=1; 415 | for c = 1:ncols 416 | 417 | if yfitdiscretized16(r,c)<0 418 | newyfitdiscretized16(r,c) = 0; 419 | else 420 | newyfitdiscretized16(r,c)= yfitdiscretized16(r,c); 421 | end 422 | end 423 | 424 | % Block B (Intermediate)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 425 | 426 | p = polyfit(Time,customerBIntermediate,10); % Data choice from pushbutton SEASONS 427 | yfit17 = polyval(p,Time); 428 | yfitdiscretized17=polyval(p,xdiscretized); 429 | 430 | % Delete values below zero for the final curve for the Active power of the load 431 | newyfitdiscretized17=yfitdiscretized17; 432 | r=1; 433 | for c = 1:ncols 434 | 435 | if yfitdiscretized17(r,c)<0 436 | newyfitdiscretized17(r,c) = 0; 437 | else 438 | newyfitdiscretized17(r,c)= yfitdiscretized17(r,c); 439 | end 440 | end 441 | 442 | % Block B (Winter)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 443 | 444 | p = polyfit(Time,customerBWinter,10); % Data choice from pushbutton SEASONS 445 | yfit18 = polyval(p,Time); 446 | yfitdiscretized18=polyval(p,xdiscretized); 447 | 448 | % Delete values below zero for the final curve for the Active power of the load 449 | nrows = 1; 450 | ncols = (23/SampleTime)+1; 451 | newyfitdiscretized18=yfitdiscretized18; 452 | r=1; 453 | for c = 1:ncols 454 | 455 | if yfitdiscretized18(r,c)<0 456 | newyfitdiscretized18(r,c) = 0; 457 | else 458 | newyfitdiscretized18(r,c)= yfitdiscretized18(r,c); 459 | end 460 | end 461 | 462 | % Block LH (Monsoon)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 463 | 464 | p = polyfit(Time,customerLHMonsoon,10); % Data choice from pushbutton SEASONS 465 | yfit19 = polyval(p,Time); 466 | yfitdiscretized19=polyval(p,xdiscretized); 467 | 468 | % Delete values below zero for the final curve for the Active power of the load 469 | nrows = 1; 470 | ncols = (23/SampleTime)+1; 471 | newyfitdiscretized19=yfitdiscretized19; 472 | r=1; 473 | for c = 1:ncols 474 | 475 | if yfitdiscretized19(r,c)<0 476 | newyfitdiscretized19(r,c) = 0; 477 | else 478 | newyfitdiscretized19(r,c)= yfitdiscretized19(r,c); 479 | end 480 | end 481 | 482 | % Block LH (Intermediate)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 483 | 484 | p = polyfit(Time,customerLHIntermediate,10); % Data choice from pushbutton SEASONS 485 | yfit20 = polyval(p,Time); 486 | yfitdiscretized20=polyval(p,xdiscretized); 487 | 488 | % Delete values below zero for the final curve for the Active power of the load 489 | newyfitdiscretized20=yfitdiscretized20; 490 | r=1; 491 | for c = 1:ncols 492 | 493 | if yfitdiscretized20(r,c)<0 494 | newyfitdiscretized20(r,c) = 0; 495 | else 496 | newyfitdiscretized20(r,c)= yfitdiscretized20(r,c); 497 | end 498 | end 499 | 500 | % Block LH (Winter)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 501 | 502 | p = polyfit(Time,customerLHWinter,10); % Data choice from pushbutton SEASONS 503 | yfit21 = polyval(p,Time); 504 | yfitdiscretized21=polyval(p,xdiscretized); 505 | 506 | % Delete values below zero for the final curve for the Active power of the load 507 | nrows = 1; 508 | ncols = (23/SampleTime)+1; 509 | newyfitdiscretized21=yfitdiscretized21; 510 | r=1; 511 | for c = 1:ncols 512 | 513 | if yfitdiscretized21(r,c)<0 514 | newyfitdiscretized21(r,c) = 0; 515 | else 516 | newyfitdiscretized21(r,c)= yfitdiscretized21(r,c); 517 | end 518 | end 519 | 520 | % Block RH (Monsoon)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 521 | 522 | p = polyfit(Time,customerRHMonsoon,10); % Data choice from pushbutton SEASONS 523 | yfit22 = polyval(p,Time); 524 | yfitdiscretized22=polyval(p,xdiscretized); 525 | 526 | % Delete values below zero for the final curve for the Active power of the load 527 | nrows = 1; 528 | ncols = (23/SampleTime)+1; 529 | newyfitdiscretized22=yfitdiscretized22; 530 | r=1; 531 | for c = 1:ncols 532 | 533 | if yfitdiscretized22(r,c)<0 534 | newyfitdiscretized22(r,c) = 0; 535 | else 536 | newyfitdiscretized22(r,c)= yfitdiscretized22(r,c); 537 | end 538 | end 539 | 540 | % Block RH (Intermediate)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 541 | 542 | p = polyfit(Time,customerRHIntermediate,10); % Data choice from pushbutton SEASONS 543 | yfit23 = polyval(p,Time); 544 | yfitdiscretized23=polyval(p,xdiscretized); 545 | 546 | % Delete values below zero for the final curve for the Active power of the load 547 | newyfitdiscretized23=yfitdiscretized23; 548 | r=1; 549 | for c = 1:ncols 550 | 551 | if yfitdiscretized23(r,c)<0 552 | newyfitdiscretized23(r,c) = 0; 553 | else 554 | newyfitdiscretized23(r,c)= yfitdiscretized23(r,c); 555 | end 556 | end 557 | 558 | % Block RH (Winter)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 559 | 560 | p = polyfit(Time,customerRHWinter,10); % Data choice from pushbutton SEASONS 561 | yfit24 = polyval(p,Time); 562 | yfitdiscretized24=polyval(p,xdiscretized); 563 | 564 | % Delete values below zero for the final curve for the Active power of the load 565 | nrows = 1; 566 | ncols = (23/SampleTime)+1; 567 | newyfitdiscretized24=yfitdiscretized24; 568 | r=1; 569 | for c = 1:ncols 570 | 571 | if yfitdiscretized24(r,c)<0 572 | newyfitdiscretized24(r,c) = 0; 573 | else 574 | newyfitdiscretized24(r,c)= yfitdiscretized24(r,c); 575 | end 576 | end 577 | 578 | % Temperature for each seasons from the edit box 579 | 580 | Temp1=zeros(1,(23/SampleTime)+1);% Creation matrix Temp1 581 | Temp1(:,:)=26.8; % Set value into the matrix 582 | 583 | Temp2=zeros(1,(23/SampleTime)+1);% Creation matrix Temp2 584 | Temp2(:,:)=17.4; % Set value into the matrix 585 | 586 | Temp3=zeros(1,(23/SampleTime)+1);% Creation matrix Temp3 587 | Temp3(:,:)=23.4; % Set value into the matrix 588 | 589 | % Run the GUI 590 | run('Supervision'); 591 | -------------------------------------------------------------------------------- /src/PhotovoltaicSim.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/src/PhotovoltaicSim.m -------------------------------------------------------------------------------- /src/Supervision.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microgrid/Simulink-microgrid/b78a79d26df08c0e7505e7a832b35aa9e13878ad/src/Supervision.m -------------------------------------------------------------------------------- /src/iconRead.m: -------------------------------------------------------------------------------- 1 | function cdata = iconRead(filename,guessalpha) 2 | % ICONREAD read an image file and convert it to CData for a HG icon. 3 | % 4 | % CDATA=ICONREAD(FILENAME) 5 | % Read an image file and convert it to CData with automatic transparency 6 | % handling. If the image has transparency data, PNG files sometimes do, 7 | % the transparency data is used. If the image has no CData, the top left 8 | % pixel is treated as the transparent color. 9 | % 10 | % CDATA=ICONREAD(FILENAME, FALSE) 11 | % Same as above but supress the usage of the top left pixel for images 12 | % with no transparency data. This may require the caller to handle the 13 | % transparency explicitly. View the contents of this m-file for an 14 | % example of how to handle transparency. 15 | % 16 | % Example: 17 | % 18 | % icon = fullfile(matlabroot,'toolbox','matlab','icons','matlabicon.gif'); 19 | % uitoggletool('CData',iconread(icon)); 20 | % 21 | % See also IMREAD. 22 | 23 | % Copyright 1984-2007 The MathWorks, Inc. 24 | 25 | if nargin < 2 26 | guessalpha = true; 27 | end 28 | 29 | [p,f,ext] = fileparts(filename); 30 | % if this is a mat-file, look for the varible cdata (or something like it) 31 | if isequal(lower(ext),'.mat') 32 | cdata = []; 33 | s = whos('-file',filename); 34 | for i=1:length(s) 35 | if ~isempty(strfind(lower(s(i).name), 'cdata')) 36 | data = load(filename,s(i).name); 37 | cdata = data.(s(i).name); 38 | end 39 | end 40 | return 41 | end 42 | 43 | [cdata,map,alpha] = imread(filename); 44 | if isempty(cdata) 45 | return; 46 | end 47 | 48 | if isempty(map) 49 | if isinteger(cdata) 50 | cname = class(cdata); 51 | cdata=double(cdata); 52 | cdata = cdata/double(intmax(cname)); 53 | else 54 | cdata=double(cdata); 55 | cdata = cdata/255; 56 | end 57 | else 58 | cdata = ind2rgb(cdata,map); 59 | end 60 | 61 | if isempty(alpha) 62 | if ~guessalpha 63 | return; 64 | end 65 | % guess the alpha pixel by using the top left pixel in the icon 66 | ap1 = cdata(1,1,1); 67 | ap2 = cdata(1,1,2); 68 | ap3 = cdata(1,1,3); 69 | alpha = cdata(:,:,1) == ap1 & cdata(:,:,2) == ap2 & cdata(:,:,3) == ap3; 70 | alpha = ~alpha; 71 | end 72 | 73 | % process alpha data 74 | r = cdata(:,:,1); 75 | r(alpha == 0) = NaN; 76 | g = cdata(:,:,2); 77 | g(alpha == 0) = NaN; 78 | b = cdata(:,:,3); 79 | b(alpha == 0) = NaN; 80 | cdata = cat(3,r,g,b); 81 | -------------------------------------------------------------------------------- /src/mi_psbfft_scope_THD.m: -------------------------------------------------------------------------------- 1 | function [mag,phase,freq]=mi_psbfft_scope_THD(t,sig_struct,freq_fund,freq_max,nb_cycles,no_input,no_sig) 2 | %%PSBFFT_SCOPE computes and displays spectrum of a signal stored in a Structure with Time 3 | % format (Format used to save signals in Simulink Scope block and in To Workspace block). 4 | % The signal must be sampled at fixed step. 5 | % 6 | % PSBFFT_SCOPE performs Fourier analysis of the NB_CYCLES last cycles of signal. 7 | % The analyzed signal and a bar graph of the magnitudes of harmonic components are displayed . 8 | % Harmonic magnitudes are displayed in percent of one of the following two components: 9 | % DC component or fundamental component defined by FREQ_FUND. 10 | % The highest of these two components is chosen as a base value to normalize harmonic contents. 11 | % The magnitude of the DC component or fundamental value is written on the spectrum graph. 12 | % For accurate results, use a sampling time giving an integer number of samples per period. 13 | % 14 | % Syntax: 5 or 6 input arguments are allowed: 15 | % [mag,phase,freq]=psbfft_scope(sig_struct, freq_fund, freq_max, nb_cycles, no_input) 16 | % [mag,phase,freq]=psbfft_scope(sig_struct, freq_fund, freq_max, nb_cycles, no_input, no_sig) 17 | % 18 | % input arguments 19 | % --------------- 20 | % sig_struct : name of the structure containing time and signals saved in the Scope 21 | % freq_fund : fundamental frequency of signal (Hz) 22 | % freq_max : maximum frequency of spectrum to be displayed (Hz) 23 | % nb_cycles : number of cycles to analyze 24 | % no_input : scope input number 25 | % no_sig : signal number; default=1 26 | % (to be specified only in case of multiplexed signals on the same scope input) 27 | % 28 | % output arguments 29 | % --------------- 30 | % mag : vector of magnitudes of harmonics (units of input signal) 31 | % mag(1)= DC component, mag(nb_cycles+1)=fundamental,... 32 | % mag(n*nb_cycles+1)= harmonic order n 33 | % phase : vector of phases (degrees) 34 | % freq : vector of frequencies (Hz) 35 | % 36 | % 37 | % See also PSBFFTSCOPE 38 | 39 | % G. Sybille, Hydro-Quebec; IREQ 01-02-2000, 07-02-2001. 40 | % Copyright 1997-2001 TEQSIM International Inc., under sublicense 41 | % from Hydro-Quebec, and The MathWorks, Inc. 42 | % $Revision: 1.6 $ 43 | 44 | 45 | DT=t(2)-t(1); 46 | 47 | 48 | 49 | ncycles=max(t)*freq_fund; 50 | % if ncycles1, 63 | % fprintf('Input %d contains %d signals; Signal %d will be analyzed\n',no_input,nsig,no_sig); 64 | % end 65 | 66 | npoints=round(nb_cycles*nech_cycle); 67 | n=length(t); 68 | mat=sig_struct; 69 | t=t(n-npoints+1:n); 70 | V=mat(n-npoints+1:n); 71 | 72 | 73 | clf; figure(1); 74 | % Plot last cycle of signal to be analyzed 75 | %------------------------------------------ 76 | subplot(211) 77 | plot(t,V) 78 | ylabel(sprintf('Signal ')); 79 | xlabel('time (s)'); 80 | grid 81 | 82 | % Compute fft 83 | % ----------- 84 | spec_V=2*fft(V)/(npoints); 85 | freq=0:freq_fund/nb_cycles:1/DT; 86 | nfmax=find(freq>=freq_max); nfmax=nfmax(1); 87 | mag=abs(spec_V(1:nfmax)); 88 | phase=angle(spec_V(1:nfmax))*180/pi; 89 | freq=freq(1:nfmax); 90 | 91 | % Compute THD 92 | % ----------- 93 | 94 | sef = sqrt(sum(mag.^2) - mag(nb_cycles+1)^2 - mag(1)^2); 95 | THD = sef/mag(nb_cycles+1)*100 96 | 97 | % Plot frequency spectrum in % of fundamental 98 | % ------------------------------------------- 99 | subplot(212) 100 | 101 | % Sort harmonics starting from DC component or fundamental component 102 | if mag(1)==max(mag) 103 | [mag_sort,nh_sort]=sort(mag(2:nfmax)); %sort harmonics of rank>0 (DC) 104 | harmo_base=mag(1)/2; % base value to be used for normalization=DC component 105 | n1=0; 106 | else 107 | [mag_sort,nh_sort]=sort(mag(nb_cycles+2:nfmax)); %sort harmonics of rank >1 (Fund) 108 | harmo_base=mag(nb_cycles+1); % base value to be used for normalization=fundamental 109 | n1=1; 110 | end 111 | 112 | % Compute first 2 highest harmonics in % of DC or fundamental 113 | mag_max1=mag_sort(length(nh_sort))/harmo_base*100; % mag of highest harmonic 114 | nh_max1=nh_sort(length(nh_sort))/nb_cycles+n1; % order of first highest harmonic 115 | mag_max2=mag_sort(length(nh_sort)-1)/harmo_base*100; % mag of highest harmonic 116 | nh_max2=nh_sort(length(nh_sort)-1)/nb_cycles+n1; % order of first highest harmonic 117 | 118 | % Plot spectrum normalized with respect to fundamental or DC component 119 | % and display first 2 highest values in command window 120 | 121 | bar(freq,mag*100/harmo_base,0.25); 122 | axis([0 freq_max 0 1.1*mag_max1]) 123 | if n1==0 124 | str=sprintf('DC component = %g',harmo_base); 125 | text(0.05*freq_max,0.95*mag_max1,str) 126 | ylabel('Mag (% of DC component)'); 127 | fprintf('DC component : %g ; Highest harmonics : Orders=[%d %d] Values=[%4g%% %4g%%]\n\n',... 128 | harmo_base, nh_max1, nh_max2, mag_max1, mag_max2); 129 | 130 | 131 | else 132 | str=sprintf('Fundamental (%g Hz)= %g',freq_fund,harmo_base); 133 | text(0.05*freq_max,0.95*mag_max1,str); 134 | str=['Mag (% of ',num2str(freq_fund),' Hz component)']; 135 | ylabel(str); 136 | fprintf('Fundamental : %g ; Highest harmonics : Orders=[%d %d] Values=[%4g%% %4g%%]\n\n',... 137 | harmo_base, nh_max1, nh_max2, mag_max1, mag_max2); 138 | 139 | 140 | end 141 | xlabel('Frequency (Hz)'); --------------------------------------------------------------------------------