how to covert negative samples of sine wave into positive?
26 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuestas (1)
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
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.
Ver también
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!