how to covert negative samples of sine wave into positive?

23 vues (au cours des 30 derniers jours)
kowsalya ramaraj
kowsalya ramaraj le 21 Juil 2019
Commenté : Adam Danz le 25 Juil 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 commentaires
kowsalya ramaraj
kowsalya ramaraj le 22 Juil 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 le 22 Juil 2019
Modifié(e) : Adam Danz le 25 Juil 2019
Great! I'll move that comment to the answers section so the question is marked as answered.

Connectez-vous pour commenter.

Réponses (1)

Adam Danz
Adam Danz le 22 Juil 2019
Modifié(e) : Adam Danz le 23 Juil 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 commentaires
Thorsten
Thorsten le 25 Juil 2019
Modifié(e) : Thorsten le 25 Juil 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 le 25 Juil 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.

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by