Search code examples
matlabdigital-analog-converter

How do I write MATLAB code for a DAC converter ?


In the first step I generated a sequence of bits (0,1)..

I used a randi command x = randi([0 1],1,3) to generate random bits

I stuck with these 2 steps :

Divide sequence by 3 bits into 8 levels [000, 001, 010, 011, 100, 101, 110, 111]

For each quantum level assigns amplitude value from the range [-2, 2]


Solution

  • I won't provide the full source code to leave a bit of the homework for you, but I will give you some hints:

    • randi() is creating a sequence of 0 and 1 floating point numbers
    • Look at the documentation of function bitpack. This allows you to pack your bits from array elements into a single byte. Be aware that you need to provide an 8 element array of "bits" to fill a byte. User 'uint8' as the class argument.
    • before passing the array of floating point numbers to bitpack you have to convert it to a logical array by using the logical() function.
    • look at the documentation of linspace() to create an array with 8 elements containing your equally spaces amplitude values
    • lookup the amplitude value in this array for each "digital" value.