08 Odds Ends
08 Odds Ends
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1011 B 11
Lecture 7 3
ASCII Table in Hex first hex digit
0 1 2 3 4 5 6 7
0 NUL ^@ null (\0) DLE ^P SP space 0 @ P ` p
1 SOH ^A start of hdr DC1 ^Q ! 1 A Q a q
2 STX ^B start text DC2 ^R “ 2 B R b r
3 ETX ^C end text DC3 ^S # 3 C S c s
4 EOT ^D end trans DC4 ^T $ 4 D T d t
5 ENQ ^E NAK ^U % 5 E U e u
second hex digit
Lecture 7 5
Two’s Complement
• Unsigned are direct binary representation
• Signed integers usually follow “two’s complement”
binary hex unsigned 2’s complement
0000 0000 0x00 0 0
0000 0001 0x01 1 1
0000 0010 0x02 2 2
0111 1111 0x7F 127 127
1000 0000 0x80 128 -128
1000 0001 0x81 129 -127
1111 1110 0xFE 254 -2
1111 1111 0xFF 255 -1
– rule: to get neg. number, flip all bits and add one
• example: -2: 0000 0010 1111 1101 + 1 = 1111 1110
– adding pos. & neg. 0000 0000 (ignore overflow bit)
Lecture 7 6
Floating Point Numbers
• Most standard is IEEE format
– http://en.wikipedia.org/wiki/IEEE_754-1985
Lecture 7 8
Indexing Arrays
int i,j[8]={0},k[]={2,4,6,8,1,3,5,7};
double x[8]={0.0},y[2]={1.0,3.0},z[8];
char name[20],state[]="California";
Lecture 7 9
Memory Allocation in Arrays
• state[]=“California”;
each block is 8-bit char
C a l i f o r n i a \0
• name[11]=“Bob”;
B o b \0
Lecture 7 12
Example: 3x3 matrix multiplication
void mm3x3(double a[], double b[], double c[])
Lecture 7 13
mm3x3, expanded
• The function is basically doing the following:
Lecture 7 14
Notes on mm3x3
• The function is constructed to deal with 1-d instead
of 2-d arrays
– 9 elements instead of 3×3
– it could have been done either way
• There is a pointer, *cptr being used
– by specifying cptr as a double pointer, and assigning its
address (just cptr) to c, we can stock the memory by using
“pointer math”
– cptr is the address; *cptr is the value at that address
– just like &x_val is an address, while x_val contains the value
– cptr++ bumps the address by the amount appropriate to
that particular data type, called “pointer math”
– *cptr++ = value; assigns value to *cptr, then advances the cptr
count
Lecture 7 15
Using mm3x3
#include <stdio.h>
int main()
{
double a[]={1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
double b[]={1.0, 2.0, 3.0, 4.0, 5.0, 4.0, 3.0, 2.0, 1.0};
double c[9];
mm3x3(a,b,c);
printf("c = %f %f %f\n",c[0],c[1],c[2]);
printf(" %f %f %f\n",c[3],c[4],c[5]);
printf(" %f %f %f\n",c[6],c[7],c[8]);
return 0;
}
• passing just the names (addresses) of the arrays
– filling out a and b, but just making space for c
– note function declaration before main
Lecture 7 16
Another way to skin the cat
double a[3][3]={{1.0, 2.0, 3.0},
{4.0, 5.0, 6.0},
{7.0, 8.0, 9.0}};
double b[3][3]={{1.0, 2.0, 3.0},
{4.0, 5.0, 4.0},
{3.0, 2.0, 1.0}};
double c[3][3];
mm3x3(a,b,c);
Lecture 7 17
Decibels
• Sound is measured in decibels, or dB
– as are many radio-frequency (RF) applications
• Logarithmic scale
– common feature is that every 10 dB is a factor of 10 in
power/intensity
– other handy metrics
• 3 dB is 2×
• 7 dB is 5×
• obviously piling 2× and 5× is 10×, which is 10 dB = 3 dB + 7 dB
– decibels thus combine like logarithms: addition represents
multiplicative factors
Lecture 7 18
Sound Intensity
• Sound requires energy (pushing atoms/molecules through a
distance), and therefore a power
• Sound is characterized in decibels (dB), according to:
– sound level = 10log(I/I0) = 20log(P/P0) dB
– I0 = 1012 W/m2 is the threshold power intensity (0 dB)
– P0 = 2105 N/m2 is the threshold pressure (0 dB)
• atmospheric pressure is about 105 N/m2
• 20 out front accounts for intensity going like P2
• Examples:
– 60 dB (conversation) means log(I/I0) = 6, so I = 106 W/m2
• and log(P/P0) = 3, so P = 2102 N/m2 = 0.0000002 atmosphere!!
– 120 dB (pain threshold) means log (I/I0) = 12, so I = 1 W/m2
• and log(P/P0) = 6, so P = 20 N/m2 = 0.0002 atmosphere
– 10 dB (barely detectable) means log(I/I0) = 1, so I = 1011 W/m2
• and log(P/P0) = 0.5, so P 6105 N/m2
Lecture 7 19
Sound hitting your eardrum
• Pressure variations displace membrane (eardrum,
microphone) which can be used to measure sound
– my speaking voice is moving your eardrum by a mere
1.510-4 mm = 150 nm = 1/4 wavelength of visible light!
– threshold of hearing detects 510-8 mm motion, one-half
the diameter of a single atom!!!
– pain threshold corresponds to 0.05 mm displacement
• Ear ignores changes slower than 20 Hz
– so though pressure changes even as you climb stairs, it is
too slow to perceive as sound
• Eardrum can’t be wiggled faster than about 20 kHz
– just like trying to wiggle resonant system too fast produces
no significant motion
Lecture 7 20
dB Scales
• In the radio-frequency (RF) world, dB is used several
ways
– dB is a relative scale: a ratio: often characterizing a gain or
loss
• +3 dB means a factor of two more
• −17 dB means a factor of 50 loss, or 2% throughput
– dBm is an absolute scale, in milliwatts: 10×log(P/1 mW)
• a 23 dBm signal is 200 mW
• 36 dBm is 4 W (note 6 dB is two 3 dB, each a factor of 2 4×)
• −27 dBm is 2 mW
– dBc is signal strength relative to the carrier
• often characterizes distortion from sinusoid
• −85 dBc means any distortions are almost nine orders-of-
magnitude weaker than the main sinusoidal “carrier”
Lecture 7 21
Coherent Detection
• Sometimes fighting to discern signal against
background noise
– photogate in bright setting, for instance
• One approach is coherent detection
– modulate signal at known phase, in ON/OFF pattern at
50% duty cycle
– accumulate (add) in-phase parts, while subtracting out-of-
phase parts
– have integrator perform accumulation, or try in software
• but if background is noisy in addition to high, integration better
– basically background subtraction
– gain more the greater the number of cycles integrated
Lecture 6 22
Raw Signal, Background, and Noise
Lecture 6 23
Modulated Signal; still hard to discern
Lecture 6 24
Integration, subtracting “OFF” portions
Lecture 6 25
Expressed in Electronics
first op-amp just inverting; second sums two inputs, only one on at a time
has effect of adding parts when Ref = +1, subtracting where Ref = -1
clears “memory” on timescale of tint = RintC
could also conceive of performing math in software
Lecture 6 26
Announcements
• Project Proposals due next Friday, Feb 7
• Lab 4 due following Tu/Wed (2/11, 2/12)
Lecture 7 27