0% found this document useful (0 votes)
166 views31 pages

Tugas

The document is a report in Indonesian that contains 16 MATLAB programs for signal processing. The programs generate and analyze various periodic signals including square waves, sine waves, sawtooth waves, and pulse trains. Fourier transforms are performed on some of the signals to analyze their harmonic content. Plots and audio outputs are generated from the signals. The programs are examples used to teach topics in signal processing.

Uploaded by

Ariel Sayudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views31 pages

Tugas

The document is a report in Indonesian that contains 16 MATLAB programs for signal processing. The programs generate and analyze various periodic signals including square waves, sine waves, sawtooth waves, and pulse trains. Fourier transforms are performed on some of the signals to analyze their harmonic content. Plots and audio outputs are generated from the signals. The programs are examples used to teach topics in signal processing.

Uploaded by

Ariel Sayudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

TUGAS

PEMROSESAN SINYAL

Dosen Pengampu : Dwi Kuswanto, S.Pd.,M.T

Oleh :

Elfira Putri Sudrajat

150411100005

PRODI TEKNIK INFORMATIKA

FAKULTAS TEKNIK

UNIVERSITAS TRUNOJOYO MADURA

2018
LAPORAN

BAB 1

Program 1.1 Square signal

% Square signal

A=[1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0];

fs=10; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(3-tiv); %time intervals set (30 values)

plot(t,A,'*k'); %plots figure

axis([0 3 -0.5 1.5]);

xlabel('seconds'); title('square wave samples');

Hasil Running :
Program 1.2 Sine signal

Sinyal sinusoidal dengan periode 1 detik menggunakan fungsi sinus.

% Sine signal

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

fs=60; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(3-tiv); %time intervals set

y=sin(wy*t); %signal data set

plot(t,y,'k'); %plots figure

Hasil Running :
Program 1.3 Sine and cosine signals

Sinyal sinus dan cosinus dengan frekuensi yang sama 1 Hz.

% Sine & cosine signals

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

fs=60; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(3-tiv); %time intervals set

ys=sin(wy*t); %signal data set

plot(t,ys,'k'); hold on; %plots figure

axis([0 3 -1.5 1.5]);

xlabel('seconds');

yc=cos(wy*t); %signal data set

plot(t,yc,'--k'); %plots figure

axis([0 3 -1.5 1.5]);

xlabel('seconds'); title('sine (solid) & cosine (dashed)');


Hasil Running :

Program 1.4 Square signal

Square signal dengan periode 0.01 detik (frekuensi 100Hz). Dengan menggunakan
fungsi Square().

% Square signal

fy=100; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

duy=0.03; %signal duration in seconds

fs=20000; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(duy-tiv); %time intervals set

y=square(wy*t); %signal data set

plot(t,y,'k'); %plots figure

axis([0 duy -1.5 1.5]);

xlabel('seconds'); title('square signal');


Hasil Running :

Program 1.5 Sawtooth signal

Generate 0.03 detik Sinyal sawtooth dengan periode 0.01 (frekuensi 100Hz).

% Sawtooth signal

fy=100; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

duy=0.03; %signal duration in seconds

fs=20000; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(duy-tiv); %time intervals set

y=sawtooth(wy*t); %signal data set

plot(t,y,'k'); %plots figure

axis([0 duy -1.5 1.5]);

xlabel('seconds'); title('sawtooth signal');


Hasil Running :

Program 1.6 Sawtooth signals

% Sawtooth signals

fy=100; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

duy=0.03; %signal duration in seconds

fs=20000; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(duy-tiv); %time intervals set

y=sawtooth(wy*t,0.1); %signal data set (width 0.1)

subplot(2,2,1); plot(t,y,'k'); %plots figure

axis([0 duy -1.5 1.5]);

xlabel('seconds'); title('sawtooth signal');

y=sawtooth(wy*t,0.3); %signal data set (width 0.3)


subplot(2,2,2); plot(t,y,'k'); %plots figure

axis([0 duy -1.5 1.5]);

xlabel('seconds'); title('sawtooth signal');

y=sawtooth(wy*t,0.5); %signal data set (width 0.5)

subplot(2,2,3); plot(t,y,'k'); %plots figure

axis([0 duy -1.5 1.5]);

xlabel('seconds'); title('sawtooth signal');

y=sawtooth(wy*t,0.9); %signal data set (width 0.9)

subplot(2,2,4); plot(t,y,'k'); %plots figure

axis([0 duy -1.5 1.5]);

xlabel('seconds'); title('sawtooth signal');

Hasil Running :
Program 1.7 Sine audio signal

Sinyal sinusoidal dengan frekuensi 300Hz selama 5 detik.

Dengan menggunakan fungsi sound() dapat mengirim sinyal dengan daya yang
cukup untuk pengeras suara.

% Sine signal sound

fy=900; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

fs=6000; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(5-tiv); %time intervals set (5 seconds)

y=sin(wy*t); %signal data set

sound(y,fs); %sound

t=0:tiv:(0.01-tiv); %time intervals set (0.01 second)

y=sin(wy*t); %signal data set

plot(t,y,'k'); %plots figure

axis([0 0.01 -1.5 1.5]);

xlabel('seconds'); title('sine signal');


Hasil Running :

Program 1.8 Sum of sines signal

% Sum of sines signal

fy=300; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

fs=6000; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(5-tiv); %time intervals set (5 seconds)

y=0.6*sin(wy*t)+0.3*sin(3*wy*t)+0.2*sin(5*wy*t); %signal data set

sound(y,fs); %sound

t=0:tiv:(0.01-tiv); %time intervals set (0.01 second)

nn=length(t);

plot(t,y(1:nn),'k'); %plots figure


axis([0 0.01 -1.5 1.5]);

xlabel('seconds'); title('sum of sines signal');

Hasil Running :

Program 1.9 Multiplication of sines

Perkalian sinyal

Pada satu sinyal memiliki frekuensi 70Hz dan pada sinyal lain memiliki frekuensi
2Hz

% Multiplication of sines signal

fx=70; %signal frequency in Hz

wx=2*pi*fx; %signal frequency in rad/s

fz=2; %signal frequency in Hz

wz=2*pi*fz; %signal frequency in rad/s

fs=6000; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(8-tiv); %time intervals set (8 seconds)


y=sin(wx*t).*sin(wz*t); %signal data set

sound(y,fs); %sound

t=0:tiv:(1-tiv); %time intervals set (1 second)

y=sin(wx*t).*sin(wz*t); %signal data set

plot(t,y,'k'); %plots figure

axis([0 1 -1.5 1.5]);

xlabel('seconds'); title('multiplication of sines signal');

Hasil Running :

Program 1.10 Sawtooth signal to be analyzed

%sawtooth signal to be analyzed

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

Ty=1/fy; %signal period in seconds

Ns=256; %number of samples per signal period

fs=Ns*fy; %sampling frequency in Hz


tiv=1/fs; %time interval between samples;

t=0:tiv:((3*Ty)-tiv); %time intervals set (3 periods)

y3=sawtooth(wy*t); %signal data set

plot(t,y3,'k');

xlabel('seconds'); title('sawtooth signal (3 periods)');

Hasil Running :

Program 1.11 Fourier transform of sawtooth signal

%Fourier Transform of sawtooth signal

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

Ty=1/fy; %signal period in seconds

N=256;

fs=N*fy; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(Ty-tiv); %time intervals set

y=sawtooth(wy*t); %signal data set


fou=fft(y,fs); %Fourier Transform (set of complex numbers)

hmag=imag(fou); bh=hmag/N; %get set of harmonic amplitudes

stem(0:9,bh(1:10)); %plot of first 10 harmonics

axis([0 10 0 1]);

xlabel('Hz'); title('sawtooth signal harmonics');

Hasil Running :

Program 1.12 Rectified signal to be analyzed

%rectified sine signal to be analyzed

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

Ty=1/fy; %signal period in seconds

Ns=256; %number of samples per signal period

fs=Ns*fy; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:((3*Ty)-tiv); %time intervals set (3 periods)

y3=abs(sin(wy*t)); %signal data set


plot(t,y3);

xlabel('seconds'); title('rectified sine signal (3 periods)');

Hasil Running :

Program 1.13 Fourier transform of rectified signal

%Fourier Transfom of rectified sine signal

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

Ty=1/fy; %signal period in seconds

Ns=256; %%number of samples per signal period

fs=Ns*fy; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(Ty-tiv); %time intervals set (1 period)

y=abs(sin(wy*t)); %signal data set

fou=fft(y); %Fourier Transform (set of complex numbers)

%get set of harmonic amplitudes:


ah(1)=fou(1)/Ns;

hmag=real(fou);

ah(2:Ns)=(hmag(2:Ns)*2)/Ns;

stem(0:9,ah(1:10)); hold on; %plot of first 10 harmonics

plot([0 10],[0 0],'k');

xlabel('Hz'); title('rectified sine signal harmonics');

Hasil Running :

Program 1.14 Triangular signal to be analyzed

%triangular signal to be analyzed

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

Ty=1/fy; %signal period in seconds

Ns=256; %number of samples per signal period

fs=Ns*fy; %sampling frequency in Hz


tiv=1/fs; %time interval between samples;

t=0:tiv:((3*Ty)-tiv); %time intervals set (3 periods)

y3=-sawtooth(wy*t,0.5); %signal data set

plot(t,y3);

xlabel('seconds'); title('triangular signal (3 periods)');

Hasil Running :

Program 1.15 Fourier transform of triangular signal

%Fourier Transfom of triangular signal

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

Ty=1/fy; %signal period in seconds

Ns=256; %%number of samples per signal period

fs=Ns*fy; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(Ty-tiv); %time intervals set (1 period)

y=-sawtooth(wy*t,0.5); %signal data set


fou=fft(y); %Fourier Transform (set of complex numbers)

%get set of harmonic amplitudes:

ah(1)=fou(1)/Ns;

hmag=real(fou);

ah(2:Ns)=(hmag(2:Ns)*2)/Ns;

stem(0:9,ah(1:10)); hold on; %plot of first 10 harmonics

plot([0 10],[0 0],'k');

xlabel('Hz'); title('triangular signal harmonics');

Hasil Running :

Program 1.16 Pulse train signal

pulse train signal to be analyzed

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

Ty=1/fy; %signal period in seconds


Ns=256; %number of samples per signal period

fs=Ns*fy; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:((3*Ty)-tiv); %time intervals set (3 periods)

W=20;

y1=zeros(256,1); y1(1:W)=1; y1((256-W):256)=1; %signal first part

yt=cat(1,y1,y1,y1); %signal to be plotted

plot(t,yt);

axis([0 3 -0.1 1.1]);

xlabel('seconds'); title('pulse train signal (3 periods)');

Hasil Running :

Program 1.17 Fourier transform of pulse train signal

%Fourier Transform of pulse train signal

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s


Ty=1/fy; %signal period in seconds

Ns=256; W=20;

fs=Ns*fy; %sampling frequency in Hz

y1=zeros(256,1); y1(1:W)=1; y1((256-W):256)=1; %signal period

fou=fft(y1); %Fourier Transform (set of complex numbers)

%get set of harmonic amplitudes:

ah(1)=fou(1)/Ns;

hmag=real(fou);

ah(2:Ns)=(hmag(2:Ns)*2)/Ns;

stem(0:49,ah(1:50)); hold on; %plot of first 50 harmonics

plot([0 50],[0 0],'k');

xlabel('Hz'); title('pulse train signal harmonics');

Hasil Running :
Program 1.18 Sinc function

%sinc function

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

Ty=1/fy; %signal period in seconds

Ns=256; %number of samples per signal period

fs=Ns*fy; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=-((6*Ty)-tiv):tiv:((6*Ty)-tiv); %time intervals set (12 periods)

y=sinc(t); %signal data set

plot(t,y); hold on;

plot([0 0],[-0.4 1.2],'k');

xlabel('seconds'); title('sinc function');

Hasil Running :
Program 1.19 Sine signal and low sampling frequency

% Sine signal & slow sampling frequency

fy=1; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

fs=7; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(3-tiv); %time intervals set

y=sin(wy*t); %signal data set

plot(t,y,'-kd'); %plots figure

axis([0 3 -1.5 1.5]);

xlabel('seconds'); title('sine signal');

Hasil Running :
Program 1.20 Sine signal and aliasing

% Sine signal & aliasing

fy=3; %signal frequency in Hz

wy=2*pi*fy; %signal frequency in rad/s

% good sampling fequency

fs=100; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(3-tiv); %time intervals set

y=sin(wy*t); %signal data set

subplot(2,1,1); plot(t,y,'k'); %plots figure

axis([0 3 -1.5 1.5]);

title('3Hz sine signal');

ylabel('fs=100');

% too slow sampling fequency

fs=4; %sampling frequency in Hz

tiv=1/fs; %time interval between samples;

t=0:tiv:(3-tiv); %time intervals set

y=sin(wy*t); %signal data set

subplot(2,1,2); plot(t,y,'-kd'); %plots figure

axis([0 3 -1.5 1.5]);


xlabel('seconds');

ylabel('fs=4');

Hasil Running :
LAPORAN

BAB II

Program 2.1 Random signal with uniform PDF

% Normal PDF with shaded zone


v=-1.3:0.01:1.3;
mu=0; sigma=0.4;
ypdf=normpdf(v,mu,sigma);
plot(v,ypdf); hold on;
axis([-1.5 1.5 0 1.1]);
xlabel('values'); title('normal PDF');
for n=1:2:50,
plot([v(150+n) v(150+n)],[0 ypdf(150+n)],'g','linewidth',2);
end;

Hasil Running :

Program 2.2 Uniform PDF

% Random signal with uniform PDF


fs=100; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(2-tiv); %time intervals set (200 values)
N=length(t); %number of data points
y=rand(N,1); %random signal data set
plot(t,y,'-k'); %plots figure
axis([0 2 0 1.2]);
xlabel('seconds'); title('random signal with uniform PDF');

Hasil Running :

Program 2.3 Histogram of a random signal with uniform PDF

% Uniform PDF
v=0:0.01:1; %values set
ypdf=unifpdf(v,0,1); %uniform PDF
plot(v,ypdf); hold on; %plots figure
axis([-0.5 1.5 0 1.1]);
xlabel('values'); title('uniform PDF');
plot([0 0],[0 1],'--k');
plot([1 1],[0 1],'--k');
Hasil Running :
Program 2.4 Random signal with normal PDF

% Histogram of a random signal with uniform PDF


fs=100; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(100-tiv); %time intervals set (10000 values)
N=length(t); %number of data points
y=rand(N,1); %random signal data set
v=0:0.02:1; %value intervals set
hist(y,v); colormap(cool); %plots histogram
xlabel('values'); title('Histogram of random signal with uniform PDF');

Hasil Running :

Program 2.5 Normal PDF

% Random signal with normal PDF


fs=100; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(2-tiv); %time intervals set (200 values)
N=length(t); %number of data points
y=randn(N,1); %random signal data set
plot(t,y,'-k'); %plots figure
axis([0 2 -3 3]);
xlabel('seconds'); title('random signal with normal PDF');
Hasil Running :

Program 2.6 Histogram of a random signal with normal PDF

% Normal PDF
v=-3:0.01:3; %values set
mu=0; sigma=1; %random variable parameters
ypdf=normpdf(v,mu,sigma); %normal PDF
plot(v,ypdf); hold on; %plots figure
axis([-3 3 0 0.5]);
xlabel('values'); title('normal PDF');

Hasil Running :

Program 2.7 Random signal with log-normal PDF

% Histogram of a random signal with normal PDF


fs=100; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(100-tiv); %time intervals set (10000 values)
N=length(t); %number of data points
y=randn(N,1); %random signal data set
v=-4:0.1:4; %value intervals set
hist(y,v); colormap(cool); %plots histogram
xlabel('values'); title('Histogram of random signal with normal PDF');

Hasil Running :

Program 2.8 Log-normal PDF

% Random signal with log-normal PDF


fs=100; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(2-tiv); %time intervals set (200 values)
N=length(t); %number of data points
mu=0; sigma=1; %random signal parameters
y=lognrnd(mu,sigma,N,1); %random signal data set
plot(t,y,'-k'); %plots figure
axis([0 2 0 12]);
xlabel('seconds'); title('random signal with log-normal PDF');
Hasil Running :

Program 2.9 Histogram of a random signal with log-normal PDF

% Log-normal PDF
v=-3:0.01:6; %values set
mu=0; sigma=1; %random variable parameters
ypdf=lognpdf(v,mu,sigma); %log-normal PDF
plot(v,ypdf); hold on; %plots figure
axis([0 6 0 0.7]);
xlabel('values'); title('log-normal PDF');

Hasil Running :
Program 2.10 A skewed PDF with mean, median and mode

% Histogram of a random signal with log-normal PDF


fs=100; %sampling frequency in Hz
tiv=1/fs; %time interval between samples;
t=0:tiv:(100-tiv); %time intervals set (10000 values)
N=length(t); %number of data points
mu=0; sigma=1; %random signal parameters
y=lognrnd(mu,sigma,N,1); %random signal data set
v=0:0.1:12; %value intervals set
hist(y,v); colormap(cool); %plots histogram
axis([0 8 0 700]);
xlabel('values'); title('Histogram of random signal with log-normal PDF');

Hasil Running :

You might also like