Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a PWM signal using a Compare To Constant block.
Simulink
pwm_signal = (input_signal [1] threshold); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality operator instead of greater than.
Using less than operator which inverts the PWM signal.
✗ Incorrect
The PWM signal is generated by comparing the input signal to a threshold using the greater than operator.
2fill in blank
mediumComplete the code to set the PWM frequency by adjusting the carrier signal period.
Simulink
carrier_period = 1 / [1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using duty cycle instead of frequency.
Using amplitude or phase shift which do not set frequency.
✗ Incorrect
The carrier period is the inverse of the frequency, so setting carrier_period = 1 / frequency sets the PWM frequency.
3fill in blank
hardFix the error in the PWM duty cycle calculation code.
Simulink
duty_cycle = [1] / max_signal_value; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using min_signal_value which does not represent the current input.
Using threshold or carrier_signal which are unrelated to duty cycle calculation.
✗ Incorrect
The duty cycle is calculated by dividing the input signal by the maximum signal value to normalize it between 0 and 1.
4fill in blank
hardFill both blanks to create a PWM signal dictionary with duty cycle and frequency keys.
Simulink
pwm_params = {"duty_cycle": [1], "frequency": [2] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'frequency' variable instead of 'pwm_frequency'.
Using 'duty' instead of 'duty_cycle'.
✗ Incorrect
The dictionary keys are 'duty_cycle' and 'frequency'. The values should be the variables duty_cycle and pwm_frequency respectively.
5fill in blank
hardFill all three blanks to generate a PWM signal array with given duty cycle, frequency, and time vector.
Simulink
pwm_signal = (mod([1] * [2], 1) < [3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up duty cycle and frequency in the multiplication.
Using amplitude which is unrelated here.
✗ Incorrect
The PWM signal is generated by computing mod(time_vector * frequency, 1) and checking if it is less than duty_cycle.