# Constructing a sine/cosine waveform circuit using combinational logic

Design a combinational circuit based sine and cosine waveform generator having 4-bit signed output. Each waveform should have equally distributed 16 data points. Digital circuit must be realized in its minimized form with possible shared logic units. The digital circuit for Sine waveform generator should contain only NAND gates while that for cosine waveform generator should contain only NOR gates.

Hint:- 16 data points relate to input angles between 0 to 360

The general roadmap for solving these kind of questions is to first create the truth table, and then, trying to derive the boolean function using K-maps. Once this is done, using appropriate logic gates to build the circuit is trivial.

For this particular question, we will have y1=f1(x1,x2..x16), y2=f2(x1,x2..x16)... y4=f4(x1,x2..x16) where f1,f2,f3,f4 are the boolean functions.

However, I am totally stumped as to what exactly the truth table should like and hence cannot proceed further. Also, what exactly is the hint trying to tell us? What exactly is the significance of having 16 points as inputs for representing angles from 0 to 360?

And finally, what is the significance of having a 4 bit output? Presumably one of the bits is for the sign, but why exactly do we need four ?

Any help regarding constructing the truth table will be appreciated. I do not want the complete solution.

• Have you considered asking your professor or TA?? Sep 16, 2021 at 14:36
• Why 4 bits? .... A sinewave has amplitude from -1 to +1, how can you represent fractional numbers in between? Sep 16, 2021 at 14:42
• @MituRaj A normalised sinusoid has values between +1 and -1; this one could be between 0 and 15 or +7 and -8 (depending on what representation you choose to use). Sep 16, 2021 at 14:52
• 360/16 = 22.5, so compute sin 0°, sin 22.5°, sin 45°, etc. Multiply by 2^7 and you have pattern. Sep 16, 2021 at 15:33
• Re, "why exactly do we need four?" You need four bits because your professor said so. That's an external requirement -- a design choice that is forced on you by somebody else. In the real world, the output of your circuit would be an input to some other circuit. If you wanted to know "why 4 bits?" you'd ask the designer of that other circuit. If you wanted to negotiate a different number of bits, that's who you'd talk to. Maybe their design still would be open to change, maybe not. Sep 16, 2021 at 15:35

You have 8 discrete values (plus a sign bit). So think of the output as ±7 or as 7*sin(x * 360/16) where x = 0 to 15. That will give you the binary output values at each of the 16 points (after rounding). (I assume the input is coming from a 4-bit counter). That will give you your input-to-output truth table.

Likewise for the cos table.

For the sine wave version:

Since the sinusoidal wave is smooth, at each time interval you'll have to choose the nearest of sixteen levels, rounding up or down. The equivalent wave would have "steps". Note that the sequence from one step to the next repeats for subsequent sine cycles.

Why 4-bits? That's what's called for.
More bits than four would more accurately represent a sine wave. More intervals for 360 degrees would be more accurate too, resulting in smaller steps...but 16 is the design spec.

Also, what exactly is the hint trying to tell us? What exactly is the significance of having 16 points as inputs for representing angles from 0 to 360?

16 points are almost the minimum to show some sign of sine wave from a binary number.

And finally, what is the significance of having a 4 bit output? Presumably one of the bits is for the sign, but why exactly do we need four ?

3 bits for 8 points of the amplitude, 1 bit for the sign.

Any help regarding constructing the truth table will be appreciated. I do not want the complete solution.

You may use LibreOffice Calc.

A7: =A6+1
B7: =SIN(2 * PI() * A7/$B$3)
D7: =SIGN(B7)
E7: =((-1 * D7+1)/2)
F7: =DEC2BIN(B7 * D7 * $B$3/2)
H7: =BIN2DEC(F7)
I7: =H7*D7

Design a combinational circuit based sine and cosine waveform generator having 4-bit signed output.

OK, make sure you know how such values are constructed.

Each waveform should have equally distributed 16 data points.

Draw a period of a sine on paper. distribute 16 points on the x axis (exclude the endpoint, that's already the start point of the next period)

Hint:- 16 data points relate to input angles between 0 to 360

I think this "angles" hint is important. Your circuit should be able to produce angles and from these values.

Another hint: you don't need to compute all values. Draw a sine on paper, and make sure you see which values you can reuse.

The general roadmap for solving these kind of questions is to first create the truth table, and then, trying to derive the boolean function using K-maps

Yeah, but not the winning method here, really. Make a list of the values, and generate these. That's essentially a ROM that you walk through. In a naive implementation, it would be a ROM with 16 entries of 4 bit each. So, maybe it's four circular shift registers, each 16 entries deep, that each give a bit successively.

You're clever, so you can do it with fewer entries (some are duplicate), but then you actually need to generate addresses for a ROM, and that probably won't pay at this simplicity of ROM.

For additional knowledge: if you actually need an analog sine waveform, you only need to toggle a single bit and then low-pass filter away all the harmonics. I don't know how much Fourier analysis you already know, but you probably know Bode diagrams, so look at the spectrum of a square wave, and imagine an analog filter (e.g. an RC) whose purpose is to suppress any of the spectral peaks aside from the first. You're left with a spectrum with a single peak, that's a sine or cosine (with a phase).

• Thank you for the detailed answer. From yours and BrianB's explanation, I atleast now know that we are trying to construct y= 7sin(22.5 x.. This allowed me to write the truth table, and also the fact that we can reuse some values made it easier: however, what can we do next? Using K-maps seems to be very tedious here. You also mention, "Yeah, but not the winning method here, really. Make a list of the values, and generate these. That's essentially a ROM that you walk through" What exactly do you mean by this? Sep 16, 2021 at 16:45
• I mean the things I write in the next four sentences :) Sep 16, 2021 at 16:46
• I don't know anything about ROMs or bode plots unfortunately :( Sep 16, 2021 at 16:47
• I agree with the first half of our answer, but in the last couple paragraphs you're missing the forest for the trees. It's apparent that the exercise is to develop the truth table and work out the most efficient way to implement that truth table with just NAND (and NOR) logic gates. The whole part about the sin/cosin is a thought exercise to generate a truth table that has some applicability to the real world without getting crazy and using lots of bits. Sep 16, 2021 at 17:51
• @MarcusMüller The exercise says to implement with NAND gates. This is a simple 4-bit S-Box mapped into the fewest number of NAND gates. satan-29 don't get led down a rabbit hole - do a truth table for each of the 4 output bits and how to generate them from NAND gates. Sep 16, 2021 at 17:56