Raadiolained, moduleerimine, induktsooon

Kogun siia enda jaoks subjektis toodu teemaga seotud linke ja infot, et neist ükspäeb enda jaoks terviklik pilt kokku panna.

Sageduse suurenedes suureneb aktiivtakistus pindefekti mõjul – juhtmes indutseeritud pöörisvoolude mõjul kulgeb vool rohkem pinnakihtides. Juhtme südamik jääb põhiliselt kasutamata, seetõttu juhtme ristlõikepind näivalt väheneb ja takistus suureneb. (Allikas: http://www.ene.ttu.ee/leonardo/elektro_alused/6Vahelduvvool.pdf)

 

 

 

Allikas: https://commons.wikimedia.org/wiki/Main_Page

 

 

https://www.electronics-tutorials.ws/oscillator/oscillators.html

http://www.learnabout-electronics.org/Oscillators/osc10.php

Game Theory

Aeg-ajalt olen seda fraasi kuulnud ja siis googeldanud ja üldmõttest aru saanud. Et edaspidi lihtsam oleks, siis kirjutan omale siia maha kokkuvõtte mänguteeooria ühest levinumast näitest – Prisoners’ Dilemma.

Olukord on siis selline, et kaks tegelast jäävad autovargusega vahele, mille eest tahetakse neile panna karistuseks kaks aastat. Mõlemad paigutatakse eraldi kambritesse ülekuulamiseks. Samas selgub, et mõlemat tegelast kahtlustatakse ka pangaröövis. Tegelased omavahel suhelda ei saa.

Mõlemale pätile antakse valikud:

  1. Kui mõlemad tunnistavad pangaröövi ülesse, siis saavad kolm aastat.
  2. Kui üks tunnistab pangaröövi ülesse ja teine ei tunnista, siis see, kes tunnistab pangaröövi saab ühe aasta ja see, kes ei tunnistanud saab kümme aastat.

Antud valikutest saab moodustada maatriksi:

Vang 1
TunnistabEi tunnista
Vang 2TunnistabMõlemad saavad kolm aastatVang 2 saab ühe aasta. Vang 2 saab kümme aastat.
Ei tunnistaVang 1 saab kümme aastat. Vang 1 saab ühe aastaVang 1 saab kaks aastat. Vang 2 saab kaks aastat.

Kui nüüd mõlemad vangid läheksid oma karistuse minimaliseerimise peale (kaks aastat), siis on oht, et üks või teine tunnistab ennast siiski pangaröövis süüdi ja üks või teine saab kümme aastat. Analüüsides ülal toodud lihtsat tabelit, siis selgub, oluline on mõlema vangi vaatevinklist kümme aastal laualt minema saada. Ja valikutesse jääb üks aasta, juhul kui üks või teine ei tunnista ennast süüdi või siis kolm aastat kui mõlemad tunnistavad ennast süüdi.

What does reduce

 

List( 1, 2, 3, 4 ).reduce( (x,y) => x + y )   == (((1+2)+3)+4)
Step 1 : op( 1, 2 ) will be the first evaluation. 
  Start with 1, 2, that is 
    x is 1  and  y is 2
Step 2:  op( op( 1, 2 ), 3 ) - take the next element 3
  Take the next element 3: 
    x is op(1,2) = 3   and y = 3
Step 3:  op( op( op( 1, 2 ), 3 ), 4) 
  Take the next element 4: 
    x is op(op(1,2), 3 ) = op( 3,3 ) = 6    and y is 4

Restore ESP8266EX original firmware using esptool

https://github.com/mlwmlw/esp8266-workshop/tree/master/firmware

margusja@IRack:/System/Library/Extensions$ esptool.py –port /dev/tty.wchusbserial1410 write_flash 0x00000 /Users/margusja/Downloads/v1.3.0.2\ AT\ Firmware.bin
esptool.py v2.2
Connecting….
Detecting chip type… ESP8266
Chip is ESP8266EX
Uploading stub…
Running stub…
Stub running…
Configuring flash size…
Auto-detected Flash size: 1MB
Compressed 1044480 bytes to 242823…
Wrote 1044480 bytes (242823 compressed) at 0x00000000 in 21.6 seconds (effective 387.1 kbit/s)…
Hash of data verified.

Leaving…
Hard resetting…

 

AT+GMR
AT version:0.40.0.0(Aug 8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04
OK

OpenCP cv:Mat and cv:transpose

Matrix transpose does some cool stuff with matrix elements. In example using OpenCV:

    Mat A = (Mat_<float>(2, 5) << 1, 2, 3, 4, 5, 7, 8, 9, 10, 11);

    cout << “A = “ << endl << ” “ << A << endl << endl;

    Mat A1;

    transpose(A, A1);

    cout << “A1 = “ << endl << ” “ << A1 << endl << endl;

A =

[1, 2, 3, 4, 5;

7, 8, 9, 10, 11]

 

A1 =

[1, 7;

2, 8;

3, 9;

4, 10;

5, 11]

 

Nice yeah.

As OpenCV holds pictures as matrixes then lets find out what is turns out to transpose image.

 

 

Picture has a little more matrix elements than in a previous example –

Image heigth: 720 cols: 1080 – It means 720 x 1080 elements.

    // Load an color image in grayscale

    Mat img = imread(“/Users/margusja/Pictures/faces/margusja2.jpg”,0);

    cv::Size s = img.size();

    int rows = s.height;

    int cols = s.width;

    Mat fimage;

    transpose(img, fimage);

    cout << “Image heigth: “ << rows << ” cols: “ << cols << endl;

    namedWindow( “Display window”, WINDOW_AUTOSIZE );

    imshow(“Margusja 1”,img);

    namedWindow( “Display window”, WINDOW_AUTOSIZE );

    imshow(“Margusja transposed”,fimage);

And result:

Versus

 

Now we have a clue how they rotate our pictures 🙂

Simple Tensorflow arithmetic

Lets imagine we have to do a simple arithmetic: (10+20) * (30-40)

In some unclear reason we decidet to use Tensorflow.

Default language is there python.

(tensorflow) margusja@IRack:~/tensorflow/tensorflow_scripts$ python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import tensorflow as tf
/Users/margusja/tensorflow/lib/python3.6/importlib/_bootstrap.py:205: RuntimeWarning: compiletime version 3.5 of module ‘tensorflow.python.framework.fast_tensor_util’ does not match runtime version 3.6
return f(*args, **kwds)
>>>
>>> a = tf.constant(10)
>>> b = tf.constant(20)
>>> c = tf.constant(30)
>>> d = tf.constant(40)
>>> e = tf.add(a,b)
>>> f = tf.subtract(c,d)
>>> h = tf.multiply(e,f)
>>> sess = tf.Session()
2017-11-10 19:02:43.777454: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
>>> print(sess.run(h))
-300

We can explore graph in tensorbar:

 

Change GIT password from command line

$ git config credential.helper store
$ git push https://github.com/repo.git

Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>

Ethereum Sol

It took me some time to understand Solidity events. But in the end I think I can explain it.

So the example contract:

contract CallCalc {
address calcReg =0xd794EaF737549c2698e2232c07A9b666934584f8;
event TestEvent(address indexed _from , uint);

function call(uint256 input) returns (uint) {
TestEvent(msg.sender, input);
if (!calcReg.call(bytes4(sha3(“add(uint256)”)), input))
throw;
}
}

After executing method call I can see event in my client

 

Ethereum JSON_RPC eth_getStorageAt

Create a simple contract:


contract Storage {
    uint pos0;
    mapping(address => uint) pos1;
    
    function Storage() {
        pos0 = 1234;
        pos1[msg.sender] = 5678;
    }
}

submit it and get back address. In example 0x9a5CdfCb1132dcbEca55b213372224D9bd0209c2

Now lets execute it under one account. In example 0xa2213890a81042692B4716025D6e98349b432349

Lets see how we can get what is in storage related with contract.

We can use JSON_RPC eth_getStorageAt or web3.eth.getStorageAt from geth command line. In this example I’ll use JSON_RPC eth_getStorageAt.

Contracts storage is basically key-value storage.

To get pos0 is simple:

margusja@IRack:~$ curl -X POST --data '{"jsonrpc":"2.0", "method": "eth_getStorageAt", "params": ["0x9a5CdfCb1132dcbEca55b213372224D9bd0209c2", "0x0", "latest"], "id": 1}' localhost:8545
{"jsonrpc":"2.0","id":1,"result":"0x00000000000000000000000000000000000000000000000000000000000004d2"}

hex value 4d2 to decimal is 1234.

TO get pos1 is more tricky. First we have to calculate index position using contract executor address and index. Go to geth commandline and:

var key = “000000000000000000000000a2213890a81042692B4716025D6e98349b432349″ + “0000000000000000000000000000000000000000000000000000000000000001”

We added zeros to get 64 bit value. Next in geth command line:

web3.sha3(key, {“encoding”: “hex”}) – it returns aadress: 0x790e4fae970c427bd6d93e3f64ba898c69fdead01d68e500efb6f3abc672d632

Now we can get value from storage:

margusja@IRack:~$ curl -X POST --data '{"jsonrpc":"2.0", "method": "eth_getStorageAt", "params": ["0x9a5CdfCb1132dcbEca55b213372224D9bd0209c2", "0x790e4fae970c427bd6d93e3f64ba898c69fdead01d68e500efb6f3abc672d632", "latest"], "id": 1}' localhost:8545
{"jsonrpc":"2.0","id":1,"result":"0x000000000000000000000000000000000000000000000000000000000000162e"}

hex value 162e to decimal is 5678

Source – https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_clientversion