Main Content
Results for
Kindly help me correct this code to function properly. I am just learning MATLAB. i cannot get the output in abc frame. This is the code:
%----------- Define input and state parameters-----------------------------
clc
v_dc = 350; % DC input voltage in V
m = 0.841; % modulation index
C = 4000e-6; % DC buss capacitance in uf
L_1 = 2.5e-3; % Inverter side inductance in mH
L_2 = 2.5e-3; % Load side inductance in mH
L = 0; % load inductance
C_f = 10e-6; % filter capacitance in uf
R_f = 0.7; % damping resistance in ohms
R_L = 20; % load resistance in ohms
f_s = 10e3; % switching frequency
f = 60; % System frequency
R_s = 0.01; % Capacitance of the DC circuit
I_d = 8.594; % steady state current
w = 2*pi*f; % System angular Frequency
% Define initial steady state values
v_c = 349.4; i_d = 8.594; i_q = -0.213; v_df = 285; v_qf = -120; i_Ld = 8.594; i_Lq = 0.85;
%------------------S V P W M Generator-------------------------------------
% Define reference vector Uref
U_mag = m*v_dc/2; % Magnitude of Uref
% Define switching vectors
U1 = [v_dc/2;0]; % Vector Q1
U2 = [v_dc/4;sqrt(3)*v_dc/4]; % Vector Q2
U3 = [-v_dc/4;sqrt(3)*v_dc/4]; % Vector Q3
U4 = [-v_dc/2;0]; % Vector Q4
U5 = [-v_dc/4;-sqrt(3)*v_dc/4]; % Vector Q5
U6 = [v_dc/4;-sqrt(3)*v_dc/4]; % Vector Q6
% Define sector angles
theta1 = pi/6;
theta2 = pi/2;
theta3 = 5*pi/6;
theta4 = 7*pi/6;
theta5 = 3*pi/2;
theta6 = 11*pi/6;
% Define duty cycles for each switch using a for loop
for t=0:1/f_s:1/f % Time variable from 0 to one cycle of system frequency with steps of switching frequency
U_phase = w*t; % Phase of Uref (t is time variable)
U_alpha = U_mag*cos(U_phase); % Alpha component of Uref
U_beta = U_mag*sin(U_phase); % Beta component of Uref
if (0 <= U_phase) && (U_phase < theta1) % Sector 1
T1 = (sqrt(3)*U_beta + U_alpha)/(2*v_dc);
T2 = (-sqrt(3)*U_beta + U_alpha)/(2*v_dc);
T0 = 1 - T1 - T2;
d_a(round(t)+1) = T1 + T0/2;
d_b(round(t)+1) = T2 + T0/2;
d_c(round(t)+1) = T0/2;
elseif (theta1 <= U_phase) && (U_phase < theta2) % Sector 2
T3 = (sqrt(3)*U_beta - U_alpha)/(2*v_dc);
T2 = (sqrt(3)*U_beta + U_alpha)/(2*v_dc);
T0 = 1 - T3 - T2;
d_a(round(t)+1) = T0/2;
d_b(round(t)+1) = T2 + T0/2;
d_c(round(t)+1) = T3 + T0/2;
elseif (theta2 <= U_phase) && (U_phase < theta3) % Sector 3
T3 = (sqrt(3)*U_beta - U_alpha)/(2*v_dc);
T4 = (-sqrt(3)*U_beta - U_alpha)/(2*v_dc);
T0 = 1 - T3 - T4;
d_a(round(t)+1) = T0/2;
d_b(round(t)+1) = T0/2;
d_c(round(t)+1) = T3 + T0/2;
elseif (theta3 <= U_phase) && (U_phase < theta4) % Sector 4
T5 = (-sqrt(3)*U_beta + U_alpha)/(2*v_dc);
T4 = (-sqrt(3)*U_beta - U_alpha)/(2*v_dc);
T0 = 1 - T5 - T4;
d_a(round(t)+1) = T5 + T0/2;
d_b(round(t)+1) = T0/2;
d_c(round(t)+1) = T4 + T0/2;
elseif (theta4 <= U_phase) && (U_phase < theta5) % Sector 5
T5 = (-sqrt(3)*U_beta + U_alpha)/(2*v_dc);
T6 = (sqrt(3)*U_beta + U_alpha)/(2*v_dc);
T0 = 1 - T5 - T6;
d_a(round(t)+1) = T5 + T0/2;
d_b(round(t)+1) = T6 + T0/2;
d_c(round(t)+1) = T0/2;
elseif (theta5 <= U_phase) && (U_phase < theta6) % Sector 6
T1 = (sqrt(3)*U_beta + U_alpha)/(2*v_dc);
T6 = (sqrt(3)*U_beta - U_alpha)/(2*v_dc);
T0 = 1 - T1 - T6;
d_a(round(t)+1) = T1 + T0/2;
d_b(round(t)+1) = T0/2;
d_c(round(t)+1) = T6 + T0/2;
end
end
%-------------------------Define system matrices---------------------------
% Create Three-phase SVPWM VSI Inverter
% System matrix Nx-by-Nx matrix
A = [-1/(C*R_s),-sqrt(3)*m/(2*C),0,0,0,0,0;
sqrt(3)*m/(3*L_1),-R_f/(3*L_1),w,-1/(2*L_1),-sqrt(3)/(6*L_1),-R_f/(3*L_1),0;
0,-w,-R_f/(3*L_1),-sqrt(3)/(6*L_1),-1/(2*L_1),0,R_f/(3*L_1);
0,1/(2*C_f),-sqrt(3)/(6*C_f),0,w,-1/(2*C_f),sqrt(3)/(6*C_f);
0,sqrt(3)/(6*C_f),1/(2*C_f),-w,0,-sqrt(3)/(6*C_f),-1/(2*C_f);
0,R_f/(3*(L_2+L)),0,1/(2*(L_2+L)),sqrt(3)/(6*(L_2+L)),((-3*R_L-R_f)/(3*(L_2+L))),w;
0, 0, R_f/(3*(L_2+L)), -sqrt(3)/(6*(L_2+L)), 1/(2*(L_2+L)), -w, ((-3*R_L-R_f)/(3*(L_2+L)))];
% Define input matrix
B = [1/(C*R_s),-sqrt(3)*i_d/(2*C);d_a*v_dc,(sqrt(3)*v_c)/L_1;d_b*v_dc,0;d_c*v_dc,0;0,0;0,0;0,0]; % Nx-by-Nu input matrix
% Define output matrix
C = [0 1 0 0 0 0 0; % Ny-by-Nx matrix
0 0 1 0 0 0 0;
0 0 0 1 0 0 0;
0 0 0 0 1 0 0;
0 0 0 0 0 1 0;
0 0 0 0 0 0 1];
% Feedthrough matrix
D = zeros(6, 2); % Ny-by-Nu matrix
% create state-space model object
sys = ss(A,B,C,D);
% Define initial conditions and input
x0 = [v_c; i_d; i_q; v_df; v_qf; i_Ld; i_Lq]; % Initial state vector
t = 0:1e-6:0.5; % Time vector for simulation
u = repmat([v_dc;m],1,length(t)); % repeat u for each time step
% Simulate the system
[y, ~, x] = lsim(sys, u, t, x0);
% Extract the states
v_c_sim = x(:, 1);
i_d_sim = x(:, 2);
i_q_sim = x(:, 3);
v_df_sim = x(:, 4);
v_qf_sim = x(:, 5);
i_Ld_sim = x(:, 6);
i_Lq_sim = x(:, 7);
% Extract the outputs
v_abc_sim = y(:, 1:3);
i_abc_sim = y(:, 4:6);
v_dq_sim = y(:, 4:5);
i_dq_sim = y(:, 2:3);
% Plot the variables
figure;
subplot(4, 2, 1);
plot(t, v_c_sim);
xlabel('Time');
ylabel('v_c');
title('Capacitor Voltage');
subplot(4, 2, 2);
plot(t, i_d_sim);
xlabel('Time');
ylabel('i_d');
title('d-Axis Current');
subplot(4, 2, 3);
plot(t, i_q_sim);
xlabel('Time');
ylabel('i_q');
title('q-Axis Current');
subplot(4, 2, 4);
plot(t, v_df_sim);
xlabel('Time');
ylabel('v_df');
title('d-Component Filter Voltage');
subplot(4, 2, 5);
plot(t, v_qf_sim);
xlabel('Time');
ylabel('v_qf');
title('q-Component Filter Voltage');
subplot(4, 2, 6);
plot(t, i_Ld_sim);
xlabel('Time');
ylabel('i_Ld');
title('d-Axis Load Current');
subplot(4, 2, 7);
plot(t, i_Lq_sim);
xlabel('Time');
ylabel('i_Lq');
title('q-Axis Load Current');
% Perform coordinate transformation from dq frame to abc frame for currents
i_a_sim = cos(w*t)*i_d_sim - sin(w*t)*i_q_sim;
i_b_sim = cos(w*t - 2*pi/3)*i_d_sim - sin(w*t - 2*pi/3)*i_q_sim;
i_c_sim = cos(w*t + 2*pi/3)*i_d_sim - sin(w*t + 2*pi/3)*i_q_sim;
% Perform coordinate transformation from dq frame to abc frame for voltages
v_a_sim = cos(w*t)*v_df_sim - sin(w*t)*v_qf_sim;
v_b_sim = cos(w*t - 2*pi/3)*v_df_sim - sin(w*t - 2*pi/3)*v_qf_sim;
v_c_sim = cos(w*t + 2*pi/3)*v_df_sim - sin(w*t + 2*pi/3)*v_qf_sim;
Many thanks
The MATLAB Answers community is an invaluable resource for all MATLAB users, providing selfless assistance and support. However, with the emergence of AI-based chatbots, like chatGPT, there may be concerns about the future relevance and utility of the MATLAB Answer community. What are your thoughts?
Hello, Recently I have started working on a thermal management project at my Institute. I am taking some hints from en example of EV thermal management provided by MATLAB. I am having an issue in deciding how the battery current and powertrain heat load is calculated as a function of vehicle speed. It would be helpful if someone could provide some links or references regarding this. (Also, attaching a screenshot of the example for better understanding)
I am processing ocean and climate data (1982-2022). Here, I have table which having heatwaves events details. Now, I want to sort the data month wise and also seasonal wise (summer:October- February, and winter:March-September), and then i wanted to plot mean seasonal and trend.
Sample file is attached. length of original file may vary in size.
Thanks in addvance.
Hello,
can someone help me with HEV model? I have no experience with simulink modeling, maybe someone have any simple HEV models or any tutorials how to start everything? :)
Thank you.
I am using simulink to generate a simple ADC sampling code. I configured ADC module in software mode, which updates the sampled value according to the sample time configured in the module. I set the sample time to 1e-4, 1e-5, 1e-6 respectively. But it seems that the sampling speed did not reach the value I set. I suspect it has something to do with the read and write operations, but I am not sure if that's the reason.
I also tried to do it using PWM event to trigger the start of conversion of ADC. Same problem happened. Because I connect a potentiometer and turn its knob slowly, the Graph on CCS is correct while when I turn it very quickly, the graph is not able to keep up with my movements. So the sampling rate is surely not enough. I wonder what I should do to successfully configure this model, thanks in advance!
Hello,
I have an Open Loop Transfer Function:
Gc(s)Gp(s) = aKp(1+Tis) / Tis(s+1+p)
It was decided for this system a=5, Ti=0.1 and p=0.5
What would the poles and zeroes be for this?
Ive done the other examples but this one looks very different to the other questions and it has me stuck.
Any help is appreciated and sorry if this is the wrong place to post such questions.
"The model is configured to create a SIL block, which is not supported for the selected hardware board. To resolve this, search for 'Create block' in the Configuration Parameters dialog box and set it to 'None' or 'PIL'.
I am facing an issue in data store memory block using store memory Read and write Block in matlab simulink. I have attached the screen short in which the posed error has been depicted.
Hello,
i want to implement a Energy Storage System with a Battery and a Supercapacitor, where the Supercapacitor comes in when the Battery has a short circuit for an emergency system. How can i implement something like this ? I think the right way is to implement a function where a switch is controlled by the SOC of the two storage systems or ?
Hi, I am currently studying the effects of varying switching frequency towards the inverter and motor system efficiency. I am using the three-phase converter which the gate signal is sent by a PWM generator. Inside the PWM generator block, there is switching frequency parameter. Therefore, is it possible if I can tune the value of switching frequency by making it as input and receving the signal in Matlab Simulink similar with Vabc and Vdc instead of tuning from Matlab code?
Hope to receive any comment or suggestion. Thank you.
Need some guidance on how to model the mutual inductance model from Simscape. The secondary side does not receive the voltage.
This is the 6th installment of the wish-list and bug report thread.
This topic is the follow on to the first Wish-list for MATLAB Answer sections and second MATLAB Answers Wish-list #2 (and bug reports). The third started out as New design of the forum - grey on white and the fourth and fifth also grew so large they are slow to load and navigate.
Same idea as the previous ones: one wish (or bug report) per answer, so that people can vote their wishes.
What should you post where?
Next Gen threads (#1): features that would break compatibility with previous versions, but would be nice to have
@anyone posting a new thread when the last one gets too large (about 50 answers seems a reasonable limit per thread), please update this list in all last threads. (if you don't have editing privileges, just post a comment asking someone to do the edit)
I want to understand this from the scratch, i will appreciate help and guidance very much.
Hi, having problems with this model. Tried changing all the capacitor values without any success. Any help/suggestions would be most welcome.
There are two kinds of text data type (=string data type) in MATLAB:
Text1='aText'; % first one
Text2="aText"; % first one
The second one did not exist in "old" MATLAB versions but the first one only.
My questions are: 1) What was motivation of MathWorks programmers to introduce the Text Data Type of the second format?
Yes, I know the difference: length(Text1)=5 whilst length(Text2)=1; Text1(2)='T' but Text2(2) does not exist. The array Text3=['one' ; 'fifth'] does not exist too.
2) However, any explanations and recommendations how to apply the second sort in contrast to the first one?
3) Is there any way how to convert one sort to another one?
Thanks for explanation in advance!
I've now seen linear programming questions pop up on Answers recently, with some common failure modes for linprog that people seem not to understand.
One basic failure mode is an infeasible problem. What does this mean, and can it be resolved?
The most common failure mode seems to be a unbounded problem. What does this mean? How can it be avoided/solved/fixed? Is there some direction I can move where the objective obviously grows without bounds towards +/- inf?
Finally, I also see questions where someone wants the tool to produce all possible solutions.
A truly good exposition about linear programming would probably result in a complete course on the subject, and Aswers is limited in how much I can write (plus I'll only have a finite amount of energy to keep writing.) I'll try to answer each sub-question as separate answers, but if someone else would like to offer their own take, feel free to do so as an answer, since it has been many years for me since I learned linear programming.
Hello,
I am trying to do image to image regression neural network training. In place of digitTrain4DArrayData, I have used my own dataset of 500 input and 500 output grayscale images of size 100*100 pixels for training.
The code is as follows:
imds1 = datastore(fullfile(matlabdrive,"T10itTI"),"IncludeSubFolders",true,...
"FileExtensions",".png","type","image");
imds2 = datastore(fullfile(matlabdrive,"TFiSTI"),"IncludeSubFolders",true,...
"FileExtensions",".png","type","image");
dsnew = combine(imds1,imds2);
layers = [
imageInputLayer([100 100 1])
batchNormalizationLayer
reluLayer('Name','relu_1')
convolution2dLayer(3,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_2')
convolution2dLayer(3,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_3')
convolution2dLayer(3,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_4')
convolution2dLayer(1,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_5')
convolution2dLayer(3,1,'Stride',2)
batchNormalizationLayer
reluLayer('Name','relu_6')
convolution2dLayer(3,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_7')
convolution2dLayer(3,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_8')
convolution2dLayer(3,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_9')
convolution2dLayer(3,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_10')
convolution2dLayer(3,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_11')
convolution2dLayer(3,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_12')
convolution2dLayer(1,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_13')
transposedConv2dLayer(1,1,'Stride',2)
batchNormalizationLayer
reluLayer('Name','relu_14')
convolution2dLayer(1,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_15')
convolution2dLayer(1,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_16')
convolution2dLayer(3,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_17')
convolution2dLayer(1,1,'Stride',1)
batchNormalizationLayer
reluLayer('Name','relu_18')
transposedConv2dLayer(3,1,'Stride',2)
fullyConnectedLayer(1)
regressionLayer
]
lgraph = layerGraph(layers);
options = trainingOptions("adam", ...
InitialLearnRate=8e-3, ...
SquaredGradientDecayFactor=0.99, ...
MaxEpochs=20, ...
MiniBatchSize=64, ...
Plots="training-progress")
net=trainNetwork(dsnew, lgraph, options);
On running the code, I get following error:
Error using trainNetwork Invalid training data. The output size ([1 1 1]) of the last layer does not match the response size ([1 1 1972224]).
When I use fullyConnectedLayer(1972224) in place of fullyConnectedLayer(1), I get following error:
Error using trainNetwork Layer 'fc': Invalid initializer. Requested 1972224x17161 (252.2GB) array exceeds maximum array size preference (5.0GB). This might cause MATLAB to become unresponsive.
Error in mt1tt1 (line 95) net=trainNetwork(dsnew, lgraph, options);
Caused by: Error using nnet.internal.cnn.assembler.InitializeMixin/initializeLearnableParameters Layer 'fc': Invalid initializer. Requested 1972224x17161 (252.2GB) array exceeds maximum array size preference (5.0GB). This might cause MATLAB to become unresponsive.
Can you suggest correction in code?
Thankyou
Hi Fellow Users,
I am Muthuserpi From A begginer of Optics studio Please anyone help me how to add two diffeaction reflective grating and How to tilt and decenter in matlab simulation
Thanks And Regards
S.Muthuserpi
Hello Community,
For E vehicle application to control the speed and torque of PMSM motor I am implementing FOC algorithm. We know that to arrive at Speed set point we have speed control loop which is outer loop, Further PI CONTROLLER of speed loop will give reference for Iq current which regulates the current using current loop. My question is 1.How to arrive at Torque set point?
2. Is speed control using FOC is enough or we should implement Torque control algorithm also?
3. should we have speed mode and Torque mode selection in case of constant speed requirement during cruise mode and high torque requirement during uphill situation respectively
4. To arrive at Torque set point what is the relation or transfer function to tune PI controller for Torque loop?
Please give your valuable inputs and answers, thanks in advance