how to covert negative samples of sine wave into positive?

26 visualizaciones (últimos 30 días)
kowsalya ramaraj
kowsalya ramaraj el 21 de Jul. de 2019
Comentada: Adam Danz el 25 de Jul. de 2019
hello
I am having trouble to get unsigned samples of sinewave. For example generated 1MHz sine wave. But samples are with both positive and negative values. But this sinewave LUT not be stored in FPGA. i have to convert negative samples into positive. I tried 2's complement method but it changing shape of sine wave. could some one help on this how to do it in matlab?
%clc;
%clear all;
%close all;
% t=linspace(0,1e-8,10000);
t = 0:0.00406901041666666666666666666667e-6:1e-6;
f=1e6;
x=sin(2*pi*f*t);
plot(t,x);
xlabel('Time (us)');
ylabel('Amplitude');
a1=x*1000;
b1=round(a1);
[c,v]=size(b1);
n3 = c*v;
word_len =11;
data = reshape(b1',n3,1);
databin =fi(data,1,10);
h = bin(databin);
d = bin2dec(h);
when i plot d vlaues from the code i am getting sine wave as above figure. not exact sine wave. please help on this.
  5 comentarios
kowsalya ramaraj
kowsalya ramaraj el 22 de Jul. de 2019
Thank you so much all for kind response. iI am getting positive samples and sine wave with this expression sin(x) - min(sin(x(sin(x)<0))).....
Adam Danz
Adam Danz el 22 de Jul. de 2019
Editada: Adam Danz el 25 de Jul. de 2019
Great! I'll move that comment to the answers section so the question is marked as answered.

Iniciar sesión para comentar.

Respuestas (1)

Adam Danz
Adam Danz el 22 de Jul. de 2019
Editada: Adam Danz el 23 de Jul. de 2019
To shift the sin curve upward so that it's minimum value is not negative,
x1 = sin(x) - min(sin(x(sin(x)<0)));
Another way to think about that is
y = sin(x);
y1 = y- min(y(y<0));
  2 comentarios
Thorsten
Thorsten el 25 de Jul. de 2019
Editada: Thorsten el 25 de Jul. de 2019
Instead of y1 = y- min(y(y<0)); you can simply use
y1 = y - min(y);
or
y1 = y + 1;
because you know the minimum value of sin is -1.
Adam Danz
Adam Danz el 25 de Jul. de 2019
In the simple case of sin(x), yes this is true. But with additional parameters such as a*sin(x) you'd have to find the minimum negative value.

Iniciar sesión para comentar.

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by