Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fs = 10000;
- f= 60;
- t = 0:1/fs:4;
- x =4*sin(2*pi*f*t);
- y =4*square(2*pi*f*t);
- z =4*sawtooth(2*pi*f*t);
- plot (t,x);
- axis ([0 0.1 -5 5])
- _______________________________________
- %Frekuensi Sampling
- f=35+10;
- fsa=1000;
- fsb=10000;
- fsc=50;
- fsd=2.01*f;
- fse=2.1*f;
- fsf=1.9*f;
- %Periode
- ta= 0:1/fsa:1;
- tb= 0:1/fsb:1;
- tc= 0:1/fsc:1;
- td= 0:1/fsd:1;
- te= 0:1/fse:1;
- tf= 0:1/fsf:1;
- %Signal Equetion
- Sinyal_a= sin(2*pi*f*ta);
- Sinyal_b= sin(2*pi*f*tb);
- Sinyal_c= sin(2*pi*f*tc);
- Sinyal_d= sin(2*pi*f*td);
- Sinyal_e= sin(2*pi*f*te);
- Sinyal_f= sin(2*pi*f*tf);
- fsg= [10:0.1:200];
- for i = 1:length (fsg)
- tg= 0:1/fsg(i):1;
- Sinyal_g = sin(2*pi*f*tg);
- pks_g(i) =length(findpeaks(Sinyal_g));
- end
- %Plotting Sinyal
- figure(1)
- subplot(3,2,1);
- plot(ta,Sinyal_a)
- title('Sinyal Frekuensi 1000 HZ');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(3,2,2);
- plot(tb,Sinyal_b)
- title('Sinyal Frekuensi 10000 Hz');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(3,2,3);
- plot(tc,Sinyal_c)
- title('Sinyal Frekuensi 50 Hz');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(3,2,4);
- plot(td,Sinyal_d)
- title('Sinyal Frekuensi 90.45 Hz');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(3,2,5);
- plot(te,Sinyal_e)
- title('Sinyal Frekuensi 94.5 Hz');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(3,2,6);
- plot(tf,Sinyal_f)
- title('Sinyal Frekuensi 85.5 Hz');
- xlabel('Time(s)')
- ylabel('Amplitude');
- figure (2)
- subplot(3,2,1);
- plot(ta,Sinyal_a)
- title('Sinyal Frekuensi 1000 HZ');
- xlabel('Time(s)')
- ylabel('Amplitude');
- findpeaks(Sinyal_a,ta)
- pks_a = findpeaks(Sinyal_a,ta);
- subplot(3,2,2);
- plot(tb,Sinyal_b)
- title('Sinyal Frekuensi 10000 Hz');
- xlabel('Time(s)')
- ylabel('Amplitude');
- findpeaks(Sinyal_b,tb)
- pks_b = findpeaks(Sinyal_b,tb);
- subplot(3,2,3);
- plot(tc,Sinyal_c)
- title('Sinyal Frekuensi 50 Hz');
- xlabel('Time(s)')
- ylabel('Amplitude');
- findpeaks(Sinyal_c,tc)
- pks_c = findpeaks(Sinyal_c,tc);
- subplot(3,2,4);
- plot(td,Sinyal_d)
- title('Sinyal Frekuensi 90.45 Hz');
- xlabel('Time(s)')
- ylabel('Amplitude');
- findpeaks(Sinyal_d,td)
- pks_d = findpeaks(Sinyal_d,td);
- subplot(3,2,5);
- plot(te,Sinyal_e)
- title('Sinyal Frekuensi 94.5 Hz');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(3,2,6);
- findpeaks(Sinyal_e,te)
- pks_e = findpeaks(Sinyal_e,te);
- plot(tf,Sinyal_f)
- title('Sinyal Frekuensi 85.5 Hz');
- xlabel('Time(s)')
- ylabel('Amplitude');
- findpeaks(Sinyal_f,tf)
- pks_f = findpeaks(Sinyal_f,tf);
- figure (3)
- plot(fsg,pks_g)
- findpeaks(pks_g,fsg)
- title('Sinyal Fg');
- xlabel('Time(s)')
- ylabel('Amplitude');
- __________________________
- %Frekuensi
- f = 60;
- %Deskrit
- D = [ 6, 4, 5, 6, 1, 2, 2, 5]
- %Impulse
- I = [ones(1,1), zeros(1,7)]
- %Sampling
- fs = 1000;
- %Time index
- t1 = 0:1/fs:4;
- t2 = 0:14;
- t3 = 0:4007;
- t4 = 0:8000;
- %Fungsi sinyal
- MySignal1 = 3*sawtooth(2*pi*f*t1)
- MySignal2 = 5*square(2*pi*f*t1);
- MySignal3 = 8*square(2*pi*f*t1);
- %Convolution
- CSignal1 = conv(D,I)
- CSignal2 = conv(D,MySignal1)
- CSignal3 = conv(D,MySignal2)
- CSignal4 = conv(D,MySignal3)
- CSignal5 = conv(I,MySignal2)
- CSignal6 = conv(I,MySignal1)
- CSignal7 = conv(I,MySignal3)
- CSignal8 = conv(MySignal1,MySignal2)
- CSignal9 = conv(MySignal2,MySignal3)
- %Plotting Sinyal
- figure(1)
- subplot(2,2,1);
- %plot(t2,CSignal1)
- stem(t2,CSignal1);
- xlim([0 16])
- title('Discrete + Impulse Signal');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(2,2,2);
- %plot(t3,CSignal2)
- stem(t3,CSignal2);
- xlim([0 16])
- title('Discrete + Sawtooth Signal');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(2,2,3);
- %plot(t3,CSignal3)
- stem(t3,CSignal3);
- xlim([0 16])
- title('Discrete + Square Signal');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(2,2,4);
- %plot(t3,CSignal4)
- stem(t3,CSignal4);
- xlim([0 16])
- title('Discrete + My Signal');
- xlabel('Time(s)')
- ylabel('Amplitude');
- figure(2)
- subplot(3,2,1);
- %plot(t3,CSignal5)
- stem(t3,CSignal5);
- xlim([0 16])
- title('Impulse + Square Signal');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(3,2,2);
- %plot(t3,CSignal6)
- stem(t3,CSignal6);
- xlim([0 16])
- title('Impulse + Sawtooth Signal');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(3,2,3);
- %plot(t3,CSignal7)
- stem(t3,CSignal7);
- xlim([0 16])
- title('Impulse + My Signal');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(3,2,4);
- %plot(t4,CSignal8)
- stem(t4,CSignal8);
- xlim([0 16])
- title('Square + Sawtooth Signal');
- xlabel('Time(s)')
- ylabel('Amplitude');
- subplot(3,2,5);
- %plot(t4,CSignal9)
- stem(t4,CSignal9);
- xlim([0 16])
- title('Square + My Signal');
- xlabel('Time(s)')
- ylabel('Amplitude');
- _________________________________
- %0
- Fs= 1000;
- T= 1/Fs;
- L= 1000;
- t= (0:L-1)*T;
- An0= 0;
- x= 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
- y0= x + An0*randn(size(t));
- NFFT= 2^nextpow2(L);
- Y0= fft(y0,NFFT)/L;
- f= Fs/2*linspace(0,1,NFFT/2+1);
- %1
- An1= 1;
- y1= x + An1*randn(size(t));
- Y1= fft(y1,NFFT)/L;
- %2
- An2= 2;
- y2= x + An2*randn(size(t));
- Y2= fft(y2,NFFT)/L;
- %3
- An3= 3;
- y3= x + An3*randn(size(t));
- Y3= fft(y3,NFFT)/L;
- %4
- An4= 4;
- y4= x + An4*randn(size(t));
- Y4= fft(y4,NFFT)/L;
- %5
- An5= 5;
- y5= x + An5*randn(size(t));
- Y5= fft(y5,NFFT)/L;
- figure(1)
- %0
- subplot(3,2,1);
- plot(Fs*t(1:50), y0(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,2);
- plot(f,2*abs(Y0(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- %1
- subplot(3,2,3);
- plot(Fs*t(1:50), y1(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,4);
- plot(f,2*abs(Y1(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- %2
- subplot(3,2,5);
- plot(Fs*t(1:50), y2(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,6);
- plot(f,2*abs(Y2(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- figure(2)
- %3
- subplot(3,2,1);
- plot(Fs*t(1:50), y3(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,2);
- plot(f,2*abs(Y3(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- %4
- subplot(3,2,3);
- plot(Fs*t(1:50), y4(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,4);
- plot(f,2*abs(Y4(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- %5
- subplot(3,2,5);
- plot(Fs*t(1:50), y5(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,6);
- plot(f,2*abs(Y5(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- -------------------------------------------------------------
- %0
- Fs= 1000;
- T= 1/Fs;
- L= 1000;
- t= (0:L-1)*T;
- An0= 0;
- x= 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
- y0= x + An0*randn(size(t));
- NFFT= 2^nextpow2(L);
- Y0= fft(y0,NFFT)/L;
- f= Fs/2*linspace(0,1,NFFT/2+1);
- %1
- An1= 1;
- y1= x + An1*randn(size(t));
- Y1= fft(y1,NFFT)/L;
- %2
- An2= 2;
- y2= x + An2*randn(size(t));
- Y2= fft(y2,NFFT)/L;
- %3
- An3= 3;
- y3= x + An3*randn(size(t));
- Y3= fft(y3,NFFT)/L;
- %4
- An4= 4;
- y4= x + An4*randn(size(t));
- Y4= fft(y4,NFFT)/L;
- %5
- An5= 5;
- y5= x + An5*randn(size(t));
- Y5= fft(y5,NFFT)/L;
- figure(1)
- %0
- subplot(3,2,1);
- plot(Fs*t(1:50), y0(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,2);
- plot(f,2*abs(Y0(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- %1
- subplot(3,2,3);
- plot(Fs*t(1:50), y1(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,4);
- plot(f,2*abs(Y1(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- %2
- subplot(3,2,5);
- plot(Fs*t(1:50), y2(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,6);
- plot(f,2*abs(Y2(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- figure(2)
- %3
- subplot(3,2,1);
- plot(Fs*t(1:50), y3(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,2);
- plot(f,2*abs(Y3(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- %4
- subplot(3,2,3);
- plot(Fs*t(1:50), y4(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,4);
- plot(f,2*abs(Y4(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- %5
- subplot(3,2,5);
- plot(Fs*t(1:50), y5(1:50))
- title('Signal Corruped with Zero-Mean Random Noise')
- xlabel('time (Miliseconds)')
- subplot(3,2,6);
- plot(f,2*abs(Y5(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- ______________________________________________
- fs = 10000;
- f= 60;
- t = 0:1/fs:4;
- y =4*square(2*pi*f*t);
- NFFT= 2^nextpow2(L);
- Y= fft(y,NFFT)/L;
- ff= Fs/2*linspace(0,1,NFFT/2+1);
- plot(ff,2*abs(Y(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (ff)|')
- ___________________________________________
- A= audioread('17,5K_Hz.wav');
- B= A(:,1);
- NFFT= 2^nextpow2(L);
- Y= fft(B,NFFT)/L;
- ff= Fs/2*linspace(0,1,NFFT/2+1);
- plot(ff,2*abs(Y(1:NFFT/2+1)))
- title('Single-side Amplitude Spectrum of y(t)')
- ylabel('|Y (f)|')
- _______________________________________
- Laplace Transform and Bode Plot
- %Untuk men set sumbu X dalam Hz
- opts = bodeoptions;
- opts.FreqUnits = 'Hz';
- % untuk menset fungsi transfer
- % untuk tf([polynomial penyebut],[polynomial pembagi])
- G1 = tf([1],[0.001 1]) %Vc(s)/Vs(s)
- G2 = tf([-10^9-10^6 10^9],[10^3 10^6 0]) %Vr(s)/Vs(s)
- % untuk memplot bode plot
- figure(1)
- bode(G1,opts)
- grid on
- figure(2)
- bode(G2,opts)
- grid on
- ____________________________________________
- Transformasi Z
- %18035(NIM 5 Digit Terakhir) x 3 = 54105
- %Ganti Semua 0 mejadi 1, 0=>1, =54115
- NIM_5_Digit= [5 4 1 1 5];
- NIM = NIM_5_Digit *0.2;
- A=NIM(1,1);
- B=NIM(1,2);
- C=NIM(1,3);
- D=NIM(1,4);
- E=NIM(1,5);
- %Tugas
- %1.
- x1 = [1 zeros(1,100)];
- y1 = [0 0];
- for i = 1:length(x1)
- n1 = i+2;
- y1(n1) = C*x1(i) + (-1*D*y1(n1-1)) + E*y1(n1-2);
- end
- y1 = y1(3:n1);
- figure(1)
- subplot(3,1,1)
- stem(y1)
- title('Respon Impulse sistem')
- subplot(3,1,2)
- m1 = 100; %jumlah sample
- BB1 = [1 0 0]; %numerator
- AA1 = [C -D E]; %denominator
- impz(BB1,AA1,m1)
- [Z1,P1,K1] = tf2zp(BB1,AA1)
- subplot(3,1,3)
- zplane(BB1,AA1)
- %2.
- x2 = [1 zeros(1,100)];
- y2 = [0 0];
- for i = 1:length(x2)
- n2 = i+2;
- y2(n2) = x2(i)+((C+(-E))*y2(n2-1));
- end
- y2 = y2(3:n2);
- figure(2)
- subplot(3,1,1)
- stem(y2)
- title('Respon Impulse sistem')
- subplot(3,1,2)
- m2 = 100; %jumlah sample
- BB2 = [1 0 0]; %numerator
- AA2 = [1 C-E 0]; %denominator
- impz(BB2,AA2,m2)
- [Z2,P2,K2] = tf2zp(BB2,AA2)
- subplot(3,1,3)
- zplane(BB2,AA2)
- %3
- x3 = [1 zeros(1,100)];
- y3 = [0 0];
- for i = 1:length(x3)
- n3 = i+2;
- y3(n3) = (A*x3(i) + (-1*C*y3(n3-1))) +(B*x3(i) + D*y3(n3-1));
- end
- y3 = y3(3:n3);
- figure(3)
- subplot(3,1,1)
- stem(y3)
- title('Respon Impulse sistem')
- subplot(3,1,2)
- m3 = 100; %jumlah sample
- BB3 = [1 0 0]; %numerator
- AA3 = [A-B -C-D 0]; %denominator
- impz(BB3,AA3,m3)
- [Z3,P3,K3] = tf2zp(BB3,AA3)
- subplot(3,1,3)
- zplane(BB3,AA3)
- %4.
- x4 = [1 zeros(1,100)];
- y4 = [0 0];
- for i = 1:length(x4)
- n4 = i+2;
- y4(n4) = exp(x4(i)) + (-1*A*y4(n4-1)) + (-1*B*y4(n4-2)) + (C*y4(n4-1)) + (D*y4(n4-2));
- end
- y4 = y4(3:n4);
- figure(4)
- subplot(3,1,1)
- stem(y4)
- title('Respon Impulse sistem')
- subplot(3,1,2)
- m4 = 100; %jumlah sample
- BB4 = [1 0 0]; %numerator
- AA4 = [exp(1) -A+C -B+D]; %denominator
- impz(BB4,AA4,m4)
- [Z4,P4,K4] = tf2zp(BB4,AA4)
- subplot(3,1,3)
- zplane(BB4,AA4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement