data typecast fixed point conversion - point

I'm trying to scale a value of 1e-4 into fixed point format, but I'm having trouble getting the proper results.
Any help would be greatly appreciated.
Matlab :
fprintf('%f | %d|\n',fi(1e-4,0,32,45),storedInteger(fi(1e-4,0,32,45)) );
0.000100 | 3518437209|
and
I'm doing this in C fixed point notation.
uint32_t eps = 3518437209;
eps = (uint32_t)(eps / ((uint64_t)1 << 45));
In contrast to my anticipation of
0.000100
, the value of eps is
0
.
Thank you!!

Related

Lowpass Filter in Frequency Domain

I had a set of data and I plot it as in Figure 1
Then I used the lowpass filter to remove noise as below
N = length(FM);
n = floor(0.005*N);
H = zeros(size(FM));
H(1:n) = 1;
H( (N/2+2):N ) = H(N/2:-1:2);
LP_FM = FM .* H;
lp_fm = ifft(LP_FM);
plot(timesec,fm);
hold on
plot(timesec,real(lp_fm),'Linewidth',2);
I got the results as in Figure 2
Could anyone tell me what I am doing wrong here, please?
Why I got the abnormal values at the beginning?
Greatly appreciate for your help :)
Thanks!

Bit Error Probability

I want to ask for any help to solve my problem. I want to compute BER (Bit error rate) for a nine combination points as illustrated below. I used the computation for SER and then I convert it to BER, but the result was incorrect. Any site or suggestion please?
Many thanks
Othman
My code is:
clear all clc
SNR = 0:40;
SNRL = 10.^(SNR./10);
Eb=1;
sigma = sqrt(2*Eb./SNRL);
d2 = 0.3;
Pe = 14/9*erfc((d2)./sqrt(2*sigma.^2))+2/9*erfc((0)./sqrt(2*sigma.^2));
semilogy(SNR,Pe) grid on hold on

How do I solve this exponential equation on Excel Solver?

100e^0.25*y = 97.5
Solving for y
Using Excel Solver
I tried using empty column entry for y in 'By changing cells' and Set objective function as LHS of above equation (empty column entry in equation included) equal to value of 97.5 in solver.
It gives no solution
How do I do this?
It's a bit ambiguous what you're asking...
Literal math interpretation: 100*(e^0.25)*y = 97.5
Then y = 97.5 / ( 100 * exp(.25)) = .759
My guess of what you want: 100*e^(0.25*y) = 97.5
Then y = ln(97.5/100) / .25 = -.101
Another possibility: (100 * e)^(0.25 * y) = 97.5
Then y = (ln(97.5) / ln(100*e)) / .25 = 3.268
Whatever it is, this doesn't need solver!
You don't really need the solver. Just re-arrange your formula to solve for Y. Since y = b^x is the same as log(b)Y = x (log of Y, with base b)
Your formula above is the same as:
Y = (log(100e)97.5))/.25
(Read aloud, that's log of 97.5, with base 100e, divided by .25
So, Y = 3.268305672
(Bonus points for someone who can tell me how to format this so the Log looks correct)
The question is "How do I solve this exponential equation on Excel Solver?" which is a fair enough question, as it points to trying to understand how to set up solver.
My interpretation of the equation provided is given in this screenshot ...
The solver dialog box is then setup as follows ...
Of note:
This is a non-linear equation and needs GRG Nonlinear. If you choose LP Simplex, it will not pass the linearity test.
Ensure "Make Unconstrained Variables Non-Negative" is not checked.
It provided this result for me ...
A more precise answer can be obtained by decreasing the "Convergence" value on the GRG Non-Linear Options dialog.
A problem this simple can also be solved using Goal Seek.

Gnuplot's calculation is incorrect

I try to plot the orbital velocity with gnuplot, but somehow gnuplot gets completely different results than me. Now from experience I think my values are correct but I checked it with Google's calculator and get my results.
I use the formula from Wikipedia and Google gets a velocity at apoapsis of about 2.2 km/s. Now gnuplot itself gets a velocity of about 3.2 km/s.
set xlabel "Altitude above sea level (meters)"
set ylabel "Orbital velocity (meters per second)"
set title "Velocity of an 80×100 km orbit around Kebrin"
set terminal png size 800,640
set output "orbitv.png"
set xrange [80000:100000]
G=6.674*10**-11
M=5.2915793*10**22
R=600000
plot sqrt(G*M*(2/(x+R)-1/(90000+R))) title 'Orbital velocity' with lines
I'm wondering were did I make the mistake? I copied the formula directly to Google and replaced G, M and R with the constant values and x with 100000 and get the result linked above.
This problem has to do with how gnuplot handles integers when doing arithmetic. When you have an expression like 1/(90000 + R), if R is an integer, gnuplot evaluates 1/(690000) = 0, which is perfectly valid integer arithmetic. The solution is to add a period to a number so that gnuplot knows to cast it as a floating-point number:
R = 600000. # short option
R = 600000.0 # clearer option
Another solution is to use e-notation for big numbers:
R = 6e5
Gnuplot treats that as a float. This also helps prevent order-of-magnitude/number-of-zeroes errors.
Incidentally, python and other languages have the same problem with integer arithmetic--watch out!

How to alter brightness of a single rgb color simply and easily via php?

A quesion about RGB color and finding the simplest, tiniest, php conversion code for manipulating the lightness/darkness of a given RGB hue.
Imagine a variable $colorA containning a valid six char RGB color, like F7A100 which we want to make a bit lighter and/or darker:
$color = B1B100; // original RGB color manually set.
Then, at any page have that color bit darker/lighter on the fly:
$colorX = someFunction($color, +10); // original color 10 steps lighter
$colorY = someFunction($color, -25); // original color 25 steps darker
What would be YOUR way of solving this? Keep the RGB as is or first change it to HSL? Hints and suggestions are welcome. Your sample/code is welcome too.
This really focuses to the TINIES / SIMPLES / SHORTEST possible code to just make the same hue bit darker/lighter.
I deliberately do not suggest my code, as I want to keep possibilities open in here.
The absolutely simplest solution is to add some constant (like 1) to each part of the color representation: [R, G, B]. This is due to the fact that max values of all [R, G, B] represent white, while min values - black. In pseudo-code (assuming 255 is max, sorry, I don't know PHP):
lighter(R, G, B) = [
min(255, R + 1),
min(255, G + 1),
min(255, B + 1)
]
You must keep in mind though that this transformation is way too simplistic and the proper implementation would be to convert to HSL/HSB, increase H and transform back to RGB.
For slight alteration of brightness you can convert the hexadecimal values to decimal, manipulate them and convert back to hexadecimal like this:
function alterBrightness($color, $amount) {
$rgb = hexdec($color); // convert color to decimal value
//extract color values:
$red = $rgb >> 16;
$green = ($rgb >> 8) & 0xFF;
$blue = $rgb & 0xFF;
//manipulate and convert back to hexadecimal
return dechex(($red + $amount) << 16 | ($green + $amount) << 8 | ($blue + $amount));
}
echo alterColor('eeeeee', -10); //outputs e4e4e4
Beware that this code does not handle overflow for one color - if one color value becomes less than 0 or more than 255 you will get an invalid color value. This should be easy enough to add.
For drastic changes in brightness, convert to HSL and manipulate the lightness.
Using the functions from the Drupal code, this can be done like this:
$hsl = _color_rgb2hsl(_color_unpack('eeeeee'));
$hsl[2] -= 10;
$rgb = _color_pack(_color_hsl2rgb($hsl));
echo $rgb; //outputs e4e4e4

Resources