Simulink From block accepting values from matlab code -


i have following simulink model : dc/ac half-bridge inverter, uses pwm block (inside green frame) generate switching signals igbts, from block (inside red frame) accepts signal pwm using goto block, passes output igbts.

schema

i'm trying build custom pwm using matlab code :

clc; close all; clear all; t=0:0.001:1; s=sawtooth(2*pi*10*t+pi); m=0.75*sin(2*pi*1*t); n=length(s); i=1:n     if (m(i)>=s(i))         pwm(i)=1;     elseif (m(i)<=s(i))         pwm(i)=0;     end end plot(t,pwm,'-g',t,m,'--r',t,s,'--b'); grid on; ylabel('amplitude'); xlabel('time index'); title('pwm wave'); axis([0 1 -1.5 1.5]); 

here result of plot :

enter image description here

my question :

i know t contains time values , pwm contains pwm values, want know how "somehow" redirect data matlab code, through block igbts can use them switching signal ?

the multiple ways this, easiest use from workspace block direct replacement pwm generator (2 pulses) block.

run matlab code define variables in matlab workspace, , (assuming g1_1 , g2_1 signals negation of each other) use [t(:) pwm(:) ~pwm(:)] block's data parameter.

note also, don't need loop in code:

pwm = (m >= s); 

or if need them doubles rather logical then

pwm = double(m >= s); 

Comments