Installing Octave 4.0 in Ubuntu 14.04

So I already have Octave 3.8.1 in my machine, Ubuntu 14.04, with signal, control and audio package. I want to upgrade it to the newest one, Octave 4.0.0 which has GUI as default and some improvements. How to install Octave 4.0 on Trusty? Here is how, the defaults didn’t works for me (actually it works but has some errors).

Octave 4.0.0 on Ubuntu 14.04 Trusty with GUI as default

Step-by-step:

  1. Add Octave/stable ppa
  2. sudo apt-add-repository ppa:octave/stable
  3. Update and upgrade
  4. sudo apt-get update
    sudo apt-get upgrade
  5. Download and install signal package from Octave-forge
  6. Download from here, and then in Octave do (within directory):

    pkg install signal-1.3.2.tar.gz
  7. Download and install control package from Octave-forge
  8. Download from here, and then in Octave do (within directory):

    pkg install control-2.8.5.tar.gz
  9. Download and install audio pakcage from Octave-forge
  10. Download from here, and then in Octave do (within directory):

    pkg install audio-1.1.4.tar.gz
  11. Install liboctave-dev
  12. sudo apt-get install liboctave-dev
  13. Configure Octave by using dpkg
  14. sudo dpkg --configure octave
  15. Upgrade it again
  16. sudo apt-get upgrade
  17. Now you are set, try to open in: Octave.
  18. octave

Installing Octave 4.0 in Ubuntu 14.04

So I already have Octave 3.8.1 in my machine, Ubuntu 14.04, with signal, control and audio package. I want to upgrade it to the newest one, Octave 4.0.0 which has GUI as default and some improvements. How to install Octave 4.0 on Trusty? Here is how, the defaults didn’t works for me (actually it works but has some errors).

Octave 4.0.0 on Ubuntu 14.04 Trusty with GUI as default

Step-by-step:

  1. Add Octave/stable ppa
  2. sudo apt-add-repository ppa:octave/stable
  3. Update and upgrade
  4. sudo apt-get update
    sudo apt-get upgrade
  5. Download and install signal package from Octave-forge
  6. Download from here, and then in Octave do (within directory):

    pkg install signal-1.3.2.tar.gz
  7. Download and install control package from Octave-forge
  8. Download from here, and then in Octave do (within directory):

    pkg install control-2.8.5.tar.gz
  9. Download and install audio pakcage from Octave-forge
  10. Download from here, and then in Octave do (within directory):

    pkg install audio-1.1.4.tar.gz
  11. Install liboctave-dev
  12. sudo apt-get install liboctave-dev
  13. Configure Octave by using dpkg
  14. sudo dpkg --configure octave
  15. Upgrade it again
  16. sudo apt-get upgrade
  17. Now you are set, try to open in: Octave.
  18. octave
     

Update to 4.0.1

  1. Download the source
  2. Download the latest GNU Octave binary from here, choose the .tar.gz file >> http://ftp.gnu.org/gnu/octave 

  3. Install the Dependencies
  4. sudo apt-get install libblas-dev liblapack-dev libpcre3-dev libarpack2-dev libcurl4-gnutls-dev epstool libfftw3-dev transfig libfltk1.3-dev libfontconfig1-dev libfreetype6-dev libgl2ps-dev libglpk-dev libreadline-dev libhdf5-dev llvm-dev lpr libosmesa6-dev pstoedit portaudio19-dev libqhull-dev libqrupdate-dev libqscintilla2-dev libqt4-dev libqtcore4 libqtwebkit4 libqt4-network libqtgui4 libqt4-opengl-dev libsuitesparse-dev libxft-dev zlib1g-dev libportaudio19-dev
  5. ./Configure, Make, Make install
  6. Extract the .tar.gz file, cd to that directory and install with,

    mkdir build
    cd build
    ../configure
    make
    sudo make install

Computation at VibrasticLab

The following slide I made for smr2761: Workshop on Computational Science Infrastructure and Applications for Academic Development, or simply as HPC workshop (high performance computing) in Trieste, 28 September ~ 9 October 2015. At the first day, we are required to introduce our selves, explain the current computing facilities, the future plan for development and our expectation from the workshop. This is my slide from VibrasticLab. 
  https://drive.google.com/file/d/0B2cAmw9oV5cuQUZvc3VmaUJLZEE/preview

Computation at VibrasticLab

The following slide I made for smr2761: Workshop on Computational Science Infrastructure and Applications for Academic Development, or simply as HPC workshop (high performance computing) in Trieste, 28 September ~ 9 October 2015. At the first day, we are required to introduce our selves, explain the current computing facilities, the future plan for development and our expectation from the workshop. This is my slide from VibrasticLab. 
 

Matlab in Terminal: Nodesktop Vs Nojvm

There are two choices to use Matlab in terminal or console (under Unix and Linux-based OS), with option -nodesktop or -nojvm. The following two pictures are the similar of Matlab running in terminal with those different options/arguments.

Matlab with nodesktop

Matlab with nojvm

What’s the difference?

So, what’s the different?  It looks same from the terminal, but with nojvm we cannot do anything which needs java like figure/plot, animation, help and other but with nodesktop we can still do plot, figure, edit and other. When we command plot or figure , matlab with -nojvm will give the following error,

Error using figure
This functionality is no longer supported under the -nojvm startup option. For
more information, see “Changes to -nojvm Startup Option” in the MATLAB Release
Notes. To view the release note in your system browser, run
web(‘http://www.mathworks.com/help/matlab/release-notes.html#btsurqv-6’,
‘-browser’).

So, if you want to make computation with no figure, it is better to use matlab with -nojvm, but if you want to make plot just use matlab with -nodesktop. Using matlab with -nojvm will save approximateley 400 MB of RAM. However, using Matlab with -nodesktop does not save any substantial memory.

Memakai Matlab atau GNU Octave?

Ada banyak halaman yang membahas perbedaan antara Matlab dan GNU/Octave. Perbedaan secara teknis bisa dilihat di halaman Wikibooks: MATLAB Programming/Differences between Octave and MATLAB, perbedaan dari sisi desain (compiler, core, dll) bisa dilihat di FAQ octave, dan perbedaan secara sintaks bisa dilihat disini. Lalu, mana yang dipilih, Matlab atau Octave?

Matlab (kiri) dan GNU Octave (kanan) dalam satu workspace


Bagi saya, memakai Matlab atau Octava tergantung apa kata Bos. Kalau dahulu bos saya (baca: Sensei/Professor) memaksa saya memakai Octave, saya harus menurutinya (agar lulus master), dan sekarang Kalab (Kepala Lab) lebih familiar dengan Matlab, maka mau tak mau saya pun harus membiasakan diri kembali memakai Matlab.

Secara individu, tentu saya lebih ingin memakai Octave, namun saya perlu belajar lebih dan hal tersebut akan lebih menyita waktu (that is a challange!). Dan meski memakai Matlab, saya tetap akan stay up-to-date terhadap Octave sehingga kelak ketika saya berkuasa penuh saya dapat menggunakan program tersebut dengan mudah… 🙂

Note: Octave tersedia gratis dan open-source sedangkan Matlab berbayar dan propietary.

Update May 24, 2015:
Saya sedang mempertimbangkan untuk kembali menggunakan Octave karena free dan open source.

Memakai Matlab atau GNU Octave?

Ada banyak halaman yang membahas perbedaan antara Matlab dan GNU/Octave. Perbedaan secara teknis bisa dilihat di halaman Wikibooks: MATLAB Programming/Differences between Octave and MATLAB, perbedaan dari sisi desain (compiler, core, dll) bisa dilihat di FAQ octave, dan perbedaan secara sintaks bisa dilihat disini. Lalu, mana yang dipilih, Matlab atau Octave?

Matlab (kiri) dan GNU Octave (kanan) dalam satu workspace


Bagi saya, memakai Matlab atau Octava tergantung apa kata Bos. Kalau dahulu bos saya (baca: Sensei/Professor) memaksa saya memakai Octave, saya harus menurutinya (agar lulus master), dan sekarang Kalab (Kepala Lab) lebih familiar dengan Matlab, maka mau tak mau saya pun harus membiasakan diri kembali memakai Matlab.

Secara individu, tentu saya lebih ingin memakai Octave, namun saya perlu belajar lebih dan hal tersebut akan lebih menyita waktu (that is a challange!). Dan meski memakai Matlab, saya tetap akan stay up-to-date terhadap Octave sehingga kelak ketika saya berkuasa penuh saya dapat menggunakan program tersebut dengan mudah… 🙂

Note: Octave tersedia gratis dan open-source sedangkan Matlab berbayar dan propietary.

Memfilter Sinyal Suara Pada Range Frekuensi Tertentu (Bandpass) dengan Matlab / Octave

Buka – buka file lama di folder kuliah S1 Teknik Fisika, saya menemukan file script matlab yang saat itu dimintai tolong seorang teman untuk mengerjakan Tugas Akhirnya. Script ini untuk memfilter sinyal (suara) pada frekuensi tertentu dengan menggunakan bandpass filter, yakni gabungan antara low pass filter dan high-pass filter.

Misalnya kita mempunyai sinyal suara dengan frekuensi 0 – 20000 Hz, namun karena suatu hal (misalnya noise) kita cuma butuh sinyal di frekuensi 700 – 1400 Hz saja, maka kita bisa menggunakan script matlab / octave ini. Script ini berjalan lancar baik pada Matlab maupun GNU Octave.

Gambar spectrogram di bawah ini membandingkan spectrogram sinyal sebelum difilter dan setelah difilter. Script untuk GNU / Octave ada di bawahnya.

Sinyal Sebelum di filter
Sinyal Setelah di filter

Berikut script kode Octave / Matlab (link Github disini).

% demo program untuk memfilter suara pada range fekuensi oktaf tertentu
% by bagustris bagustris@linuxmail.org
% adopted from somewhere (forget aka lupa)

% set general variables
clear all; close all; clc;
sf = 22050; % sample frequency
nf = sf / 2; % nyquist frequency
d = 1.0; % duration, ganti untuk merubah durasi suara
n = sf * d; % number of samples
nh = n / 2; % half number of samples

% set variables for filter
lf = 700; % lowest frequency, ganti dengan batas bawah bandpass
hf = 1400; % highest frequency, ganti dengan batas atas bandpass
lp = lf * d; % ls point in frequency domain
hp = hf * d; % hf point in frequency domain

% band pass filter!
filter = zeros(1, n); % initializaiton by 0
filter(1, lp : hp) = 1; % filter design in real number
filter(1, n - hp : n - lp) = 1; % filter design in imaginary number

% make noise
rand('state',sum(100 * clock)); % initialize random seed
noise = randn(1, n); % Gausian noise
noise = noise / max(abs(noise)); % -1 to 1 normalization

% do filter
s = fft(noise); % FFT
s = s .* filter; % filtering
s = ifft(s); % inverse FFT
s = real(s);

%untuk mendengarkan suara asli
sound(noise,sf);
pause(d+0.5);

%untuk mendengarkan suara terfilter (bandpass);
sound(s,sf);
pause(d+0.5);

%untuk menyimpan file suara dalam format .wav
%ketik perintah berikut dalam command window (tanpa tanda persen%)
% wavwrite(s,sf 'namafile.wav');

Untuk mengecek hasilnya (spectrum yang telah terfilter) bisa menggunakan spectrogram sbb:

figure(1); specgram(noise, 512, sf);
figure(2); specgram(s, 512, sf);

Silakan dicoba. Please note the correctness and accurateness is not guaranteed.

Memfilter Sinyal Suara Pada Range Frekuensi Tertentu (Bandpass) dengan Matlab / Octave

Buka – buka file lama di folder kuliah S1 Teknik Fisika, saya menemukan file script matlab yang saat itu dimintai tolong seorang teman untuk mengerjakan Tugas Akhirnya. Script ini untuk memfilter sinyal (suara) pada frekuensi tertentu dengan menggunakan bandpass filter, yakni gabungan antara low pass filter dan high-pass filter.

Misalnya kita mempunyai sinyal suara dengan frekuensi 0 – 20000 Hz, namun karena suatu hal (misalnya noise) kita cuma butuh sinyal di frekuensi 1000 – 4000 Hz saja, maka kita bisa menggunakan script matlab / octave ini. Script ini berjalan lancar baik pada Matlab maupun GNU Octave.

Gambar spectogram di bawah ini membandingkan spectogram sinyal sebelum difilter dan setelah difilter. Script untuk GNU / Octave ada di bawahnya.

Sinyal Noise

Sinyal setelah difilter

Berikut script kode Octave / Matlab (link Github disini).

% demo program untuk memfilter suara pada range fekuensi oktaf tertentu
% by bagustris bagustris@linuxmail.org
% adopted from somewhere (forget aka lupa)

% set general variables
clear all; close all; clc;
sf = 22050; % sample frequency
nf = sf / 2; % nyquist frequency
d = 1.0; % duration, ganti untuk merubah durasi suara
n = sf * d; % number of samples
nh = n / 2; % half number of samples

% set variables for filter
lf = 1000; % lowest frequency, ganti dengan batas bawah bandpass
hf = 4000; % highest frequency, ganti dengan batas atas bandpass
lp = lf * d; % ls point in frequency domain
hp = hf * d; % hf point in frequency domain

% band pass filter!
filter = zeros(1, n); % initializaiton by 0
filter(1, lp : hp) = 1; % filter design in real number
filter(1, n - hp : n - lp) = 1; % filter design in imaginary number

% make noise
rand('state',sum(100 * clock)); % initialize random seed
noise = randn(1, n); % Gausian noise
noise = noise / max(abs(noise)); % -1 to 1 normalization

% do filter
s = fft(noise); % FFT
s = s .* filter; % filtering
s = ifft(s); % inverse FFT
s = real(s);

%untuk mendengarkan suara asli
sound(noise,sf);
pause(d+0.5);

%untuk mendengarkan suara terfilter (bandpass);
sound(s,sf);
pause(d+0.5);

%untuk menyimpan file suara dalam format .wav
%ketik perintah berikut dalam command window (tanpa tanda persen%)
% wavwrite(s,sf 'namafile.wav');

Silakan dicoba. Please note the correctness and accurateness is not guaranteed.

Image Compression in GNU Octave and Matlab

Suppose you have an image file namely “image.jpg”. Due to the file size, you want to compress it to smaller size. In GNU Octave and Matlab, the following simple commands can be used,

image=imread('image.jpg');

imwrite(image,'image_new.jpg','quality',50);

Those commands will compress “image.jpg” to “image_new.jpg” with the quality of compressed image is 50% of the original image.Please note, the current supported image format. when I wrote this article, is .jpg only.