sin1(x) > 1 ?

DSP related issues, mathematics, processing and techniques
jotb
Posts: 23
Joined: Mon Jul 28, 2014 5:08 pm

sin1(x) > 1 ?

Post by jotb »

Hello,

studid question:
I run a 500Hz sine wave into the dsp module. If i process sin1(x), where x is the input, the output is > 1. how is that possible? :o
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: sin1(x) > 1 ?

Post by tester »

Scaling something somewhere?
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
jotb
Posts: 23
Joined: Mon Jul 28, 2014 5:08 pm

Re: sin1(x) > 1 ?

Post by jotb »

for now, I just do:

y=sin1(x);

y is streamout
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: sin1(x) > 1 ?

Post by tester »

Extract that part and post it.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
jotb
Posts: 23
Joined: Mon Jul 28, 2014 5:08 pm

Re: sin1(x) > 1 ?

Post by jotb »

hmm. strange. I just build that and now the problem is gone.

but now I have another one:
I am trying to rebuild a matlab code in the code module. But I think the sin1(x) is different than the sin(x) in matlab. How do I "convert" that? I how do I get Pi in code module? :oops:
I think that is my problem:
http://www.synthmaker.co.uk/forum/viewt ... in1#p72502
And more embarrassing: how do I get the values of the variables in code module? e.g. streamin x ?
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: sin1(x) > 1 ?

Post by KG_is_back »

jotb wrote:hmm. strange. I just build that and now the problem is gone.

but now I have another one:
I am trying to rebuild a matlab code in the code module. But I think the sin1(x) is different than the sin(x) in matlab. How do I "convert" that? I how do I get Pi in code module? :oops:
I think that is my problem:
http://www.synthmaker.co.uk/forum/viewt ... in1#p72502
And more embarrassing: how do I get the values of the variables in code module? e.g. streamin x ?


sin1(x) is normalized to 0-1 range where 0 is 0radians and 1 stands for 2pi radians.
sin(x)=sin1(x/2pi) or other way around sin(2pi*x)=sin1(x)
To get pi into code module simply declare it as variable:

Code: Select all

float pi=3.14;

simply google for more precise pi value, 9 decimal places are just enough. You can initialize variables to any numeric value. If you don't specify the value, code component simply assumes zero "float a;" is the same like "float a=0;"
For the inputs/outputs in code module use:

Code: Select all

streamin x;
streamout y;

Warning! never change the values of the input variables within the code, or you might get unexpected results in the rest of the schematic. You may use output variables just like normal variables. after all code is finished, the last value will be send out.

Code: Select all

streamin x;
streamout y;

x=123; //NEVER DO THIS!!!!
y=1;
y=2;
y=3+y;
//the code will output y=5 on stream output connector
jotb
Posts: 23
Joined: Mon Jul 28, 2014 5:08 pm

Re: sin1(x) > 1 ?

Post by jotb »

Thank you!

sin1(x)/(2*pi) seems to work

:oops: I always looked for something like math.pi

I just don`t get the stream output to do what I want...
jotb
Posts: 23
Joined: Mon Jul 28, 2014 5:08 pm

Re: sin1(x) > 1 ?

Post by jotb »

It still seems not right. I have too much "gain" and the phase seems wrong too.

the original function is:
y=sin(x)+(abs(sin(x)))^8-z

I have added the schematic. And a picture of how the sinewave should look like.
Attachments
gainstage.png
gainstage.png (59.34 KiB) Viewed 34083 times
gainstage_test2.fsm
(6.83 KiB) Downloaded 1480 times
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: sin1(x) > 1 ?

Post by KG_is_back »

te provided image definitely doesn't show the graph of function you've written. check that with this plotter, It will output the same kind of wave like your schematic:
http://rechneronline.de/function-graphs/
and input "sin(sin(x))+(abs(sin(sin(x))))^8-0.01" (the inner sinuses are there to simulate a sine wave input)
You will see that your schematic shows the same graph as this function. Basically you've made perfectly the function you've written above within the code component.

It is possible that the user used different input wave, but unlikely. There must be something more in the paper that they've done with the signal, because the function and graph definitely doesn't match if input was sine.
jotb
Posts: 23
Joined: Mon Jul 28, 2014 5:08 pm

Re: sin1(x) > 1 ?

Post by jotb »

thank you. very good link!

I have found something in the matlab code:
there is a point before ^
sin(x)+(abs(sin(x))).^8-z

i found out that is something like element by element calculation. but where is a matrix or so ?? :oops:
Post Reply