Punya dhee2 a=input('masukkan nilai a:'); fprintf('nilai a adalah %g',a); f=input('masukkan nilai f:'); fprintf('nilai f adalah %g',f); t=input('masukkan nilai t:'); fprintf('nilai t adalah %g',t) fase=input('masukkan nilai fase:'); phase=(fase*pi)/180; T=0:.1:t; y=a*(sin((2*pi*f*T)+phase)); n=t; for i=1:n s(i)=1 end subplot(311); plot(T,y); subplot(312); stem(s); subplot(313); stem(T,y);
subplot(3,1,1); plot(T,y); %penggambaran grafik fungsi sinus title('Grafik Fungsi Sinus'); xlabel('t'); ylabel('y(t)'); subplot(3,1,2); stem(s); subplot(3,1,3); stem(T,y); %penggambaran nilai fungsi waktu diskrit title('Grafik Hasil Digitalisasi'); xlabel('t'); ylabel('yi'); grid on
PROGRAM FILTER
punya astha
%---------------------------------%Program Digitalisasi Fungsi Sinus %Oleh : Astha Dandari (11792) %---------------------------------clear all; clc; disp('-------------------------------'); disp('Program Fungsi Sinus'); disp('-------------------------------'); a f t Q
= = = =
input('Nilai Amplitudo (a) = '); input('Nilai Frekuensi (f) = '); input('Time (t) = '); input('Fase (Q) = ');
phase=(Q*pi)/180; T = 0:.1:t; y = a*sin((2*pi*f*T)+phase); n=t; for i=1:n s(i)=1 end
%input %input %input %input
amplitudo frekuensi waktu fase
%waktu dari 0 sampai t %fungsi sinus
%FILTERING f1=20; a1=1.0; f2=35; a2=0.75; f3=15; a3=1.25; f4=40; a4=0.60; f5=50; a5=1.5; f6=25; a6=1.15; %waktu sampling, frek cut off, jumlah data sampling dt=0.001; n=512; FL=15; FH=45; %jumlahan fungsi sinus for i=1:n; s1(i)=a1*sin(2*pi*f1*dt*(i-1)); s2(i)=a2*sin(2*pi*f2*dt*(i-1)); s3(i)=a3*sin(2*pi*f3*dt*(i-1)); s4(i)=a4*sin(2*pi*f4*dt*(i-1)); s5(i)=a5*sin(2*pi*f5*dt*(i-1)); s6(i)=a6*sin(2*pi*f6*dt*(i-1)); s=s1+s2+s3+s4+s5+s6; end subplot (7,1,1); plot(s1); subplot (7,1,2); plot(s2); subplot (7,1,3); plot(s3); subplot (7,1,4); plot(s4); subplot (7,1,5); plot(s5); subplot (7,1,6); plot(s6); subplot (7,1,7); plot(s); title('Hasil Jumlahan Gelombang Sinus'); xlabel('Time (s)'); ylabel('Amplitudo');
%filtering FN=1/(2*dt); WN=2*pi*FN; WL=2*pi*FL; WH=2*pi*FH; m=512; %low pass filter %tanggap impulse wo=WL/WN; LP(1)=2*wo; for i=2:m; LP(i)=2*wo*sin(pi*wo*(i-1))/(pi*wo*(i-1)); end for i=1:m; HL(i)=LP(m-i+1); HL(m+i)=LP(i); end figure subplot(3,2,1); plot(HL,'b'); title('Tanggap Impulse Low Pass Filter'); xlabel('m'); ylabel('h(n)'); %zerophase response LPF=abs(fft(HL,128)); subplot(3,2,2); plot(LPF,'r'); title('Zero Phase Response'); xlabel('Frekuensi Hz'); ylabel('H(F)'); %Filtering dengan LPF L= conv(HL,s); subplot(3,2,3); plot(L,'r'); title('Filtering Gelombang dengan LPF'); xlabel('Time'); ylabel('Amplitudo'); %Band Pass w2=WH/WN; w3=WL/WN; BP(1)=(WH-WL)/WN; for i=2:m; BP(i)=2/(pi*i)*(sin((i-1)*pi*w2)-sin((i-1)*pi*w3)); end for i=1:m; hB(i)=BP(m-i+1); hB(m+i)=BP(i); end figure subplot (3,3,1); plot(hB,'b'); title('Tanggap Impulse BP Filter'); xlabel('n'); ylabel('h(n)'); %Zero Phase %zerophase response
LPF=abs(fft(hB,128)); subplot(3,3,2); plot(LPF,'r'); title('Zero Phase Response'); xlabel('Frekuensi Hz'); ylabel('H(F)'); %Filtering dengan LPF L= conv(hB,s); subplot(3,3,3); plot(L,'r'); title('Filtering Gelombang dengan LPF'); xlabel('Time'); ylabel('Amplitudo'); %HPF w1=WH/WN; HP(1)=(WN-WH)/WN; for i=2:m; HP(i)=-2*w1*(sin((i-1)*pi*w1)/((i-1)*pi*w1)); end for i=1:m; hH(i)=HP(m-i+1); hH(m+i)=HP(i); end figure subplot(1,1,1); plot(hH); title('High Pass Filter');
dst LPF
clear all; dt=0.001; fl=30; fn=1/(2*dt); wl=2*3.14*fl; wn=2*3.14*fn; w0=wl/wn; w(1)=2*(wl/wn); n=128; for i=2:n; w(i)=2*(wl/wn)*(sin((i-1)*3.14*(wl/wn))/((i-1)*3.14*(wl/wn))); end; for i=1:n; h(i)=w(n-i+1); h(n+i)=w(i); end; figure; %1 %subplot(1,3,1); plot(w); title('Tanggapan Impulse Satu Sisi LPF-FIR'); xlabel('Waktu (mSec)'); pause; figure; %2 %subplot(1,3,1); plot(h(1:256)); title('Tanggapan Impulse LPF-FIR'); xlabel('Waktu (mSec)'); pause; H = fft(h,256);
HH=abs(H); mx=max(HH); PH = H.*conj(H)/256; f = 1000/256*(0:127); %subplot(1,3,2); figure; %3 plot(f(1:25),PH(1:25)); title('Spektrum Amplitudo LPF-FIR'); xlabel('Frekuensi (Hz)'); pause; DB=20*log(HH/mx); %subplot(1,3,3); figure; %4 plot(f(1:25),DB(1:25)); title('Bode Plot LPF-FIR'); xlabel('Frekuensi (Hz)'); pause; m=1000; for i=1:m; x(i)=5*sin(2*pi*5*(i-1)*dt)+2*sin(2*pi*20*(i-1)*dt); x(i)=x(i)+1.5*sin(2*pi*80*(i-1)*dt)+2*sin(2*pi*100*(i-1)*dt); end; figure; %4 plot(x); title('Sinyal Input'); xlabel('Waktu (Det)'); pause; X=fft(x,512); PX=X.*conj(X)/512; figure; %5 plot(f(1:128),PX(1:128)); title('Spektrum Amplitudo Sinyal Input'); xlabel('Frekuensi (Hz)'); pause; y=conv(x,h); Y=fft(y,512); PY=Y.*conj(Y)/512; figure; %6 plot(f(1:128),PY(1:128)); title('Spektrum Amplitudo Hasil LPF'); xlabel('Frekuensi (Hz)'); pause; figure %7 plot(y); title('Sinyal Output Hasil LPF'); xlabel('Waktu (Det)');
BPF
clear all; dt=0.001; fl=20; fh=80; fn=1/(2*dt); wh=2*3.14*fh; wl=2*3.14*fl; wn=2*3.14*fn;
w0=(wh-wl)/wn; n=128; w(1)=w0; %(2/3.14)*(sin(3.14*wh/wn)-sin(3.14*wl/wn)); for i=2:n; w(i)=(2/(i-1)*3.14)*(sin((i-1)*3.14*wh/wn)-sin((i1)*3.14*wl/wn)); end; for i=1:n; h(i)=w(n-i+1); h(n+i)=w(i); end; figure; plot(w); pause; figure; plot(h); H = fft(h,256); HH=abs(H); mx=max(HH); PH = H.*conj(H)/256; f = 1000/256*(0:127); %subplot(1,3,2); figure; %3 plot(f(1:25),PH(1:25)); title('Spektrum Amplitudo LPF-FIR'); xlabel('Frekuensi (Hz)'); pause;
LPF DIDI
t = 0:.002:10; f1=5; f2=20; f3=25; f4=30; f5=60; y=5*sin(2*pi*f1*t)+2.5*sin(2*pi*f2*t)+1.5*sin(2*pi*f3*t) +0.5*sin(2*pi*f4*t)+3*sin(2*pi*f5*t); Y=fft(y); m=abs(Y); subplot(2,1,1), plot(t,y); title('Grafik Sinyal') subplot(2,1,2), plot(t*50,m);axis ([0 100 0 15000]) n=1:length(t)/2+1; L=0.04*sin(n*pi*0.02)./(n*pi*0.02); m=length(n); for i=1:m a(m+i-1)=L(i); a(i)=L(m-i+1); end q=-length(t)/2:length(t)/2-1; figure(); plot(q,a); axis ([-1000 1000 -.04 .1])
title('Low Pass Filter') h=conv(L,y); d=fft(h); e=abs(d); s=1:length(h); figure(); subplot(2,1,1), plot(s,h);axis ([0 10 -20 20]) title('Grafik Sinyal setelah di LPF(20)') subplot(2,1,2), plot(s/15,e); axis ([0 100 0 30000])
HPF DIDI
t = 0:.002:10; f1=5; f2=20; f3=25; f4=30; f5=60; y=5*sin(2*pi*f1*t)+2.5*sin(2*pi*f2*t)+1.5*sin(2*pi*f3*t) +0.5*sin(2*pi*f4*t)+3*sin(2*pi*f5*t); Y=fft(y); m=abs(Y); subplot(2,1,1), plot(t,y); title('Grafik Sinyal') subplot(2,1,2), plot(t*50,m);axis ([0 100 0 15000]) n=1:length(t)/2+1; L=-(0.04)./(n*pi*0.08).*sin(n*pi*0.08); m=length(n); for i=1:m a(m+i-1)=L(i); a(i)=L(m-i+1); end q=-length(t)/2:length(t)/2-1; figure(); plot(q,a); axis ([-600 600 -.04 0.01]) title('High Pass Filter') h=conv(L,y); d=fft(h); e=abs(d); s=1:length(h); figure(); subplot(2,1,1), plot(s,h);axis ([0 10 -20 20]) title('Grafik Sinyal setelah di HPF(20)') subplot(2,1,2), plot(s/15,e);axis ([0 100 0 10000])
BPF DIDI
t = 0:.002:10; f1=5; f2=20; f3=25; f4=30; f5=60; y=5*sin(2*pi*f1*t)+2.5*sin(2*pi*f2*t)+1.5*sin(2*pi*f3*t) +0.5*sin(2*pi*f4*t)+3*sin(2*pi*f5*t); Y=fft(y);
m=abs(Y); subplot(2,1,1), plot(t,y); title('Grafik Sinyal') subplot(2,1,2), plot(t*50,m);axis ([0 100 0 15000]) n=1:length(t)/2+1; L=(2./(n*pi)).*(sin(n*pi*0.12)-sin(n*pi*0.08)); m=length(n); for i=1:m a(m+i-1)=L(i); a(i)=L(m-i+1); end q=-length(t)/2:length(t)/2-1; figure(); plot(q,a); axis ([-1000 1000 -.05 0.05]) title('Band Pass Filter') h=conv(L,y); d=fft(h); e=abs(d); s=1:length(h); figure(); subplot(2,1,1), plot(s,h);axis ([0 10 -20 20]) title('Grafik Sinyal setelah di BPF(20-30)') subplot(2,1,2), plot(s/15,e); axis ([0 100 0 10000])
AUTO KORE
f=10; A=5; for i=1:1000 y(i)=A*sin(2*pi*f*0.001*(i-1)); end; for i=1:1000 z(i)=A*sin(2*pi*f*0.001*(i-1)); end; La=length(y); Lb=length(z); Lc=La+Lb-1; for i=1:Lc; c(i)=0.0; end; for i=1:La; for j=1:Lb; k=i+j-1; c(k)=c(k)+y(i)*z(j); end; end; subplot(121);plot(c);
title(['kross korelasi']) K=crosscorr(y,z);subplot(122);plot(K); title(['krosskorelasi matlab']);
AUTO KONVO
a=[1,2,3] b=[1,2,3] La=length(a); Lb=length(b); Lc=La+Lb-1; for i=1:Lc i=i+1 c(i)=0.0; end for j=1:Lb i=1:La k=i+j-1 c(k)=c(k)+a(i)*b(j) end plot(c)
RICKER WAVELET (tdomain??)
n=75; f=30; dt=0.001; phi=3.14159; n1=(n+1)/2; b=1/(phi*f); for i=1:n1 t1=(i-1)*dt; t2=b; t3=t1/t2; t4=t3*t3; rc(i)=(1-2*t4)*exp(-t4); end; for i=1:n1 rick(n1+i)=rc(i); rick(i)=rc(n1-i+1); end; plot(rick);
RWAVELET
%------------------------------%PROGRAM PEMBUATAN RICKERWAVELET %------------------------------function [R]=rickerwavelet n=25;dt=0.002;f=40; for i=1:n;
a=1-2*(pi*f*dt*(i-1))^2; b=exp(-(pi*f*dt*(i-1))^2); r(i)=a*b; t(i)=dt*(i); end; plot(t,r); title('WAVELET SATU SISI') grid on; for i=1:n R(n+i-1)=r(i); R(i)=r(n-i+1); end k=2*n-1 for i=1:k T(i)=dt*(i); end figure; plot(T-0.05,R); title('TWO SIDED WAVELET') grid on;
JEJAK SEISMIK
lp=700; nr=199; fr=30.0; dt=0.002; np=(nr+1)/2; for i=1:lp x(i)=0.0; x(25)=0.5; x(50)=-0.75; x(75)=0.1; x(100)=0.3; x(200)=0.4; x(400)=-0.2; x(420)=-0.4; x(500)=-0.6; x(600)=0.6; x(650)=0.8; x(675)=-0.2; end for i=1:np t=(i-1)*dt; b=(pi*fr*t)^2;
end
rx(i)=(1-2*b)*exp(-b);
for i=1:np rc(np+i)=rx(i); rc(i)=rx(np-i+1); end y=conv(x,rc); subplot (3,1,1); plot(x,'b'); title('Koefisien Refleksi') subplot (3,1,2); plot(rc,'r'); title('Ricker Wavelet') subplot (3,1,3); plot(y); title('Trace Seismik')
KONVO FORTRAN
10 20 30 40
50 60
dimension K(100), M(200), N(300) write(*,' (20x,A)')'Konvolusi' write(*,' (20x,A)')'Masukkan nilai m dan n' write(*,' (20x,A)')'Juga nilai a dan b' write(*,10) read(*,20) format(1x, 'Jumlah M :',M4,/) format (M3) write(*,30) read(*,40) format(1x,' Jumlah N :',N4,/) format(N3) do 100 I=1,M write(*,50)I read(*,70)A(I) format(1x,'data a ke-',M4,':')
do 110 J=1,N write(*,60)Jformat(1,x'data b ke-',N4,':') 100 format(F7.2,/) 110 format(F7.2,/) jumlah data A = M jumlah data B = N K = N + M -1 do L=1,K c(L) = 0.0
continue do I=1,M do J=N,1,-1 L=I+J-1 C(L) = C(L) + A(I) * B(J) continue do L=1,K Write (*,*) C(L) stop end SIGMA + SISIR DIRAC
b1=5; b2=1.5; f1=5; f2=20; dT=0.002; n=500; for i=1:n; a(i)=(b1*sin(2*pi*f1*dT*(i-1)))+(b2*sin(2*pi*f2*dT*(i-1))); end; fr=30; idT=4; n=500; for i=1:n;x(i)=0; end; j=1; for i=1:n; x(j)=1;j=j+idT; end; for i=1:n; y(i)=a(i)*x(i); end; subplot(3,1,1);plot(a(1:100)); subplot(3,1,2);plot(x(1:100)); subplot(3,1,3);plot(y(1:100));
PROGRAM SUM FORTRAN DIMENSION A(300) WRITE(*,'(20x,A)')'PROGRAM SUM' write(*,50) read(*,100)N
50 format(1x, 'jumlah data:',I4,/) 100 format (I3) DO 150 I=1,N write(*,60)I read(*,110)A(I) 60 format (1x, 'data ke- ',I4,':') 110 format(F7.2,/) 150 continue s=0.0 do 200 I=1,N s=s+A(I) 200 continue do 225 i=100,100 s=s*i 225 continue write (*,250)s 250 format (1x,'jumlah nilainya : ',F7.2,/) stop end
PROSES DIGITALISASI b1=5; b2=1.5; f1=5; f2=20; dT=0.004; n=500; for i=1:n;
a(i)=(b1*sin(2*pi*f1*dT*(i-1)))+(b2*sin(2*pi*f2*dT*(i-1))); end for i=1:n; x(i)=0.0; end j=1; dd=4; for i=1:n; x(j)=1.0; j=j+dd; end for i=1:n; y(i)=x(i)*a(i); end subplot(3,1,1);plot(a); title('Proses Digitalisasi'); subplot(3,1,2);plot(x(1:500)); subplot(3,1,3);plot(y);