onsdag 11 juni 2014

Finding maximum correction for three samples

I always recalculate this when I need it, but now it is time to save it somewere.


You have three samples y1 y2 y3. and you want to know there the maximum is, if you do a quadratic regression from it. We here assume that the distance between the points in the x-axis is 1.

First, lets do the quadratic regression
We describe the graph as y = ax² + by + c

So we want the values of a, b and c

for y2 = y(x = 0) we have
y2 = a·0 + b·0 + c → 
c = y2

We then have that 
y1 = y(-1) = a·(-1)² + b·(-1) + c →
y1 = a - b + c →   (c = y2)
y1 = a - b + y2

and also in a similar fashion 
y3 = y(1) = a·1² + b·1 + c →
y3 = a + b + y2

Therefore we can take
y3 - y1 = 2b →
b = (y3 - y1) / 2

and
y1 + y3 = 2a + 2c = 2a + 2y2
2a = y1 + y3 - 2y2
a = (y1 + y3)/2 - y2


To get the maximum of the graph, we just have to find the zero of the derivative y'.
y = ax² + bx + c →
y' = 2ax + b

0 = y'
0 = 2ax + b
0 = 2((y1 + y3) / 2 + y2)·x + (y3 - y1)/2
2((y1 + y3) / 2 - y2)·x = -(y3 - y1)/2
(y1 + y3 - 2y2)·x = (y1 - y3)/2
x =  (y1 - y3) / (y1 + y3 - 2y2) / 2

...Done once for all.


torsdag 14 november 2013

Fixing strange apt-get update error in xubuntu


I got this strange error when trying to do apt-get update on my xubuntu:

W:Failed to fetch http://archive.ubuntu.com/ubuntu/dists/saucy/Release Unable to find expected entry 'universedeb/source/Sources' in Release file (Wrong sources.list entry or malformed file)


Or in swedish:
Hämtade 13,0 kB på 17s (750 B/s)
W: Misslyckades med att hämta http://archive.ubuntu.com/ubuntu/dists/saucy/Release  Kunde inte hitta förväntad post "universedeb/source/Sources" i Release-filen (Felaktig post i sources.list eller felformulerad fil)

E: Några indexfiler gick inte att hämta. De kommer att ignoreras eller så används de gamla istället.

So after searching the web: i got the idea to inactivate random repositories in my /etc/apt/sources.list file.

I found that by deactivating part of this section this :
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu saucy universe
deb-src http://archive.ubuntu.com/ubuntu saucy universedeb http://se.archive.ubuntu.com/ubuntu/ saucy-updates universe
deb-src http://archive.ubuntu.com/ubuntu saucy-updates universe


by commenting (putting # before)
deb-src http://se.archive.ubuntu.com/ubuntu/ saucy universedeb http://se.archive.ubuntu.com/ubuntu/ saucy-updates universe
The problem disappeared.

Still dont krow what's behind the strange error.. but now I can at least use my computer as normal.

torsdag 17 oktober 2013

Extract clips of a video and put them together in a single video in terminal

So during a group assignment i needed to clip some videos of youtube. This is how I did it:

First i got the file from youtube using the download helper. Excellent tool by the way. (I downloaded the videos as flv, when downloading them as avi, i got some strange audio synching issues.)

Then I wrote a script to extract my clips from the video. (That was after trying every gui based solution to extract clips)

#!/bin/bash

declare -a startt=(
2:24
5:22
10:32
16:04
16:53
20:00
22:18
);

declare -a lent=(
02:57
03:33
00:46
00:15
02:03
01:45
00:57
);


for I in 0 1 2 3 4 5 6
do
avconv -i Presentationsfilmer/edge.flv -ss 00:${startt[$I]} -t 00:${lent[$I]} -vcodec  copy -acodec copy "clip$I.flv"
done


I got the start and the end times by watching the videos. Then i calculated the length, as needed by the script using Libre Office Calc.. I did not want to do it in my head.

And then for putting it all together... I never did it.. It seamed impossible to find a tool to just merge the different clips.. So I just made a playlist in totem instead. I guess that that gives the video editing in Linux a Failed grade, unfortunately....

So the result.. I still hate to edit movies in Linux, it took much more time than I possibly could imagine. In the future i would probably just use Youtubes video editing tool... That's it for today. So long!

tisdag 15 oktober 2013

How to use a laptop with no screen

My laptop broke. So i thought of throwing it away before I realized the obvious in making a simple server from it. The most usable reason for me to turn it into a server was to be able to use the computational power to run synthesizers wich my secondary computer could not manage. This is the two steps i made.

install ssh

Since i already had ubuntu installed from the beginning. The only thing i really needed to do to convert it to some kind of server was to install ssh:

sudo apt-get install openssh-server

Then to use the computer all I needed to do on the client side was

ssh (ip to the computer) -X

(-X is to be able to run graphical applications as nautilus, gedit, och google-chrome [but to be onest, to run google chrome over forwarded x is a bit overkill] )

wake on lan

It would be possible to keep the computer turned on all the time, but because my computer makes a lot of noise i rather turn it off sporadically. Since my laptop has its powerbutton under the lid, I figured out that it would be most practical to be able to boot it from somewere else. And thats how i came up with the wake up on lan. For my lenovo T61 the wake on lan feature was enabled by default. I got the network card name from my router.. (format 00:00:00:00:00 something) and then i use the awesome command powerwake when i need to start the computer. Works like magic

powerwake (mac-addr)


måndag 7 oktober 2013

Archlinux

My first try to install archlinux. (On virtual box)

This is problems I came across

Keyboard layout:

Since i use the swedish-dvorak layout-that was the first thing I had to get fixed...

The archwiki had instructions to change the layout... locked at that.. Seems like the dvorak layout is installed by deafult

localectl list-keymaps
...

localectl set-keymap --no-convert dvorak-sv-a5

...seems to do kind of the job.. not the same layout for special characters as i am used to but it will work..

in the beginning it looks like you can do 
loadkeys layout


Changing keyboardlayout in x
setxkb -layout se -variant dvorak

then change the xorg.conf (add)

Mounting disk

(assuming the disks are already formated in some fancy fashion) 
In order to install you must mount the hard drive


Working network in fresh install

For some reason my network didn't seem to work on the fresh install. I found this page with the solution in the end. Just run
dhcpcd
and it worked 

Sudo

To be able to install programs with your user it can be convenient to install sudo.

first: $pacman -S sudo

$export VISUAL=   (standard is vi)

use $visudo

add 
ALL = (ALL) ALL

somwhere or

% ALL = (ALL) ALL

Miscellaneous

autocompletion: bash-autocompleton

 

... For this time i gave up... I couldn't get the wireless card to work on my laptop, and on my raspberry pi complation took to much time or did not work at all. I learned a lot about how linux works however so I recomend anybody interested to do the same journey. I have allready used my knowledge on my debian-based linux computers.

Running fluidsynth in my raspberry pi

I must publish this so i can remember it. I had som trouble to start fluidsynth in the background when i did.

fluidsynth -a oss /usr/share/sounds/sf2/FluidR3_GM.sf2 &

however after finding this post i solved it by using

 fluidsynth -a oss -s -i /usr/share/sounds/sf2/FluidR3_GM.sf2 &

and everything works like a charm. Next step is to start fluidsynth with a init.d script.. but that is for tomorrow...

I havent figured out how to change instrumment though (within the same sound-font file)

Good night

söndag 21 juli 2013

How I finally managed to install jack on my raspberry pi


To make jack audio work on the raspberry pi you need to have a patched version of jack audio installed. On the linux audio page there was some information of how to add repository lists. How ever i never succeeded to install those, but found on link to deb-files to the patched versions of jackd and libjack2.

Since i already had jackd and libjack installed i used

dpkg -r --force-depends jackd libjack0

to remove the version of jack I already had installed, without removing programs depending on jack, followed by

dpkg -i *.deb
sudo apt-get -f install


And at last.. The command that finally got jack running on my usb-card for me was : jackd -P84 -p8 -t3500 -d alsa -dhw:Set -p128 -n3 -r48000 -s &



Of course that was before i killed my raspberry by plugging in to much stuff in the usb-port and installing packages at the same time.. 

-- note: --
As an alternative i found that using the oss emulation was not that bad for ordinary synths, as amsynth. Before i got jack up and running I used this method temporarily. Now when I know how to get jack running i hope i will not have to use it again, but here it is for reference usage:

The natural alternative was portaudio, but after some research i found out that more synths were made to rely solely on jack or oss (/dev/dsp). So I decided to install the oss compatibility layer for alsa.

sudo apt-get install alsa-oss
sudo modprobe snd_pcm_oss


the "modprobe" part makes the /dev/dsp file appear, and can be inserted into /etc/rc.local to have it loaded on startup