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); ylabel ('Amplitude'); xlabel ('Time Index'); 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); ylabel ('Amplitude'); xlabel ('Time Index'); TITLE ('Unit Step Signal');
Program pembangkitan Sinyal Unit Step n=input ('Masukkan panjang sinyal step N='); t=0:n-1; y=ones(1,n); plot(t,y); ylabel ('Amplitude'); xlabel ('Time Index'); TITLE ('Unit Step Signal'); %
%Pembangkitan Sinyal Impuls t=-2:2; y=zeros(1,5); y(1,3)=1; stem(t,y); ylabel ('Amplitude'); xlabel ('Time Index'); 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); plot(t,y); ylabel ('Amplitude'); xlabel ('Time Index'); TITLE ('Exponential Signal');
%Program Pembangkitan sinyal gergaji n=input ('Enter the length of the sequence N= '); t=0:.0001:n; y=sawtooth(t); plot(t,y); ylabel ('Amplitude'); xlabel ('Time Index'); TITLE ('Sawtooth waveform');
%Program Pembangkitan sinyal segitiga n=input ('Enter the length of the sequence N= '); t=0:.0001:n; y=sawtooth(t,.5);) plot(t,y); ylabel ('Amplitude'); xlabel ('Time Index'); 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') hold on plot(t,s2,'r') hold on 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 clc; clear all; t=0.1:.1:8; x=sin(2*pi*t/4); plot(x,'linewidth',2) hold on 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) hold on
%konvolusi dua sinyal step clc; clear all; 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; end end t=1:L; subplot(3,1,1) stem(t,x) for n=1:L if n<=P v(n)=1; else v(n)=0; end end 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 clear all; clc; 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); end 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 clear all; clc; 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; clear 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)); end end %-----------------------------------------------------------%code block to plot the input sequence %-----------------------------------------------------------t=0:ln-1; subplot(221); stem(t,xn); ylabel ('Amplitude'); xlabel ('Time Index'); TITLE ('Input Sequence'); %--------------------------------------------------------------magnitude=abs(xk); % Find the magnitudes of individual DFT points %code block to plot the magnitude response %-----------------------------------------------------------t=0:ln-1; subplot(222);
stem(t,magnitude); ylabel ('Amplitude'); xlabel ('K'); TITLE ('Magnitude Response'); %-----------------------------------------------------------phase=angle(xk); % Find the phases of individual DFT points %code block to plot the magnitude sequence %-----------------------------------------------------------t=0:ln-1; 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)); end end ixk=ixk./ln; %-----------------------------------------------------------%code block to plot the input sequence %-----------------------------------------------------------t=0:ln-1; subplot(224); stem(t,xn); ylabel ('Amplitude'); xlabel ('Time Index'); 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