How do I create a single square wave of variable duty cycle and length.
Ältere Kommentare anzeigen
I tried a piece of code for developing a single square wave which consists of user input "duty cycle and length" but there are few inputs when the code doesn't function and returns an error.
function waveform = squareWave(duty_cycle,length_of_wave)
duty_cycle = duty_cycle * length_of_wave; %introduces duty cycle for positive edge
inv_duty = length_of_wave - duty_cycle; %introduces duty cycle for negative edge
oneCycle = [ones(1,duty_cycle),zeros(1,inv_duty)]; % one square wave form
end
This piece works fine and perfectly.
but when i wish to repeat this or apply a recursion to this at certain values it throws in errors.
function waveform = squareWave(length_of_wave,num_cycle, duty_cycle)
duty_cycle = duty_cycle * length_of_wave/num_cycle; %introduces duty cycle for positive edge
inv_duty = length_of_wave/num_cycle - duty_cycle; %introduces duty cycle for negative edge
oneCycle = [ones(1,duty_cycle),zeros(1,inv_duty)]; % one square wave form
waveform = repmat(oneCycle, [1,num_cycle]); %repeating "oneCycle" "num_cycle" times
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Pulse and Transition Metrics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

