How do I write MATLAB code for a 1 bit DAC?

47 vues (au cours des 30 derniers jours)
Sharada Reddy
Sharada Reddy le 20 Jan 2017
I am doing my final year project where I am struck with the 1 bit Digital to Analog Converter block. I want to convert my Digital 1 bit pulse signal into an analog sinusoidal signal. Can anybody tell me how to write1 the MATLAB code to do it? Even the basic command syntax is enough. Thank you.
  34 commentaires
Sharada Reddy
Sharada Reddy le 21 Fév 2017
Modifié(e) : Sharada Reddy le 21 Fév 2017
My digital data is for instance 101011101. How should I convert it into analog signal? Do you have any MATLAB code (not Simulink) that can convert digital data into analog? I have searched a lot and all gave ADC code only and none DAC. Hope u can give a sample code or logic that will convert digital into analog. The above code uses ,fig i dont have GUI output. I have a normal digital output in terms of 0 and 1. In accordance to your previous comment :"The power of a signal is the sum of the absolute squares of its time-domain samples divided by the signal length, or, equivalently, the square of its RMS level" the power digital signal will be 1 as it contains only 0 and 1. which is of no use to my project. could you please give a valid dac code?
Walter Roberson
Walter Roberson le 21 Fév 2017
You cannot convert your digital data into analog signal without using hardware to do so. You can at most create simulated analog signals. Which is what we have been discussing.
The digital data you have is nice and clean. There is no point post filtering it and so on. Your simulation of the transport layer would be useless without some distortion of the signal.
But how should be simulate distortion of the signal reasonably accurately? Well, I posted links to File Exchange contributions that allow detailed simulation of optical signal distortion. You said that was too complicated.
So I went back to the GUI output you posted. You posted it in https://www.mathworks.com/matlabcentral/answers/321197-how-do-i-write-matlab-code-for-a-1-bit-dac#comment_423138 . And I used that as a template for how your distortion should look.
This is not a matter of you going through a graphical output and reading off the graph and so on: you already posted representative readings, and I showed you how to use those representative readings to calculate parameters that you can use from now on as your simulated distortion function. Provided, that is, that you transmit in batches of 272 samples.
"the power digital signal will be 1 as it contains only 0 and 1"
First of all, that will not be true for the (simulated) distorted signal: it will have a range of values.
Secondly: your digital signals (1 and 0) are being ideally mapped into +1 to -1. The squares of +1 and -1 are both +1, so Yes, the ideal is constant power. However, you asked for half sine waves, not for square waves, and sine waves take time to transition between +1 and -1.

Connectez-vous pour commenter.

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 17 Juin 2021
Modifié(e) : MathWorks Support Team le 17 Juin 2021
When you go to convert your 1-bit digital signal to an analog signal using an ideal DAC on [-1, 1], you will get the same square wave signal out of the DAC that you put in.  This is because the analog signal only changes when the digital one does, and their amplitudes and biases are the same.  Any samples not corresponding to a digital value change would inherit their value from the most recent sample that did.
How Do We Make an Ideal DAC in MATLAB?
Since we can’t work with truly continuous signals, the simplest method to approximate them is to use a time step size that is small relative to your digital time step size.  You can use
xq = interp1(t, x, tq, previous)
as an ideal DAC, given digital sampling points t and “analog” sampling points tq.  Once in the new higher sample rate you can low-pass filter, add noise, etc. until the response sufficiently represents your device.  This is, however, inefficient, due to the sample points spread all over a square wave instead of being concentrated at the transitions. 
How Do We Do This More Efficiently, Sample Timing-Wise?
To get efficiently placed sample points, use Simulink®.  The solver will take care of placing sample points for you; an ideal DAC therefore would be the gain and bias required to change from the digital scale to the analog scale.  A ZOH (Zero-Order Hold) block will keep the sample rate on the digital side constant if placed between it and the analog side, and Gain and/or Bias blocks can handle the amplitude conversion between the digital and analog realms.
Non-ideal DAC Models with Impairments
Everything I said above assumes you, like the original asker, want an ideal DAC as fast as possible.  If you want to model the effects a practical DAC would have on your system a ZOH and/or Gain block will not suffice. The Mixed-Signal Blockset™ contains a Binary Weighted DAC block, which models offset error, gain error and settling time.  If you want to model stochastic noise impairments (thermal, environmental, etc.), Simulink offers a selection of configurable random sources in the standard library.

Plus de réponses (2)

Walter Roberson
Walter Roberson le 21 Fév 2017
shows an example of Digital to Analog conversion in MATLAB.

ayyoub
ayyoub le 28 Fév 2020
hey did you manage to make it !

Catégories

En savoir plus sur Device Driver Blocks dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by