Program MATLAB untuk Sistem Linier dan Prosesing SInyal Sigit Kusmaryanto http:/sigitkus.lecture.ub.ac.id Pembangkitan sinyal dasar pada system linier dan pengolahan/prosessing sinyal dapat dilakukan dengan mudah dengan program simulasi MATLAB. Contoh contoh program pembangkitan sinyal dan prosesing sinyal dengan MATLAB akan disajikan dalam bahasan berikut. Mahasiswa dapat mengeksplorasi contoh program yang disajikan untuk kasus lain. Semua contoh program telah berhasil dijalankan dengan Program MATLAB 2009 % Program pembangkitan sebuah sinyal ramp n=input('masukkan panjang sinyal ramp N = '); s=input(' Masukkan kemiringan sinyal ramp S = '); t=0:n-1; plot(t,s*t); TITLE ('Ramp signal'); % Program pembangkitan Sinyal Unit Step Sekuen n=input (Masukkan panjang sinyal step Sekuen N='); t=0:n-1; y=ones(1,n); stem(t,y); TITLE ('Unit Step Signal'); % Program pembangkitan Sinyal Unit Step n=input ('Masukkan panjang sinyal step N='); t=0:n-1; y=ones(1,n); TITLE ('Unit Step Signal');
%Pembangkitan Sinyal Impuls t=-2:2; y=zeros(1,5); y(1,3)=1; stem(t,y); TITLE ('Impulse Signal'); %Program Pembangkitan sinyal eksponensial n=input('enter the duration of the signal N = '); a=input ('Enter the scaling factor a = '); t=0:.1:n-1; y=exp(a*t); TITLE ('Exponential Signal'); %Program Pembangkitan sinyal gergaji n=input ('Enter the length of the sequence N= '); t=0:.0001:n; y=sawtooth(t); TITLE ('Sawtooth waveform'); %Program Pembangkitan sinyal segitiga n=input ('Enter the length of the sequence N= '); t=0:.0001:n; y=sawtooth(t,.5);) TITLE ('Triangular waveform');
%Pembangkitan sinyal sinusoida Fs=1000; t=(1:1000)/fs; %s1=sin(2*pi*t*5); %s1=sin(2*pi*t*10); %s1=2*sin(2*pi*t*5); f=5;% f= frekuensi fasa=0; s1=2*sin(2*pi*t*f+fasa); plot(t,s1) %Pembangkitan sinyal sinusoida variasi parameter Fs=1000; t=(1:1000)/fs; s1=sin(2*pi*t*5); s2=2*sin(2*pi*t*10+pi/2); s3=4*sin(2*pi*t*20+pi/2); plot(t,s1,'k') plot(t,s2,'r') plot(t,s3,'b') %Pembangkitan sinusoida dikrit Fs=20;%frekuensi sampling t=(0:fs-1)/fs;%proses normalisasi s1=sin(2*pi*t*2); stem(t,s1) axis([0 1-1.2 1.2]) %Penambahan noise Gausian pada sinyal sinusoida t=0.1:.1:8; x=sin(2*pi*t/4); plot(x,'linewidth',2) t=0.1:.1:8; x_n=sin(2*pi*t/4)+0.5*randn*sin(2*pi*10*t/4) + 0.2*randn*sin(2*pi*12*t/4); plot(x_n,'linewidth',2)
%konvolusi dua sinyal step L=input('Panjang gelombang(>=10) : '); P=input('Lebar pulsa (lebih kecil dari L): '); for n=1:l if n<=p x(n)=1; else x(n)=0; t=1:l; subplot(3,1,1) stem(t,x) for n=1:l if n<=p v(n)=1; else v(n)=0; t=1:l; subplot(3,1,2) stem(t,v) subplot(3,1,3) stem(conv(x,v)) %ANALISA SINYAL DALAM DOMAIN FREKUENSI %fenomena Gibb t=-3:6/1000:3; N=input('Jumlah sinyal '); c0=0.5; w0=pi; xn=c0*ones(1,length(t)); for n=1:2:n theta=((-1)^((n-1)/2)-1)*pi/2; xn = xn + 2/n/pi*cos(n*w0*t +theta); plot(t,xn) xlabel('waktu') ylabel('x(t)') %ubah input=2,3,5,7,9,... %ANALISA SINYAL DALAM DOMAIN FREKUENSI %Pengamatan Frekuensi Pada kombinasi dua Sinyal Fs=100; t=(1:400)/fs; f1=1; s1=(2/pi)*sin(2*pi*f1*t);%sinyal pertama
f2=3; s2=(2/3/pi)*sin(2*pi*f2*t);%sinyal kedua s=s1+s2;%kombinasi sinyal 1 dan 2 subplot(2,1,1) plot(t,s) xlabel('time') S=fft(s,512); w=(0:255)/256*(fs/2); subplot(2,1,2) plot(w,abs(s(1:256))) xlabel('frequency') %Program Menentukan Diskrit Fourier Transform dan Invers Diskrit Fourier Transform close all; xn=input('enter the sequence x(n)'); %Get the sequence from user ln=length(xn); %find the length of the sequence xk=zeros(1,ln); %initilise an array of same size as that of input sequence ixk=zeros(1,ln); %initilise an array of same size as that of input sequence %code block to find the DFT of the sequence %----------------------------------------------------------- for k=0:ln-1 for n=0:ln-1 xk(k+1)=xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/ln)); %code block to plot the input sequence subplot(221); stem(t,xn); TITLE ('Input Sequence'); --- magnitude=abs(xk); % Find the magnitudes of individual DFT points %code block to plot the magnitude response subplot(222);
stem(t,magnitude); xlabel ('K'); TITLE ('Magnitude Response'); phase=angle(xk); % Find the phases of individual DFT points %code block to plot the magnitude sequence subplot(223); stem(t,phase); ylabel ('Phase'); xlabel ('K'); TITLE ('Phase Response'); % Code block to find the IDFT of the sequence for n=0:ln-1 for k=0:ln-1 ixk(n+1)=ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/ln)); ixk=ixk./ln; %code block to plot the input sequence subplot(224); stem(t,xn); TITLE ('IDFT sequence'); %-----------------------------------------------------------
Referensi [1] Edward Kamen & Bonnie Heck, Fundamentals of Signals and Systems, Prentice Hall, 2000. [2] Naresh K Sinha, Linear Systems, John Wiley & Sons., 1991 [3] Alan V Oppenheim, Signals and Systems, dkk., 1997