hello everyone i performed rgb to grayscale image transformation with fixed point arithmetic on zynq7000 microcontroller and the opperations was faster,now i want to have a threshold of time and perform fixed point arithmetic(reduced precision) or floating point arithmetic(high precision) based on time that i have left.
for example:
if i perform rgb to grayscale with high precision it takes for the cpu 10 seconds.
if i perform rgb to grayscale with low precision it takes for the cpu 5 seconds.
but if the time that i can spend on the task is 7.5 seconds how i will say that i want half of the image to be performed with high precision and the other half with low precition?
i am seeking for a formula that will see my time threshold and will calculate how many values of the image i need to transform to grayscale with high precisionand how many values of the image with low precsion based on that threshold of time!thnx
The formula follows from the equation
h 10 + (1 - h) 5 = 7.5
where h is the fraction at high speed (here 50%).
Being
nH -> number of high precision images
nL -> number of low precision images
uH -> time to process a high precision image
uL -> time to process a low precision image
T -> available time
N -> images to process
To process all the images in less than T:
nH * uH + nL * uL < T
Where high precision plus low precision is equal to all the images to process:
nH + nL = N
Substituting:
nH < (T- (uL * N))/(uH - uL);
nL = N - nH;
Related
suppose ,
we get a value of Signal-to-noise(SNR) is 255.
what is value of SNR in dB ?
Note:
we know,
if a value is given 30 dB.
the SNR value will be = 10^3 = 1000
SNR Calculation – Simple
If your signal and noise measurements are already in dB form, simply subtract the noise figure from the main signal: S - N. Because when you subtract logarithms, it is the same as dividing normal numbers. The difference of the numbers is the SNR. For example: you measure a radio signal with a strength of -5 dB and a noise signal of -40 dB. -5 - (-40) = 35 dB.
SNR Calculation – Complicated
To calculate SNR, divide the value of the main signal by the value of the noise, and then take the common logarithm of the result: log(S ÷ N). There’s one more step: If your signal strength figures are units of power (watts), multiply by 20; if they are units of voltage, multiply by 10. For power, SNR = 20 log(S ÷ N); for voltage, SNR = 10 log(S ÷ N). The result of this calculation is the SNR in decibels. For example, your measured noise value (N) is 1 microvolt, and your signal (S) is 200 millivolts. The SNR is 10 log(.2 ÷ .000001) or 53 dB.
info from https://sciencing.com/how-to-calculate-signal-to-noise-ratio-13710251.html
This question might be best on https://physics.stackexchange.com/ though
I am using MPC 7555 controller. It has a 16 bit sigma delta ADC.
A signal called mic input is fed to this ADC pin. based upon the voltage , a PWM signal of same frequency of ADC signal sampling should be generated.
For e.g.
0.1 V = 2 percent
0.2 V = 4 percent
0.3 V = 6 percent....and so on
So, i thought the following logic -
5V - 0xFFFF in digital
0.1V - 1310
0.2V - 2620 and so on
So, dividing the digital value by 655 will give exact duty cycle value
1310/655 = 2
2620/655 = 4........
But digital pin could also show value of 1309 for 0.1 V which when divided by 655 would yield 1 and not 2.
Anyway i can avoid this or does any have a better solution, please share.
The task is to output PWM at the same rate as the ADC conversion rate.
Suppose the ADC conversion time is T (you can establish this by reading a free-run timer counter). And suppose the ADC conversion value is V. Then the PWM output time H spent "high" must be
H = T * V / 0xFFFF
Every time an ADC conversion is available, you (cancel any pending one-shot timer interrupt and) set the PWM output to 1 and trigger a one-shot timer at time H. When it interrupts, you set the PWM output to 0 (or the other way round if you have inverse logic).
If the input is 0x0000 or 0xFFFF you can employ an alternative strategy - set the output to 0 or 1, but don't deploy the one-shot timer.
To get the best fidelity in teh PWM signal, you would do better to work directly at the resolution of the PWM rather then calculate a percentage only to then convert that to a PWM count. Using integer percentage, you are effectively limiting your resolution to 6.64 bits per sample (i.e. log10(100)/log10(2)).
So let's say your PWM count per cycle is PWM_MAX, and your ADC maximum ADC_MAX, then the PWM high period would be:
pwm_high = adc_val * PWM_MAX / ADC_MAX ;
It is important to perform the multiplication first to avoid loss of information. If PWM_MAX is suficiently high, there is probably no need to worry about integer division rounding toward zero rather then to teh nearest integer, but if that is a concern (for low PWM_MAX ) then:
pwm_high = ((adc_val * PWM_MAX) + (ADC_MAX / 2)) / ADC_MAX ;
For example, soy your PWM_MAX is only 100 (i.e. the resolution truely is in integer percent), then in the first case:
pwm_high = 1310 * 100 / 0xFFFF = 1
and in the second:
pwm_high = ((1310 * 100) + 0x7FFF) / 0xFFFF = 2
However if PWM_MAX is a more suitable 4096 perhaps, then:
pwm_high = 1310 * 4096 / 0xFFFF = 81
or
pwm_high = ((1310 * 4096) + 0x7fff) / 0xFFFF = 82
With PWM_MAX at 4096 you have effectively 12 bits of resolution and will maintain much higher fidelity as well as directly calculating the correct PWM value.
I'm working on typing speed app and I need to know what's the Formula of calculating WPM (Words Per Minute)
Edit:
indeed i know:
wpm = correct_characters_in_60_seconds / 5
but i have no idea what should i do with decimal numbers like 22.6 or 19.7 and...
for example if user typed 158 keystrokes in 60 seconds so, 158/5 = 31.6
so do the result should be 32 WPM or 31 WPM? How?
thanks.
WPM (Word per minute)
For the purpose of typing measurement, each word is standardized to be five characters or keystrokes long, including spaces and punctuation. For example, the phrase "I run" counts as one word, but "rhinoceros" and "let's talk" both count as two.
So the formula is:
Number_of_keystroke / time_in_minute * percentages_of_accurate_word
or
Number_of_keystroke / time_in_second * 60 * percentages_of_accurate_word
When dealing with decimals you should round down when the decimal is >.5 , else round down
Example:
5.5 -> 6
7.3 -> 7
3.49 -> 3
4.51 -> 5
Words per minute(WPM) should be rounded off to the closest decimal value.
In your case 158/5 = 31.6 should be reported as 32 and not 31.
However if the the value was 156/5 = 31.2 then it should be rounded off to 31 to approximate the closest decimal value and hence averaging the overall error.
if WPM<=x.5 then WPM = x else WPM = x+1
I was reading dp, dip, px, sp measurements, but I still have some questions about dp/dpi vs ppi vs px vs inch. I am not able to compare them... is an inch the largest?
They say 160 dpi means 160 pixels per one inch. Does that mean 1 inch contains 160 pixels?
They also say 1 pixel on a 160 dpi screen = 1 dp. Does that mean 1 pixel and 1 dp are equal?
And lastly, why should we use dp instead of px? I understand that it is ideal, but why?
You should (almost) always use flexible sizing units, like dp, which is Density-Independent Pixels, because 300px on one device is not necessarily the same amount of screen real estate as 300px on another. The biggest practical implication is that your layout would look significantly different on devices with a different density than the one your design targeted.
dp or dip means Density-independent Pixels
dpi or ppi means Dots (or Pixels) Per Inch
inch is a physical measurement connected to actual screen size
px means Pixels — a pixel fills an arbitrary amount of screen area depending on density.
For example, on a 160dpi screen, 1dp == 1px == 1/160in, but on a 240dpi screen, 1dp == 1.5px. So no, 1dp != 1px. There is exactly one case when 1dp == 1px, and that's on a 160dpi screen. Physical measurement units like inches should never be part of your design—that is, unless you're making a ruler.
A simple formula for determining how many pixels 1dp works out to is px = dp * (dpi / 160).
dp is a physical measurement like inches. (Yes, it is. Read on.)
"A dp corresponds to the physical size of a pixel at 160 dpi" (https://developer.android.com/training/multiscreen/screendensities.html#TaskUseD)
The physical size of a pixel at 160 dpi is exactly 1/160th of an inch. Therefore the size of a dp is 1/160th of an inch. 160 dp = 1 inch.
Px is a somewhat arbitrary unit of measurement on a screen.
For examples of what dp converts to in px on different devices, see here:
https://stackoverflow.com/a/39495538/984003
How do dp, dip, dpi, ppi, pixels and inches relate?
For the purpose of android development:
dp = dip
dpi = ppi
inch x dpi = pixels
dp = 160 x inch
dp = 160*pixels/dpi
So, on a 160dpi phone (mdpi):
2 inches = 320 dp
2 inches = 320 pixels
On a 180 dpi phone:
2 inches = 320 dp
2 inches = 360 pixels
Note that 2 inches is ALWAYS 320dp, independent of screen size. A dp is a physical distance of 1/160th of an inch.
The dp to pixels formula is interesting:
dp = 160*pixels/dpi
Is equivalent to:
dp = pixels/(dpi/160)
dpi/160 is an interesting factor. Its the relative density compared to android's mdpi bin and the amount you must scale your graphics by for the various resource bins. You'll see that factor mentioned a few times on this page, 0.75 being the factor to ldpi.
I will explain using an example.
float density = context.getResources().getDisplayMetrics().density;
float px = someDpValue * density;
float dp = somePxValue / density;
density equals
.75 on ldpi (120 dpi)
1.0 on mdpi (160 dpi; baseline)
1.5 on hdpi (240 dpi)
2.0 on xhdpi (320 dpi)
3.0 on xxhdpi (480 dpi)
4.0 on xxxhdpi (640 dpi)
so for example,
I have a Samsung S5 with 432 dpi (http://dpi.lv/#1920×1080#5.1″).
So, density = 432/160 = phone's dpi/baseline = 2.7
Let say my top bar is 48dp. This is referenced to baseline (160dpi).
So, w.r.t my S5, it will be 48dp * 2.7.
Then if I want to see the actual height:
It will be (48dp * 2.7) / 432 dpi = 0.3 inches.
DP is the resolution when you only factor the physical size of the screen. When you use DP it will scale your layout to other similar sized screens with different pixel densities.
Occasionally you actually want pixels though, and when you deal with dimensions in code you are always dealing with real pixels, unless you convert them.
When not referring to android, but rather to monitors,
DP actually means Dot Pitch, which originally came about from CRT monitors. It refers to the diagonal distance between 2 pixels in mm. In LCD monitors, a pixel is larger, and assuming the pixels are right next to each other without gap (usually there is a very small gap, but for simplicity, we will assume it is zero), the diagonal distance between the 2 centers of each pixel is equal to the diagonal size of the pixel. The lower the DP, the crisper the image.
DP = 25.4÷ppi
0.25 DP is standard, jagged edge
0.20 DP is considered much clearer
160 ppi = 0.158 DP
So DiP is actually a rounded approximation of 1000 x DP, and the 2 are not equivalent, just very close approximations.
As mentioned before, you should not base things off of pixel size since you can zoom. This is for how clear something will appear on the screen.
In monitors, if you want clarity at 20 inches (average distance between monitor to eye) (< 0.20 DP medium clarity/0.16 DP ultra sharp), this would equate to:
1920x1080 (HD) 17.4 inch/ 14 inch
3840x2160 (4K) 35 inch / 27.8 inch
A high resolution phone might have a DP of 0.05 (approximately 500 ppi), or 3 times higher than that of a ultra sharp monitor but viewed 3 times closer.
Anything larger than these dimensions for the monitor size will appear pixelated, smaller would be clearer.
Also noteworthy is that 72 pixels per inch is a Mac standard, and very old. 96 ppi is what Windows resolution is referenced to. Photoshop was originally designed for the Mac.
As we go up the musical scale the note frequency increases;
#define A4 440 // These are the frequencies of the notes in herts
#define AS4 466
#define B4 494
#define C5 523
#define CS5 554
#define D5 587
I am generating the tones mechanically, I tell a step motor to step, delay, step, delay etc etc very quickly.
The longer the delay between steps, the lower the note. Is there some smart maths I could use to inverse the frequencies so as I climb up the scale the numbers come out lower and lower?
This way I could use the frequencies to help calculate the correct delay to generate a note.
So what you're saying is you want the numbers to represent the time between steps rather than a frequency?
440 Hz means 440 cycles/second. What you want is the number of seconds/cycle (i.e. time between steps). That's just 1 / <frequency>. That means all you have to do is define your values as 1/440, 1/466, etc. (or, if you want the values to be milliseconds, 1000/440, 1000/466 etc.)
If that is too fast (or doesn't match the actual notes), you can multiply each value by a scale factor and the relationships between the audible tones should remain the same.
For example, lets say that you empirically discover that for your machine to make an "A4" tone, the delay between steps is 10 milliseconds. To figure out the scale factor, solve for x:
x / 440 = 10
x = 4400
So define scale = 4400, and define each of your notes as scale / 440, scale / 466 etc.
Yes, that sounds possible! Let's have a look... (some of this you will know but I'll post it anyway)
In what's called an equal tempered scale, you can calculate Hertz values by multiplying by the twelfth root of two for every semitone you go up. There are 12 semitones in a whole octave, and multiplying by this value twelve times doubles the frequency, which raises the tone by an octave.
So, if you wanted to calculate descending semitone frequencies from e.g. A 440, you can calculate double x = pow(2.0, 1.0/12.0) (assuming C), and then repeatedly divide by that value (remember to do the divisions as doubles not ints :) ) and then you'll get your descending scale.
Aside: If you want to do a major scale rather than a chromatic (semitone) scale, this is the pattern of tones and semitones to use: (e.g. in C Major - using T for Tone, S for semitone)
C [T] D [T] E [S] F [T] G [T] A [T] B [S] C