What is the reason for adding 1 to magnitude of sine when we want to send samples to DAC (12 bit resolution)?

조회 수: 1 (최근 30일)
I'm not understanding reason for using y=y+1; We know that sin(0) is 0 . But getting 2048 as first sample.
What is the reason for adding 1 to Y?
Y = Y + 1;
This is the code written to generate sine wave for DAC input .
clear all;
close all;
clc; % Clear The Previous Points
Ns = 128; % Set The Number of Sample Points
RES = 12; % Set The DAC Resolution
OFFSET = 0; % Set An Offset Value For The DAC Output
%------------[ Calculate The Sample Points ]-------------
T = 0:((2*pi/(Ns-1))):(2*pi);
Y = sin(T);
Y = Y + 1;
Y = Y*((2^RES-1)-2*OFFSET)/(2+OFFSET);
Y = round(Y);
plot(T, Y);
grid
%--------------[ Print The Sample Points ]---------------
fprintf('%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, \n', Y);

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 11일
Adding one transforms it from the range [-1 1] to [0 2] . Multiply by 2^12 to get a value in the range [0 4096] . Divide by 2 to get [0 2048]. Which is suitable for transmission over a digital interface using unsigned bits.
(The way they use OFFSET looks a bit dubious to me though. But it doesn't affect anything when OFFSET is 0.)
If 1 were not added to y then you would start having to transmit values in the range [-2048 2048], and then you would start having to argue about which of the three major representations you use for negative values.
  댓글 수: 3

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by