I want to implement a code (for Simulink input) which is ON for 0 to 0.3 seconds. Than OFF (0) for 0.3 to 0.8s. Again, ON for 0.8 to 1.1s and OFF for 1.1 to 1.4s. And so on. Your code will implement a sinusoidal wave only while I wish to implement a time varying function.
Ok, now I got what you wish. Anyway, note that you are somewhat modulating the sinusoidal wave with a pulse train having a fundamental frequency with the same magnitude order. What do you think about reduce the amount of sampled pulses from 25 to something close to 2 or 3 to see in a magnified view what waveform is really being created. Additionally, you should reduce the time step in order to keep the resolution acceptable.
I tried that too. But I am still unable to figure out the reason of the two peaks in every 0.3s ON cycle, while it should generate 1 peak per ON state. Besides I need to generate this signal for 30s to really see the output of the system.
As far as I can see, the math is working exactly as expected. The pulse train is acting as a rectangular window function, but not at an even integer fraction of the sine wave, which is being therefore faceted.