# Generation of sine wave using samples

#### electronicsLearner77

Joined May 26, 2012
127
Really this is one of the questions going in my mind before i implement. This question is regarding generation of sine wave in motor application (Svpwm). if i use a PWM frequency of 20KHz, so if my sine wave frequency to be generated is 1KHz, will i get 20 samples per one cycle? All these calculations seems to be too complicated. How to analyze these calculations? Please advise.

#### MrChips

Joined Oct 2, 2009
28,154
You have many questions in one post:
• sine wave generation
• motor application
• PWM
• 1kHz sine wave with 20kHz PWM
Take one question at a time.
What is the first question?

#### electronicsLearner77

Joined May 26, 2012
127
If pwm frequency is 20Khz and if sine wave to be generated is 1Khz. The number of samples is 20KHz/1KHz = 20 ?

#### MrChips

Joined Oct 2, 2009
28,154
If pwm frequency is 20Khz and if sine wave to be generated is 1Khz. The number of samples is 20KHz/1KHz = 20 ?
Yes. Last time I checked, 20/1 was 20.

#### Ian Rogers

Joined Dec 12, 2012
1,061
I don't think it really matters... It's a question of resolution.

20Khz PWM -> 1khz sine requires 20 steps ( samples )....
15Khz PWM -> 1 khz sine will require 15 steps ( samples )…

The higher your PWM frequency, the better the sine will be..

Do a bit of research as PWM filtering isn't linear.. Visit Roman Blacks web site,, Herein you will find a "corrected" sine wave sample array... Albeit very large.... I had to tone it down a bit!

http://www.romanblack.com/onesec/Sine1kHz.htm

#### electronicsLearner77

Joined May 26, 2012
127
Thank you very much for the reply. If i see the waveform

According to me you varied the duty cycle of pwm so the width of the pulses should change but i am seeing the width constant
Q1. How much the width will be? Is it of importance?
Q2. Why the amplitude is changing?
Q3. If the amplitude is changing, amplitude will be proportional to duty cycle?

#### MrChips

Joined Oct 2, 2009
28,154
Ignore that diagram. That shows amplitude modulation, AM, not pulse-width modulation, PWM.
Amplitude and duty-cycle are independent.

If your clock frequency is 20kHz, that translates to a period of 1/20k seconds = 50μs.
For 0% duty-cycle, the pulse-width is 0μs.
For 100% duty-cycle, the pulse-width is 50μs.
Hence your PWM pulse-width can range from 0 to 50μs.

Joined Mar 10, 2018
4,057
Q1) Several considerations. PWM is being used as a DAC, where DC equivalent value
is proportional to duty cycle after filtering it.

Q2) That graph is not showing the whole pic. This graph more accurate representation.

The PWM is a logic output, but its duty cycle controls, after LPF, DC value. Which
will be the sine after appropriate PWM duty cycle modulation.

3) Yes, thats how PWM is acting as a DAC. And modulating in time its
duty cycle will create the sine.

http://www.ti.com/lit/an/spraa88a/spraa88a.pdf

https://web.csulb.edu/~hill/ee470/Lab 2d - Sine_Wave_Generator.pdf

Regards, Dana.

Last edited:

#### Ian Rogers

Joined Dec 12, 2012
1,061
As Mr chips has already said.... Ignore that graph... It only shows the readings, in excel, needed to create the sine shape...

Read the article thoroughly as there are more graphs to give better accuracy.... Read and digest!

Most micro's will give a decent resolution at 20khz PWM