Skip to content

Instantly share code, notes, and snippets.

@a46554
Created June 8, 2017 05:55
Show Gist options
  • Save a46554/1c8f4ce55a8d72db5030d5b3d59c7565 to your computer and use it in GitHub Desktop.
Save a46554/1c8f4ce55a8d72db5030d5b3d59c7565 to your computer and use it in GitHub Desktop.
clc;
clear;
sample_bits = 12;#smaple bits
fs = 10000; #sample frequency
f = 60; #target frequency
amp= 2^(sample_bits-1);
t = 0:1/fs:1/f;
x = amp*(1+sin(2*pi*f*t));#avoid negative part
pwm_duty = x/(amp*2);
bar (pwm_duty);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment