How do I write MATLAB code for a 1 bit DAC?
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 20 Gen 2017
What would the sinusoidal pulse look like? Are you thinking of all zeros normally but when the pulse occurs then there is a single sine period? If so would it be fixed width or does the width of the pulse have to be changed? Do you need to represent a 0 differently than a 1?
Sharada Reddy
il 24 Gen 2017
Walter Roberson
il 24 Gen 2017
We might be able to help if you could clarify what the analog output should look like. Also please link to the documentation for the block you are using as there are multiple Digital to Analog blocks.
Sharada Reddy
il 25 Gen 2017
Modificato: Sharada Reddy
il 25 Gen 2017
Walter Roberson
il 25 Gen 2017
It appears to me that it cannot be converted using a 1-bit DAC.
If it could be converted with a 1 bit DAC, then whether the analog signal is above 0 or not should depend exactly to whether the digital is above 0 or not, or else should depend upon it in a simple repeating pattern. For example one could imagine that the analog signal being above 0 should be in agreement with the digital for the first half of a cycle of period 2, and should be exactly opposite it for the second half of the cycle of period 2. So if you use
ydigital = digital signal
yanalog = analog signal
ydr = (yanalog > 0) * 2 - 1; %y reconstructed
seq = ydigital == ydr;
ff_seq = fft(seq);
ff_seq(1) = 0;
plot(abs(ff_seq))
then you would expect to see a simple plot with a single frequency peak corresponding to the analog-to-digital concurrence period. But you do not: you see lots of peaks, none of which is clearly dominant, and it is not a "signal and overtones" matter either.
We have to conclude from this that the analog signal is not generated by the principle of being the same polarity as the digital signal, and not generated by the principle of being same or opposite polarity in short pattern. This leads us to the conclusion that the analog signal must have more than 1 bit of state and so cannot be generated by a 1 bit DAC.
Sharada Reddy
il 25 Gen 2017
Ajith Kumar
il 25 Gen 2017
I understand what you are saying. But Delta sigma modulator has this 1 bit conversion right.Can you say how do i convert my two level signal (-1 and +1) into analog signal ? Where i want my analog signal to change with respect to width of my two level signal.
Walter Roberson
il 25 Gen 2017
Is ofdm being applied to the digital signal that you plot before the analog signal is created? If so then the digital signal you plotted could have been spread out to create a different digital signal that was passed to the daq.
If the digital signal you plotted is the result of the ofdm process, then that analog signal cannot be created from it using a 1 bit daq, not unless perhaps there is a known long period frequency modulation that is supposed to be imposed. (And if there is, I am not convinced that it could be handled with a 1 bit daq)
Sharada Reddy
il 26 Gen 2017
Modificato: Walter Roberson
il 26 Gen 2017
Walter Roberson
il 26 Gen 2017
The digital signal that is plotted in your second figure: which signal does that correspond to on your block diagram? Does it correspond to the exact signal that is to be input to the 1 bit DAC, and is the analog signal you plotted intended to be the result of that 1 bit DAC? If so then No, I do not see any reasonable way to convert that digital stream to that analog stream.
If, though, the digital signal that you plotted is intended to correspond to the "data" that is flowing in from the top left, then because there are several processing steps after that, such as adding the cyclic prefix, then perhaps it could correspond to the analog signal.
Another possibility is that the analog signal that you plotted is intended to be the received signal, that has has signal spreading happen on it, and which has be converted back to digital and error correction done: if so, if we assume that the analog signal contains some errors, then there might be some leeway.
Sharada Reddy
il 26 Gen 2017
Walter Roberson
il 26 Gen 2017
The analog signal that you show, where was it measured in the block diagram? And is there a part of the diagram that corresponds to the signal transmission (through a media that would have signal spreading, such as through a fibre optic cable)?
Sharada Reddy
il 27 Gen 2017
Sharada Reddy
il 27 Gen 2017
Walter Roberson
il 27 Gen 2017
To convert to analog we need to know what kind of digital to analog hardware you are using and how you are creating connecting to it. Are you using an NI usb-6009? Are you using an arduino with an I2c device? Are you using an Ethernet connected Tektronics signal generator with a VISA driver?
Sharada Reddy
il 27 Gen 2017
Sharada Reddy
il 30 Gen 2017
Walter Roberson
il 31 Gen 2017
There is an example https://www.mathworks.com/help/instrument/examples/generating-and-downloading-a-baseband-signal-to-an-rf-signal-generator.html showing communications with that device. It requires Instrument Control Toolbox, as it uses VISA drivers.
Sharada Reddy
il 6 Feb 2017
Modificato: Sharada Reddy
il 6 Feb 2017
Walter Roberson
il 6 Feb 2017
You would need hardware to convert digital to real optical.
There is probably a way to convert digital to simulated optical. Perhaps not an a convenient form.
https://www.mathworks.com/matlabcentral/fileexchange/40093-interactive-simulation-toolbox-for-optics
https://www.mathworks.com/products/connections/product_detail/product_35663.html (commercial product)
Sharada Reddy
il 7 Feb 2017
Walter Roberson
il 7 Feb 2017
I do not understand the question? That device has uses VISA drivers; you could connect to it using any interface you both have. That might be a USB interface or might be a TCP interface, if the device happens to have an ethernet card. It is not necessary to have that device plugged into any kind of micro-controller for it to be accessed by MATLAB.
Sharada Reddy
il 7 Feb 2017
Modificato: Sharada Reddy
il 7 Feb 2017
Walter Roberson
il 7 Feb 2017
Your signal generator outputs signals only, except for the command inputs that tell it what signal to output. Sending the commands to it over optical channel would not appear to be useful ? It would seem more likely to me that you want to connect to your signal generator as usual but have it somehow output an optical signal ?
You need a digital or electrical signal to control voltages to one or more LED in order to have them transmit information as light. You also need one or more optical receivers to receive the light and turn it into an analog signal, and you need some kind of high speed analog to digital device to be able to convert the electrical signal (from optical) to digital form that can be read in by MATLAB. (You might be able to find direct optical to digital devices without having to go through a specific analog to digital step.) Getting digital input device that works fast enough might not be easy.
Your MGX can handle up to 6 output channels. If you do not have more than 6 LED then you could potentially take the outputs of the MGX channels and connect them to LEDs fairly directly, perhaps with some resistors; possibly with an induction coil as well.
It is not clear to me, though, that the MGX is doing anything useful for you, compared to just using a standard digital to analog device. The MGX might perhaps be much faster than most digital to analog devices, but really to take advantage of faster you need to keep the data channel filled, which is going to be difficult. The MGX would be most useful in creating a repeated signal for debugging your receiver portion. Debug your receiver first and then use the receiver to debug the transition.
Sharada Reddy
il 7 Feb 2017
Walter Roberson
il 7 Feb 2017
You wrote "The signal generator has will process electrical signal.. but i want to use optical channel using LED"
The signal generator "process electrical signal" only as command input, telling it what to generate. Are you asking that an optical connection be used between MATLAB and the signal generator to tell the signal generator what to output?
If what you want is a normal connection between MATLAB and the signal generator, and you want to convert the electrical output of the signal generator into optical signals, then you have choices. If you do not need to drive more than 6 LED, then one choice is to simply wire the output signals of the signal generator to the LEDs, just with enough resistors to prevent the voltage of the signal generator output from exploding the LEDs. Just attach a wire to the signal generator output, and attach the wire to a breadboard, add some resistors, and connect the LEDs.
But then you start talking about "without physical LED and MGX". For that you need simulated optical, which is what I was talking about in http://www.mathworks.com/matlabcentral/answers/321197-how-do-i-write-matlab-code-for-a-1-bit-dac#comment_426548. You need a program that models the characteristics of light in some medium, including diffraction and reflection and the way that different frequencies of light travel at different speeds in ways related to the index of refraction. If you are simulating over any significant distance in air, you also need to model in temperature differences (light refracts near temperature boundaries) and you might also need to model dust (which is going to scatter the light, but the way it scatters the light is going to depend upon the size of the dust and possibly even the composition of the dust.)
You might also need to model the activation of LEDs, whether they turn on strictly according to a threshold voltage, whether they turn off at the same voltage or a lower one, whether brightness varies with current, whether shape of the pulse matters to how the LED produces light.
Sharada Reddy
il 7 Feb 2017
Walter Roberson
il 7 Feb 2017
What aspects of the optical channel do you want to model?
For example for your purposes would it be enough just to do a convolution? Or to run through a FIR filter designed to smear data from different times so that waveforms are distorted?
Sharada Reddy
il 8 Feb 2017
Walter Roberson
il 8 Feb 2017
If you had a digital input from before the simulated optical transfer, and you also had a pre-filtering digital input from after the simulated optical transfer, then you could fft the two and divide the two fft results, and inverse fft to get the filter coefficients that would transform the one to another.
If not, then you will have to make something up, perhaps by sythesizing a signal and what it might look like after the simulated transfer.
Sharada Reddy
il 13 Feb 2017
Walter Roberson
il 13 Feb 2017
"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"
fig2 = open('dsm output and original signal.fig');
ax = findall(fig2,'axes');
ch = get(ax,'Children');
dig_y = get(ch(2),'YData');
mod_y = get(ch(1),'YData');
fdig = fft(dig_y);
fmod = fft(mod_y);
fd = fdig;
fd(fd == 0) = 1;
warp = fmod ./ fd;
Now, for any digital output of length exactly 272, you can
f_signal = fft(TheDigitalSignalOf272);
f_mod_signal = f_signal .* warp;
ModSignalOf272 = ifft(f_mod_signal);
and ModSignalOf272 will now be version of the original signal modulated according to exactly the same pattern as was present in the diagram you posted a while ago.
Sharada Reddy
il 21 Feb 2017
Modificato: Sharada Reddy
il 21 Feb 2017
Walter Roberson
il 21 Feb 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.
Risposta accettata
Più risposte (2)
Walter Roberson
il 21 Feb 2017
1 voto
shows an example of Digital to Analog conversion in MATLAB.
ayyoub
il 28 Feb 2020
0 voti
hey did you manage to make it !
Categorie
Scopri di più su Test and Measurement in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!