# Why if I change the sample time in Matlab/Simulink modifies results in a huge way?

I'm having trouble with the circuit I'm studying but in order to modify some values, I want to get out this question of my mind.

I use a S-Function block in order to get this "triangular" wave, so I'll leave it here in case of:

static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
ssSetModelReferenceSampleTimeDefaultInheritance(S);

}

static void mdlOutputs(SimStruct *S, int_T tid)

int_T             i;
// Corriente Snubber
InputRealPtrsType u0_Is = ssGetInputPortRealSignalPtrs(S, 0);
// Triangle Reference
InputRealPtrsType u1_Iref = ssGetInputPortRealSignalPtrs(S, 1);
//  Voltaje THY - Lectura voltaje colector/emisor
InputRealPtrsType u2_Vce = ssGetInputPortRealSignalPtrs(S, 2);

real_T            *IGBT = ssGetOutputPortRealSignal(S, 0);
real_T            *THY =  ssGetOutputPortRealSignal(S, 1);
int_T             width = ssGetOutputPortWidth(S, 0);
int_T             width1 = ssGetOutputPortWidth(S, 1);

for (i=0; i<width; i++){

if (*u0_Is[i] < *u1_Iref[i]){
*IGBT++ = 1;
if (*u2_Vce[i] >= 0.8 && (*u0_Is[i] < *u1_Iref[i]) ){
*THY++ = 1;
}
else {
*THY++ = 0;
}
}
else {
*IGBT++ = 0;
*THY++ = 0;

}
}

• Wait a minute. This isn't MATLAB code. This looks like C (maybe C++, but most likely C). Do you have this code in MATLAB? Also, your Simulink module would be nice to see as well. – KingDuken Mar 21 '18 at 22:59
• @KingDuken that is C code, but to produce Simulink blocks – JonRB Mar 21 '18 at 23:08
• @JonRB Interesting... I had no knowledge of that. Thank you for tell me :) – KingDuken Mar 21 '18 at 23:10
• Try using a stiff integrator – Scott Seidman Mar 22 '18 at 1:41
• I think this can be attributed to Nyquist-Shannon sampling theorem. Remember, sampling frequency should be always higher enough than circuit's switching frequency to get the right simulation results. – Hazem Mar 22 '18 at 3:42