Monday, 22 June 2015

Another Weekend in Singapore

Now I’m working for a lab I guess I have a good idea of what working a 9 to 5 job will be like. I barely have time to do anything on weekdays. Free time has become a very precious resource. So weekends are the only time I get to actually do stuff. And most of the time, after a busy week all I feel like doing on the weekend is relax.

I’ve started going to the movies almost every week now. I didn’t have an opportunity to do that in Trichy. The theaters there are horrible. They tend not to show the kind of movies that I want to watch and when they do they either run it at a really inconvenient time or they dub it in Tamil. This place is heaven compared to Trichy. There are so many awesome places to see and visit! And so many good theaters!

Last Saturday, I decided to go visit the library. I felt like sitting in a quiet place and relaxing by reading something. I hadn’t done that in a really long time. I browsed around till I found a book that caught my eye. It was “Contact” by Carl Sagan. And I just sat down there and read for the next 4 hours. I really missed doing that. I’d do that a lot when I was a little kid. But after starting college I didn’t have much time to do that.

I went back to the library again on Sunday. This time I thought I’d do some reading on machine learning. There were these tables with power sockets on them set aside for people who wanted to do some work in the silence of the library. It was nice to sit there and work. The girl sitting beside me was also studying machine learning apparently. She had this book called “Supervised learning With Complex Valued Neural Networks” on her desk.
I think I’ll visit the library at least once a week from now on. It was nice to take a break from the general noise of the city.


I took a picture of the library building! It looks pretty cool!
image

Saturday, 20 June 2015

Using IFTTT for blog syncing.

So since I decided to keep both my blogs running in parallel, I’ve only posted two blogposts and I’m already starting to find it annoying to update both blogs every time I get a new idea for a post. So I decided to try out this thing that I signed up for a long time ago, but never really used till now. IFTTT (IF This Then That). It’s a web service that allows you to automate your social media accounts by having certain actions triggered automatically when you do something. For example, you can set it up so that whenever you like a video on youtube, it’s automatically tweeted or shared on Facebook or posted on your blog. It’s actually quite brilliant!
Now I signed up for this service when it was just starting out because I thought it was a really cool idea. But at that time I didn’t really have much going on in the web. So even though I had an account, I never really used a single recipe till now. Now I’ve finally created one so that whenever there’s a new post in my wordpress blog on my website, the same thing is automatically posted to my blogger blog as well.

Friday, 19 June 2015

Analysing sound in Python

I'm trying to build a simple word recognition system in python. As a first step, I needed to find a way to get audio sample data from my microphone and store it in a numpy array in Python. After a lot of searching and experimenting I finally found a library that works well for this task: pyalsaaudio.

This small piece of code records roughly two seconds of audio from the default microphone and plots the spectrogram. This was actually a bit tricky to figure out so I thought I'd share the code for anyone out there who might be trying to do this.
#!/usr/bin/python

import struct
import alsaaudio as aa
import numpy as np
import time
import matplotlib.pyplot as plt
from pylab import *

SAMPLERATE = 8000
PERIODSIZE = 160
CHANNELS   = 1
CARD = 'default'


inp = aa.PCM(aa.PCM_CAPTURE, aa.PCM_NONBLOCK, CARD)
inp.setchannels(1)
inp.setrate(SAMPLERATE)
inp.setformat(aa.PCM_FORMAT_S16_LE)
inp.setperiodsize(PERIODSIZE)

sound = np.array([0])

if __name__=='__main__':
    ctr = 20000
    while ctr > 0:
        ctr -= 1
        l,data = inp.read()
        if l:
            samples = struct.unpack('h'*l, data);
            sound = np.append(sound, np.array(samples))
        time.sleep(0.0001)

    print(sound.size)

    
    #plt.plot(sound)
    #plt.ylabel('amplitude')
    #plt.xlabel('time')
    #show()
    
    Pxx, freqs, bins, im = specgram(sound, NFFT=1024, Fs=8000, noverlap=900, cmap=cm.gist_heat)
    show()

Tuesday, 16 June 2015

I have a new website!

So it's summer holidays again! This time I'm spending my holiday as a research intern at NUS in Singapore. I love the labs here! They're absolutely amazing. I got an opportunity to see one of those huge KUKA robotic arms up close. Me and my friends are working on a four legged robot that uses a lot of compliance and underactuation. It's been quite a fun experience. Singapore is a really nice place. I had a little bit of trouble adjusting initially because the rooms we were staying in were quite small. Then I realized that that's a consequence of living in a big congested city like Singapore. Real estate is expensive and cheap accommodation will be small in size.

Moving on, I've been thinking of setting up a website for myself for quite some time. But I never had a big enough block of free time to set it up. So I finally decided to do it during these holidays. It took me almost a week to tweak it to my satisfaction and even then there's a lot of room for improvement. But I think it's finally time to release my website to the internet! It's live at www.ashwinnarayan.com! I've documented a lot of the projects that I've done over the last few years there.

I'm having a little bit of trouble deciding what to do with my Blogger blog. My new website has a blog and I've already imported most of the posts to it. I'm slowly publishing the older posts after fixing some formatting issues. But I'm not sure that I want to leave this blog either. I've been writing in here for years and years. I think I'll keep both the blogs alive and post in both of them. Maybe I will use the blog on my website to post exclusively about technical stuff. Or maybe I'll post on both blogs in parallel for a while.