how to covert negative samples of sine wave into positive?
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Réponses (1)
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
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.
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!