Nugroho's blog.

Saturday, October 3, 2015

Fourier Transform using Delphi

 It's not Discrete Fourier Transform.

 Instead, I use continue definition (using Integral, not Sum) to compute the transformation. I know, it's weird, but it's worth a try, :)

 What I did is transform signal with 3 frequency, remove the two frequency and trasform back to time-signal.










unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
Memo1: TMemo;
Image2: TImage;
Image3: TImage;
Image4: TImage;
procedure proses;
procedure gambarFungsi;
procedure gambarSumbu;
procedure gambarTransformasi;
procedure olahTransformasi;
procedure gambarOlahTransformasi;
procedure transformasiBalik;
procedure gambarTransformasibalik;
function f(x:real):real;
procedure Timer1Timer(Sender: TObject);
private
public
end;

const
a=200;
b=150;

var
Form1: TForm1;
x0,y0,xm,ym:integer;
s,ss:array[-a..a]of real;
ft:array[-b..b]of real;
implementation
{$R *.dfm}
function tform1.f(x:real):real;
begin
f:=cos(PI*x)+cos(2*PI*x)+cos(4*PI*x);
end;
procedure tform1.transformasiBalik;
var i,j:integer;
t,w,dt:real;
begin{}
dt:=0.1;
for i:=-a to a do begin
w:=i/10;
ss[i]:=0;
for j:=-b to b do begin
t:=j/10;
ss[i]:=ss[i]+ft[j]*cos(w*t)*dt
end;
end;
gambarTransformasiBalik;
end;

procedure tform1.olahTransformasi;
var i:integer;
begin
for i:=-b to b do begin
if abs(i)>50 then ft[i]:=0;
end;
gambarOlahTransformasi;
end;

procedure tform1.proses;
var i,j:integer;
t,w,dt:real;
begin
form1.Caption:='transformasi';
gambarSumbu;
{transformasi}
dt:=0.1;
for i:=-a to a do begin
s[i]:=f(i/30);
end;
for i:=-b to b do begin
w:=i/10;
ft[i]:=0;
for j:=-a to a do begin
t:=j/10;
ft[i]:=ft[i]+f(t)*cos(w*t)*dt
end;
end;
gambarFungsi;
gambarTransformasi;
olahTransformasi;
transformasiBalik;
end;

procedure tform1.gambarFungsi;
var i,xo,yo,xt,yt:integer;
begin
xo:=-a; yo:=0;
for i:=-a to a do begin
xt:=i;
yt:=round(10*s[i]);
with image1.Canvas do begin
moveto(x0+xo,y0-yo);lineto(x0+xt,y0-yt);
end;
xo:=xt;
yo:=yt;
end;
end;

procedure tform1.gambarTransformasibalik;
var i,xo,yo,xt,yt:integer;
begin
xo:=-a; yo:=0;
for i:=-a to a do begin
xt:=i;
yt:=round(10*ss[i]);
with image4.Canvas do begin
moveto(x0+xo,y0-yo);lineto(x0+xt,y0-yt);
end;
xo:=xt;
yo:=yt;
end;
end;

procedure tform1.gambarOlahTransformasi;
var i,xo,yo,xt,yt:integer;
begin
{}
xo:=-b; yo:=0;
for i:=-b to b do begin
xt:=i;
yt:=round(10*ft[i]);
with image3.Canvas do begin
moveto(x0+xo,y0-yo);lineto(x0+xt,y0-yt);
end;
xo:=xt;
yo:=yt;
end;
end;

procedure tform1.gambarTransformasi;
var i,xo,yo,xt,yt:integer;
begin
xo:=-b;yo:=0;
for i:=-b to b do begin
xt:=i;
yt:=round(10*ft[i]);
with image2.Canvas do begin
moveto(x0+xo,y0-yo);lineto(x0+xt,y0-yt);
end;
xo:=xt;
yo:=yt;
end;
end;

procedure tform1.gambarSumbu;
begin
x0:=image1.Width div 2;
y0:=image1.Height div 2;
xm:=image1.Width;
ym:=image1.Height;
with image1.Canvas do begin
moveto(0,y0);lineto(xm,y0);moveto(x0,0);lineto(x0,ym);
end;
with image2.Canvas do begin
moveto(0,y0);lineto(xm,y0);moveto(x0,0);lineto(x0,ym);
end;
with image3.Canvas do begin
moveto(0,y0);lineto(xm,y0);moveto(x0,0);lineto(x0,ym);
end;
with image4.Canvas do begin
moveto(0,y0);lineto(xm,y0);moveto(x0,0);lineto(x0,ym);
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
timer1.Enabled:=false;
proses;
end;

end.

HFS+ (Journaled) Flash Drive on Ubuntu

 I have no problem mount it on Centos, read and write mode.

 But, on Ubuntu, it needs some works.

 Install hfsprogs

 
sudo apt-get install hfsprogs


 umount the drive if it's already meunted


sudo umount /dev/sdb2


create folder to mount the drive


mkdir flash


mount again


sudo mount -t hfsplus -o force,rw /dev/sdb2 flash


It works for me, but it need sudo privilege to write to it. Maybe because it's journaled and ubuntu didn't support journaled HFS+ filesystem.

At least it works, :)

Friday, October 2, 2015

#MelawanAsap

 Yang tak terlupa, saat ada acara pembacaan surat YaaSin di rumah, ikut tradisi setempat, saat bapak meninggal.

 Yeah, bapak meninggal, itu sulit dilupakan.

 Tapi beberapa minggu ini ada yang mengungkit-ungkit kenangan itu lagi, kebakaran di Sumatera dan Kalimantan.

 Bukan tentang bapak yang diungkit (mudah sekali mengingat kejadiaan itu), tetapi tentang asap.

 Apa yang terjadi saat pembacaan surat YaaSin? Tentu saja, membaca surat YaaSin bersama-sama, diawali surat-surat pendek untuk pemanasan, Yaasin, trus doa-doa yang dipimpin secara estafet oleh dua pemuka agama.

 Yang terungkit oleh kebakaran di SwarnaDwipa dan Borneo justru sebelum acara. Ketika tamu mulai datang dan menunggu yang lain. Harus menemui tamu itu jelas, dan kebanyakan mereka adalah perokok! Hm, mereka merokok sebelum mendoakan seseorang yang meninggal akibat rokok, ckckck.

 Ketika acara akan mulai, tamu sudah semakin banyak, delapan puluh lebih. Ruangan sudah penuh hingga meluber ke halaman. Juga asap rokoknya.

 Sehari, ..., OK

 Dua hari, OOOOK...

 Hari ketiga, KO..., ke bidan, kena radang tenggorokan parah, harus minum 7 jenis pil.


 (dan ada dua pil yang mempunyai kandungan sama, sehingga dosisnya tanpa sengaja dobel, efeknya ketiga terbangun jam tiga pagi mau pipis, gak bisa gerak, otot kaku njarem, seperti habis berlari sprint sepuluh kilo, atau habis nabrak sedan diam dengan naik sepeda 80km/jam [sudah pernah mengalami, :) ])

 That's it. Asap, cuma terpapar tiga hari, dan setiap hari hanya sekitar dua jam.

 Bayangkan saudara kita di Sumatera dan Kalimantan.  Mereka di Pulau Emas dan Borneo terpapar setiap saat selama berminggu-minggu. SwarnaDwipa sedang berduka.

Thursday, October 1, 2015

My El Capitan

 On MacbookAir, :)







My VLC crashed

Matplotlib Python module's not working, (visual python's running without problem)









Monday, September 28, 2015

Annabeth and Magnus Chase, :)



 “I have an uncle and cousin in Boston”.

 (Excerpt From The Blood of Olympus).

 “...a teenager wouldn’t be wrapped in a stinky old sleeping bag, stuck outside in the middle of a Boston winter”.

 “Annabeth. Which meant the sandy-haired man was … Uncle Frederick?”.

 “You’re lucky you live with your momma. Annabeth stacked another domino on......” {Annabeth's not live with her mother (Athena) and/or have problem with her stepmother}

 "Annabeth looked at me. Her grey eyes..."

 "Frederick and Annabeth still lived in Virginia..."



 ( Excerpt From Magnus Chase and The gods of Asgard: The Sword of Summer preview on Percy Jackson and the Greek Heroes)

"He had sandy-colored hair like Annabeth ..."

“Dr. Chase jumped up and started patting his pockets. “My keys…” His wife sighed. “Frederick, honestly. You'd lose ”

“Ah, well. You did leave quite a few half-blood weapons in your room in Virginia, the last time you… left.” Annabeth looked down, embarrassed. I noticed Dr. Chase was very careful not to say ran away.”

(Excerpt From The Titan's Curse)

Yep, apparently they're cousin, :)

Friday, September 25, 2015

Update Value using Slider in Visual Python


 Here's the code.
 The slider act as..., well..., slider... to change the value on TextCtrl. On slight modification, it'll able to change any variable value.



from __future__ import division, print_function
from visual import *
import wx

L = 400
H = 200
d = 20


def setrate(evt):
value = s1.GetValue()
tc.Clear()
tc.write('kecepatan = '+ str(value)) #mengeset kecepatan sesuai slider


w = window(width=2*(L+window.dwidth), height=L+window.dheight+window.menuheight+H,
menus=True, title='Widgets',
style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX)

#panel#
p = w.panel

tc = wx.TextCtrl(p, pos=(1.4*L,90), value='Tulisan\n',
size=(150,90), style=wx.TE_MULTILINE)
tc.SetInsertionPoint(len(tc.GetValue())+1)
tc.SetFocus()

s1 = wx.Slider(p, pos=(1.0*L,0.8*L), size=(0.9*L,20), minValue=0, maxValue=100)
s1.Bind(wx.EVT_SCROLL, setrate)
wx.StaticText(p, pos=(1.0*L,0.75*L), label='kecepatan')

#standart mantra for vpython#
while True:
rate(100)

.
.
 

Update Visual.Graph Python

 The code below's from vpython example program, modified here and there, of course, :). It plots 5.0+5.0*cos(-0.2*t-p)*exp(0.015*t). Notice that p is act as phase, so the plot will 'walk'. The essential part is

 funct1.gcurve.pos=[]

 without it, the graph wont refresh the old curve (the old plot wouldn't be erased)



from __future__ import division, print_function
from visual import *
from visual.graph import *
import wx

L = 400
H = 200

w = window(width=2*(L+window.dwidth), height=L+window.dheight+window.menuheight+H,
menus=True, title='Widgets',
style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX)

funct1 = gcurve(color=color.cyan)

p = 0.

while True:
rate(100)
funct1.gcurve.pos=[]
for t in arange(-30, 74, 1):
funct1.plot( pos=(t, 5.0+5.0*cos(-0.2*t-p)*exp(0.015*t)) )
p = p + 0.1
if p >100:
p = 0

.



.
 
323f (5) amp (1) android (12) apple (7) arduino (18) art (1) assembler (21) astina (4) ATTiny (23) blackberry (4) camera (3) canon (2) cerita (2) computer (106) crazyness (11) debian (1) delphi (39) diary (286) flash (8) fortran (6) freebsd (6) google apps script (8) guitar (2) HTML5 (10) IFTTT (7) Instagram (7) internet (12) iOS (5) iPad (6) iPhone (5) java (1) javascript (1) keynote (2) LaTeX (6) lazarus (1) linux (29) lion (15) mac (28) macbook air (8) macbook pro (3) macOS (1) Math (3) mathematica (1) maverick (6) mazda (4) microcontroler (35) mountain lion (2) music (37) netbook (1) nugnux (6) os x (36) php (1) Physicist (29) Picture (3) programming (189) Python (109) S2 (13) software (7) Soliloquy (125) Ubuntu (5) unix (4) Video (8) wayang (3) yosemite (3)