środa, 9 lipca 2014

EMG Hand movement recognition using Artificial Neural Network and Support Vector Machine

This paper contains detailed information about creating a system capable of classifying arm muscle responses (using EMG signal) into five hand gesture classes. Informations about collecting data, processing it and validating are described. Such system is especially useful for disabled people, but low number of electrodes used creates other possibilities of usage - for example a Human-Computer Interface (HCI). Although it still cannot be used in real life as a prosthesis (we know what to do, but still don’t know how to do it exactly - for example what force to apply) it shows how easily we can interact with signals coming from our body.

Paper is available here.


sobota, 15 marca 2014

Arduino with HC-SR04 ranging sensor


How it works

To begin the measurement supply the TRIG pin with +5 V for 10 μs. The module begins to emit the ultrasonic wave (with frequency of 40 kHz).  ECHO pin receives the returning signal - it's high state time is proportional to the distance traveled by the wave.

distance [m] = (high level time [s] x 340 m/s) / 2
distance [cm] = (high level time [μs] x 34) / 1000 / 2


Arduino code

int getDistance(int trigPin, int echoPin) {
  unsigned long duration = 0;
  
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  duration = pulseIn(echoPin, HIGH);

  return duration * 34 / 1000 / 2;
}

piątek, 18 października 2013

How to send mails from JBoss Wildfly (JavaMail & GMail)

It only takes a couple of minutes to configure Wildfly 8.0.0.Alpha4 server to send mails using your Google account.


  1. Turn on standalone WildFly instance

    ./<wild_fly_home>/bin/standalone.sh

  2. Add new Mail Session (assign JNDI name, you would like to use in your applications)



  3. When the session is created, click View and add some necessary properties like your username, password, SSL encryption etc

  4. Save changes and shut down Wildfly server (CTRL+C in terminal)
  5. Open standalone configuration file (<wild_fly_home>/standalone/configuration/standalone.xml) and replace lines:

    <outbound-socket-binding name="mail-smtp">
      <remote-destination host="localhost" port="25"/>
    </outbound-socket-binding>

    with

    <outbound-socket-binding name="mail-smtp">
      <remote-destination host="smtp.gmail.com" port="465"/>
    </outbound-socket-binding>
  6. Start Wildfly (look 1.)

How to send mail from Java EE?

Use this EJB as an example:
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.logging.Level;
import java.util.logging.Logger;

@Stateless
public class Mail {

    @Resource(name = "java:jboss/mail/gmail")
    private Session session;

    public void send(String addresses, String topic, String textMessage) {

        try {

            Message message = new MimeMessage(session);
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(addresses));
            message.setSubject(topic);
            message.setText(textMessage);

            Transport.send(message);

        } catch (MessagingException e) {
            Logger.getLogger(Mail.class.getName()).log(Level.WARNING, "Cannot send mail", e);
        }
    }
}

Keep it simple!

środa, 9 października 2013

How not to get cheated in Morocco?

Morocco is considered as the most civilized African country. The difference between other continents though is still huge. People are mostly poor, and try to earn as much money as they can from tourists. Prices are different for every customers. If traders spot that you come from rich country (i.e. Germany or France) or wear good clothes they will ask you for more money.

When buying something the most important think to remember it to negotiate prices. Moroccans will often check you by asking if it is your first time in Morocco. Even if it is, you should always answer negative. You have been here a year ago, and you also have family in Casablanca. They won't be so confident after this.

I remember when we were buying some souvenirs (local women dress) and asked for the price. First we heard 2000 MAD (about 180 EUR). The best thing you can do in such situation is just start to leave the place. Traders will start pulling your sleeves, and dropping prices - in our case to 150 MAD (14 EUR) without saying any word.

They are awfully good at marketing techniques. Remember not to take anything from them without hearing the price first. You will hear many things like that is a gift, just try it on (clothes) or price later. There is really much harder to deal with them later, so avoid such situations and make simple and clear rules at the beginning (also difficult because they talk a lot).

Forget about buses when you are in bigger city. The main way to travel is by taxis. There are two sorts of those: petite taxi, and grande taxis. They look like parts from different car vendors were mixed together and created one car (I don't know why but it never crashed).

There are two ways to deal with taxi drivers.
  • determine the price before entering the vehicle.
  • making sure that kilometers counter is set correctly, don' talk about the money and pay the price that is displayed (the cheapest way).

Don't get caught in arguments like "higher night hacks", or "far away". Just start to walk away, and you will make the satisfying agreement.

wtorek, 13 sierpnia 2013

Signal from space, cure for AIDS? Check the power of parallel computing

Do you know that if you're not processing video, or processing huge amount of data, a lot of computers computational power is wasted each second?

While surfing the internet, watching movie or listening to music your using about 5% of one of your CPU cores. Modern PCs have up to 12 cores running up to 4GHz each.

Have you ever been thinking how to make more use of your machine?

Maybe something that would help someone.


Calculate it

There are about 1.1 Billion personal computers in the world (Feb 2012). Not including smartphones and tablets.


Sad scenario

Let's say that each computer is running 1GHz one-core processor (low probability). Let's also say that each of them is running constantly 50% of it's maximum performance. 

That gives us:

1E9 * 5E8 Hz = 5E17 = 0.5 EHz (Exaherz) ~ 2 exaflops


Happy scenario

Here we will assume that each computer is running dual-core 1,8GHz processor, and works under 20% constant load.

1E9 * 2 * 0,8 * 1,8E9 Hz = 2.88 EHz ~ 11.52 exaflop

World's fastest super computer build in 2013 - Tianhe-2 can actually achive perfomance of 33.86 petaflops. Analyzing worst scenario it is 60 times slower than globe collective, and in happy case more than 349 times (mention that we are using data from 2012 and no mobile devices, scientist predict that till 2016 there will be up to 2 Billion personal computers on the planet).


Unsolved problems

Nowadays human cope with many problems that are unable to solve due to lack of computational power. 

  • searching for spinning neutron starts (pulsars) using data from sky observatories and gravitational wave detectors
  • decoding Enigma messages from 1942
  • teach robots artificial intelligence (parse and convert semantic nets)
  • run simulations on LHC to improve it's design and detectors
  • cognitive process modeling to better understand the human mind
  • designing new proteins to fight diseases such as HIV, Malaria, Cancer and Alzheimer's
  • ...

How can I help


You can do it all with BOINC software (PC and Android), take a closer at my example configuration:

  • use all 4 cores
  • work on only when processor isn't used more than 25%
  • do not exceed 90% of overall CPU usage
  • work only if battery level is greater than 90%, charging and not being used (Android)

Currently I'm running 3 projects:

  1. searching for extraterrestrial intelligence (Seti@Home)
  2. searching for pulsars (Einstein@Home)
  3. searching for cures for common diseases (Rosetta@Home).

Check the full list here.

During work time I'm running BOINC at 60% (i5 4x3.2GHz, 8GB RAM) and do not feel it at all. When I leave my job I switch it to 90% to make maximum use of this power. 

Tablet (Nexus 7) that is always plugged in - also isn't lying useless. It is also running 90% but you have to disable computation when performing some stuff.

Give it a try.

piątek, 28 czerwca 2013

Iceland in 10 days.

Couple days ago I have returned from 10 days trip to Iceland. These are my memories.

We have booked cheap flights from London Luton about 6 months before the set off. It costed about 120 EUR for a return ticket. We were also travelling from Poland, so there is another 120 EUR to get to UK. 

The whole trip was meant to be as cheap as possible. Sleeping at the airports, tents, hostels, eating tunas. Unfortunately it wasn't.

1000 ISK = 6,23 EUR

You can see the full photo album here

Day 1 (6.06.2013):


Our plane touched down in Keflavik (an airport city located about 50 km from capital). The whole airport was very elegant created in wooden style. There was no problem with charging electronic devices or exchanging money (it was difficult to get local currency in Europe). One way ticket to Reykjavik (with FlyBus - Iceland Excursions) costed about 2200 ISK, return - 4000 ISK. The bus was very convenient, equipped with free wifi. First impression was like - 'Where are trees? We are on a rock desert'. Weather was very cloudy and windy.

We got to Reykjavik and started to look for a place to sleep. Luckily a bus driver spotted that we were a little bit lost and told his friend to take us to the nearest hostel - Reykjavik Backpackers. One night in 8 person room costed about 3500 ISK (with your own sleeping bag). For a place in 6 person room we would have to pay 4000 ISK. The whole hostel has 4 floors, there is a kitchen on top, and a bar at the bottom. You can access free Internet on the two first floors.

After accommodating and leaving our things, we went off for a city trip. First we have located the cheapest mall - 'Bonus'. Prices were like 2 to 3 times more like those in central-eastern Europe

Bottle of Pepsi (1,5L) - 300 ISK
Toast bread - 200 ISK
Chicken fillet (1000 g) - 5000 ISK
Water (1,5L) - 200 ISK
Kebab - 1100 ISK

After shopping we started to ramble around the town. We visited the western part of the city - church on the hill, downtown, harbour.




Day 2 (7.06.2013):


We have asked some locals for the advice - where to go. They told us - Hveragerði (about 50km from Reykjavik). We have packed our bags, and go for a bus. First we had to got to Mjódd, and then change to another bus. From Monday to Friday vehicles shuttle every 2-3 hours.


When we got to the destination spot, a nice lady at gas station gave us a map and mark the worth-seeing spots. We wanted to swim in hot rivers. It was located in mountains about 8,5 km from our current location. There were some other attractions on our way there like the restaurant, where the meals were prepared on the heat coming from the earth.


You could see mini hot founts with boiling water


a lot of ranches



There was a medium difficulty track heading to the hot river.












Hot river was amazing. It was also very dangerous - you could got scorched. There were a lot of places where water was boiling.




It was also difficult to find a good area to relax in water. Finally we managed to get to the place where two streams were meeting and resulting in temperature like 30 to 40 celsius degrees. Water wasn't smelling very good (like an old egg) but it was such a pleasure to lie there after such a long walk.



We were chilling for about an hour when it started to rain. One guy told us, that there is no need to walk the same way down the mountain, because there is a road 2 km from here in the opposite direction. It was a big mistake that we believed him.

We walked about 4 km heading to the center of the mountains. Weather quickly got completely terrible, it was raining heavily, and very windy. I was wearing 3 jackets (2 of them were water-proof), hoodie, t-shirt and a shirt. Everything was entirely wet.

Our best guess at the moment was to pitch our tents. We found a tolerable place and did it in amazingly
fast time. We took everything off, clothed double pair of socks and got into the sleeping bags. Unluckily it wasn't that good. The wind was so strong that the tents were barely standing steady. Plus the stitches burst and the water was getting into. We decided to put stuff in one tent, went outside and sealed another with raincoat and both get into it. It helped a little, two sides were protected.


Day 3 (08.06.2013)


At about 3 A.M. we figured that there is no sense, and the weather probably won't change. Sleeping bags were almost completely wet, but we had to do something. Hard decision were made - we are popping wet clothes on and going down.

12 km later when we had spotted first houses, we decided to got inside one and ask for help. I was so chilled that I couldn't take of my bagpack or bend fingers. He let us dry clothes for about 30 minutes and gave us hot water - that helped us a lot.

The plan was to go to the nearest bus station, find a course to Mjódd and than to Reykjavik. But it started to rain again... First bus would pick us in next 40 minutes, we were tired, our clothes were still wet. I didn't want to spend next couple hours like this, I knew that I would get sick. We found a guest house here - in Hveragerði

Nice guy at the gas station gave us to addresses. First was closed, we stayed in the second one. Warmth was the reason why we did it with almost no hesitation. It costed us 6000 ISK per night, but it was worth. There were heaters everywhere plus we could store our things in the basement near the stoke.



Day 4 (09.06.2013)


After one day of regeneration we decided to save some money and get to the inner of the island hitch hiking. Locals told us that people are rather friendly, and we would have no problem. We set a course on Geysirs and Gullfoss (waterfall). It was about 100 km from our current location.

First target - Selfoss. Car stopped after 3 minutes of waiting. Driver was a pole, he was working for a fish factory and heading to work. He advised us that we must visit Blue Lagoon (we did it later).

He dropped us 20 minutes later. From now on we were following the route 35. There were a couple of cars that helped us - two young guys, one older architect from Reykjavik, woman who take care of horses... When we were about 30 km from Geysir a pair from L.A. California stopped to take us. They were heading directly to Gellfoss so we decied to go with them. Driver - Garret was a surfer, he told us that about 2 weeks ago he broke the world record on the highest wave to surf on - 30 meters. I have verified this


On the information walls it was written that Gullfoss was the second most beautiful waterfall on the world (after Niagara). It's total height is 32 m with 2 drops (the longest one is 21 m).







When we were finishing contemplating this nature phenomenon it started to rain again. It was sprinkling, and we wanted to get to the Gaysir also (about 7 km). There was a lot of tourists heading in this direction so we walk down the road for about 300 m and started to catch some cars. Unfortunately none was willing to help us. It started to rain heavily, so we went totally wet again. After running back to the Gullfoss Tourist Information we came to the idea, that we would ask people on the parking lot. That worked - few minutes later we were driving with a bunch of polish people.

We landed in Geysir, geothermal area with three active springs. The most famous - Strokkur explodes every 3-4 minutes ejecting water up to 30 m.







After watching some eruptions we decided to go back. We were standing by the road, sticking thumbs and watching tourist drivers passing us by. After 30 minutes we were so bored that we started to dance (listening to music on mobiles), than drivers from NYC stopped. We were very lucky, they took us back directly to Reykjavik

During our way back, we stopped near an inactive vulcano and took some photos.


60 minutes later we were in capital where we spend the night in hostel.

Day 5 (10.06.2013)


It was our day of regeneration. We have tasted some local beer near the harbour and visited the only museum on the world - Icelandic Phallological Museum. The collection of 280 specimens from 93 species of animals includes 55 penises taken from whales, 36 from seals and 118 from land mammals, allegedly including Huldufólk (Icelandic elves) and trolls.






Day 6 (11.06.2013)


We realized that it would be very hard to visit Iceland in a cheap, convenient and fast way. Therefore we decided to rent a car. At the beginning the plan was to take a trip around the island. We calculated that it is about 1500 km, so 500 km per day and 250 km per driver daily - quite easy. We rented small Hyundai i10, for three days it costed about 24 000 ISK (including extra insurance from damage coming from gravel roads).

We put all our stuff into trunk and set a course to Hveragerði. When we get there we did shopping that let us survive 3 days - toasted bread, pizza ham, toasted cheese, tuna etc. 

Roads in Iceland are almost perfect. There are empty, in very good state. Gas stations are about 50 km from each other. The landscape is outstanding. You can see views like rock desert, lava dust moon, huge glaciers, sheeps and horses farms, sea waves.

The weather is also very different. It can change from sunny sky to awful foggy rain within 20 minutes (especially in mountains).

There is one main round around the island. If you want to go inside, it's recommended to have a special off-road vehicle (like Monster Truck) with huge tires, there are a lot of those to rent. There are also a lot of camping sites, where you can pitch your tent. 





This day we have seen two waterfalls located about 50 km from each other. 

Here are some photos and video from the first one:










The second one is called Fimmvörðuháls and is located in southern Iceland. It was well prepared for tourists - paths for old people, camp site, restroom, and small truck where you can buy something to eat.






After admiring waterfalls we got into car and start driving to south-western part (Skaftafell) part of island. There road was straight for many kilometers. We were passing places that looked almost like the moon, there was lava dust everywhere. 







We tried to get as close to the glacier that it is possible (route 998). It was 9 pm when we parked our car near camping site, and decided to finish the rest of the way by foot. It was a mystery to us how far away it is to the glacier from our position. We could see it all the time, but it didn't get closer as we walked. The surface was all covered with rocks. At the beginning there were special paths for monster trucks, but as we went further they disappeared. Few hours later we realized that there is ice under our foot. It was very dirty, and we didn't recognize it earlier. 









It was quite dangerous there. There were big, collapsed ice hollows everywhere. One false move and you could get down forever :) We kept walking, visited some ice caves. It was such a great feeling, having many tonnes of water above head.  










One hour later we decided to get back. After a long walk we came to our Hyundai at about 2 am



Day 7 (12.06.2013)


After great night in car we decided to go further on the west. We were surprised that couple kilometers from our place, we found a tourist point, from where we could get to the glacier using many different path - depending on their difficulty. We decided to try the simplest one.










It was impossible to touch the ice due to the river, created by melting snow.

We drove a couple hours heading west. 

During the way, we stopped to see Ice Lagoon.





When we get to the Hornafjörður, we admitted that it's impossible to make 1,500 km in three days (because we already made more than 500 in 2 days), and decided to turn back to Reykjavik

Day 8 (13.06.2013)


That was our last day with car. First we wanted to see Hekla (biggest active volcano, 1,400m height). We got as close as we could, but we didn't see anything due to the fog. Going couple kilometers in one direction just to see it, also didn't sound good. We were afraid of getting wet.





We reminded ourselves about Blue Lagoon. A famous place mentioned by the first pole that picked us up, when hitch-hiking. It was on the road from Reykjavik to Keflavik Airport, so we after swimming we could go back and prepare the car for the returning. We did so.

"The Blue Lagoon (Icelandic: Bláa lónið) geothermal spa is one of the most visited attractions in Iceland. The spa is located in a lava field in Grindavík on the Reykjanes Peninsula, southwestern Iceland. Bláa lónið is situated approximately 13 km (8 miles) from the Keflavík International Airport and 39 km (24 miles) from the capital city of Reykjavík. That is roughly a 20 minute drive from the airport and a 40 minute drive from Reykjavík.

The warm waters are rich in minerals like silica and sulphur and bathing in the Blue Lagoon is reputed to help some people suffering from skin diseases such as psoriasis.[1] The water temperature in the bathing and swimming area of the lagoon averages 37–39 °C (98–102 °F). The Blue Lagoon also operates a Research and Development facility to help find cures for other skin ailments using the mineral-rich water.

The lagoon is a man-made lagoon which is fed by the water output of the nearby geothermal power plant Svartsengi and is renewed every 2 days. Superheated water is vented from the ground near a lava flow and used to run turbines that generate electricity. After going through the turbines, the steam and hot water passes through a heat exchanger to provide heat for a municipal water heating system. Then the water is fed into the lagoon for recreational and medicinal users to bathe in."

Wikipedia






After swimming we came to Reykjavik, parked a car near cemetery and had a long walk before sleeping.










Day 9,10 (14-15.06.2013)


Two last days in Iceland we spent in it's capital. We didn't want to waste more money - so we kept relaxing. We were wandering through the city, drinking beers and talking to locals.