Hello,
I am wanting to create a square wave in MATLAB that increases it's duty cycle with respect to time, however when I tried to implement this, I ran into the error of MATLAB only allowing scalar values for the duty cycle.
Is there any way around this?
Here is my current code, based off of this example: https://uk.mathworks.com/matlabcentral/answers/217746-implementing-a-sine-wave-with-linearly-changing-frequency
Fs = 100000; t = 0:1/Fs:1; f_in_start = (100*1/3)/(100*0.1); %1-to-2 PFM
f_in_end = 50/(100*0.1); %1-to-1 PFM
f_in = linspace(f_in_start, f_in_end, length(t)); %Varying pulse frequency
DC_start = 100*1/3; %1-to-2 PFM DC_end = 100*1/2; %1-to-1 PFM DC_in = linspace(DC_start, DC_end, length(t)); %Varying the duty cycle
DC = cumsum(DC_in/Fs); %Duty cycle
phase_in = cumsum(f_in/Fs); %frequency
y = 0.5*square(2*pi*phase_in,DC) + 0.5; plot(t,y)
For context, the aim is to create a PFM waveform that increases in frequency with respect to time, increasing from a 1-to-2 mark space ratio to a 1-to-1 whilst keeping the 'on-time' of the signal constant.
Ideally, the waveform should look something like this at the start:
And end with something like this:
Thank you in advance
Best Answer