Advertisement
Guest User

Responsi SinyL

a guest
Jun 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.59 KB | None | 0 0
  1. fs = 10000;
  2. f= 60;
  3. t = 0:1/fs:4;
  4. x =4*sin(2*pi*f*t);
  5. y =4*square(2*pi*f*t);
  6. z =4*sawtooth(2*pi*f*t);
  7. plot (t,x);
  8. axis ([0 0.1 -5 5])
  9.  
  10. _______________________________________
  11. %Frekuensi Sampling
  12. f=35+10;
  13. fsa=1000;
  14. fsb=10000;
  15. fsc=50;
  16. fsd=2.01*f;
  17. fse=2.1*f;
  18. fsf=1.9*f;
  19.  
  20. %Periode
  21. ta= 0:1/fsa:1;
  22. tb= 0:1/fsb:1;
  23. tc= 0:1/fsc:1;
  24. td= 0:1/fsd:1;
  25. te= 0:1/fse:1;
  26. tf= 0:1/fsf:1;
  27.  
  28. %Signal Equetion
  29. Sinyal_a= sin(2*pi*f*ta);
  30. Sinyal_b= sin(2*pi*f*tb);
  31. Sinyal_c= sin(2*pi*f*tc);
  32. Sinyal_d= sin(2*pi*f*td);
  33. Sinyal_e= sin(2*pi*f*te);
  34. Sinyal_f= sin(2*pi*f*tf);
  35.  
  36. fsg= [10:0.1:200];
  37. for i = 1:length (fsg)
  38. tg= 0:1/fsg(i):1;
  39. Sinyal_g = sin(2*pi*f*tg);
  40. pks_g(i) =length(findpeaks(Sinyal_g));
  41. end
  42.  
  43. %Plotting Sinyal
  44. figure(1)
  45. subplot(3,2,1);
  46. plot(ta,Sinyal_a)
  47. title('Sinyal Frekuensi 1000 HZ');
  48. xlabel('Time(s)')
  49. ylabel('Amplitude');
  50. subplot(3,2,2);
  51. plot(tb,Sinyal_b)
  52. title('Sinyal Frekuensi 10000 Hz');
  53. xlabel('Time(s)')
  54. ylabel('Amplitude');
  55. subplot(3,2,3);
  56. plot(tc,Sinyal_c)
  57. title('Sinyal Frekuensi 50 Hz');
  58. xlabel('Time(s)')
  59. ylabel('Amplitude');
  60. subplot(3,2,4);
  61. plot(td,Sinyal_d)
  62. title('Sinyal Frekuensi 90.45 Hz');
  63. xlabel('Time(s)')
  64. ylabel('Amplitude');
  65. subplot(3,2,5);
  66. plot(te,Sinyal_e)
  67. title('Sinyal Frekuensi 94.5 Hz');
  68. xlabel('Time(s)')
  69. ylabel('Amplitude');
  70. subplot(3,2,6);
  71. plot(tf,Sinyal_f)
  72. title('Sinyal Frekuensi 85.5 Hz');
  73. xlabel('Time(s)')
  74. ylabel('Amplitude');
  75.  
  76. figure (2)
  77.  
  78. subplot(3,2,1);
  79. plot(ta,Sinyal_a)
  80. title('Sinyal Frekuensi 1000 HZ');
  81. xlabel('Time(s)')
  82. ylabel('Amplitude');
  83. findpeaks(Sinyal_a,ta)
  84. pks_a = findpeaks(Sinyal_a,ta);
  85.  
  86. subplot(3,2,2);
  87. plot(tb,Sinyal_b)
  88. title('Sinyal Frekuensi 10000 Hz');
  89. xlabel('Time(s)')
  90. ylabel('Amplitude');
  91. findpeaks(Sinyal_b,tb)
  92. pks_b = findpeaks(Sinyal_b,tb);
  93.  
  94. subplot(3,2,3);
  95. plot(tc,Sinyal_c)
  96. title('Sinyal Frekuensi 50 Hz');
  97. xlabel('Time(s)')
  98. ylabel('Amplitude');
  99. findpeaks(Sinyal_c,tc)
  100. pks_c = findpeaks(Sinyal_c,tc);
  101.  
  102. subplot(3,2,4);
  103. plot(td,Sinyal_d)
  104. title('Sinyal Frekuensi 90.45 Hz');
  105. xlabel('Time(s)')
  106. ylabel('Amplitude');
  107. findpeaks(Sinyal_d,td)
  108. pks_d = findpeaks(Sinyal_d,td);
  109.  
  110. subplot(3,2,5);
  111. plot(te,Sinyal_e)
  112. title('Sinyal Frekuensi 94.5 Hz');
  113. xlabel('Time(s)')
  114. ylabel('Amplitude');
  115. subplot(3,2,6);
  116. findpeaks(Sinyal_e,te)
  117. pks_e = findpeaks(Sinyal_e,te);
  118.  
  119. plot(tf,Sinyal_f)
  120. title('Sinyal Frekuensi 85.5 Hz');
  121. xlabel('Time(s)')
  122. ylabel('Amplitude');
  123. findpeaks(Sinyal_f,tf)
  124. pks_f = findpeaks(Sinyal_f,tf);
  125.  
  126.  
  127. figure (3)
  128. plot(fsg,pks_g)
  129. findpeaks(pks_g,fsg)
  130. title('Sinyal Fg');
  131. xlabel('Time(s)')
  132. ylabel('Amplitude');
  133.  
  134.  
  135. __________________________
  136.  
  137.  
  138. %Frekuensi
  139. f = 60;
  140. %Deskrit
  141. D = [ 6, 4, 5, 6, 1, 2, 2, 5]
  142. %Impulse
  143. I = [ones(1,1), zeros(1,7)]
  144. %Sampling
  145. fs = 1000;
  146. %Time index
  147. t1 = 0:1/fs:4;
  148. t2 = 0:14;
  149. t3 = 0:4007;
  150. t4 = 0:8000;
  151. %Fungsi sinyal
  152. MySignal1 = 3*sawtooth(2*pi*f*t1)
  153. MySignal2 = 5*square(2*pi*f*t1);
  154. MySignal3 = 8*square(2*pi*f*t1);
  155.  
  156. %Convolution
  157. CSignal1 = conv(D,I)
  158. CSignal2 = conv(D,MySignal1)
  159. CSignal3 = conv(D,MySignal2)
  160. CSignal4 = conv(D,MySignal3)
  161. CSignal5 = conv(I,MySignal2)
  162. CSignal6 = conv(I,MySignal1)
  163. CSignal7 = conv(I,MySignal3)
  164. CSignal8 = conv(MySignal1,MySignal2)
  165. CSignal9 = conv(MySignal2,MySignal3)
  166.  
  167. %Plotting Sinyal
  168. figure(1)
  169. subplot(2,2,1);
  170. %plot(t2,CSignal1)
  171. stem(t2,CSignal1);
  172. xlim([0 16])
  173. title('Discrete + Impulse Signal');
  174. xlabel('Time(s)')
  175. ylabel('Amplitude');
  176. subplot(2,2,2);
  177. %plot(t3,CSignal2)
  178. stem(t3,CSignal2);
  179. xlim([0 16])
  180. title('Discrete + Sawtooth Signal');
  181. xlabel('Time(s)')
  182. ylabel('Amplitude');
  183. subplot(2,2,3);
  184. %plot(t3,CSignal3)
  185. stem(t3,CSignal3);
  186. xlim([0 16])
  187. title('Discrete + Square Signal');
  188. xlabel('Time(s)')
  189. ylabel('Amplitude');
  190. subplot(2,2,4);
  191. %plot(t3,CSignal4)
  192. stem(t3,CSignal4);
  193. xlim([0 16])
  194. title('Discrete + My Signal');
  195. xlabel('Time(s)')
  196. ylabel('Amplitude');
  197. figure(2)
  198. subplot(3,2,1);
  199. %plot(t3,CSignal5)
  200. stem(t3,CSignal5);
  201. xlim([0 16])
  202. title('Impulse + Square Signal');
  203. xlabel('Time(s)')
  204. ylabel('Amplitude');
  205. subplot(3,2,2);
  206. %plot(t3,CSignal6)
  207. stem(t3,CSignal6);
  208. xlim([0 16])
  209. title('Impulse + Sawtooth Signal');
  210. xlabel('Time(s)')
  211. ylabel('Amplitude');
  212. subplot(3,2,3);
  213. %plot(t3,CSignal7)
  214. stem(t3,CSignal7);
  215. xlim([0 16])
  216. title('Impulse + My Signal');
  217. xlabel('Time(s)')
  218. ylabel('Amplitude');
  219. subplot(3,2,4);
  220. %plot(t4,CSignal8)
  221. stem(t4,CSignal8);
  222. xlim([0 16])
  223. title('Square + Sawtooth Signal');
  224. xlabel('Time(s)')
  225. ylabel('Amplitude');
  226. subplot(3,2,5);
  227. %plot(t4,CSignal9)
  228. stem(t4,CSignal9);
  229. xlim([0 16])
  230. title('Square + My Signal');
  231. xlabel('Time(s)')
  232. ylabel('Amplitude');
  233.  
  234. _________________________________
  235.  
  236. %0
  237. Fs= 1000;
  238. T= 1/Fs;
  239. L= 1000;
  240. t= (0:L-1)*T;
  241. An0= 0;
  242.  
  243. x= 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
  244. y0= x + An0*randn(size(t));
  245.  
  246. NFFT= 2^nextpow2(L);
  247. Y0= fft(y0,NFFT)/L;
  248. f= Fs/2*linspace(0,1,NFFT/2+1);
  249.  
  250. %1
  251. An1= 1;
  252.  
  253. y1= x + An1*randn(size(t));
  254. Y1= fft(y1,NFFT)/L;
  255.  
  256. %2
  257. An2= 2;
  258.  
  259. y2= x + An2*randn(size(t));
  260. Y2= fft(y2,NFFT)/L;
  261.  
  262. %3
  263. An3= 3;
  264.  
  265. y3= x + An3*randn(size(t));
  266. Y3= fft(y3,NFFT)/L;
  267.  
  268. %4
  269. An4= 4;
  270.  
  271.  
  272. y4= x + An4*randn(size(t));
  273. Y4= fft(y4,NFFT)/L;
  274.  
  275. %5
  276. An5= 5;
  277.  
  278.  
  279. y5= x + An5*randn(size(t));
  280. Y5= fft(y5,NFFT)/L;
  281.  
  282. figure(1)
  283. %0
  284. subplot(3,2,1);
  285. plot(Fs*t(1:50), y0(1:50))
  286. title('Signal Corruped with Zero-Mean Random Noise')
  287. xlabel('time (Miliseconds)')
  288.  
  289. subplot(3,2,2);
  290. plot(f,2*abs(Y0(1:NFFT/2+1)))
  291. title('Single-side Amplitude Spectrum of y(t)')
  292. ylabel('|Y (f)|')
  293.  
  294. %1
  295. subplot(3,2,3);
  296. plot(Fs*t(1:50), y1(1:50))
  297. title('Signal Corruped with Zero-Mean Random Noise')
  298. xlabel('time (Miliseconds)')
  299.  
  300. subplot(3,2,4);
  301. plot(f,2*abs(Y1(1:NFFT/2+1)))
  302. title('Single-side Amplitude Spectrum of y(t)')
  303. ylabel('|Y (f)|')
  304.  
  305. %2
  306. subplot(3,2,5);
  307. plot(Fs*t(1:50), y2(1:50))
  308. title('Signal Corruped with Zero-Mean Random Noise')
  309. xlabel('time (Miliseconds)')
  310.  
  311. subplot(3,2,6);
  312. plot(f,2*abs(Y2(1:NFFT/2+1)))
  313. title('Single-side Amplitude Spectrum of y(t)')
  314. ylabel('|Y (f)|')
  315.  
  316. figure(2)
  317. %3
  318. subplot(3,2,1);
  319. plot(Fs*t(1:50), y3(1:50))
  320. title('Signal Corruped with Zero-Mean Random Noise')
  321. xlabel('time (Miliseconds)')
  322.  
  323. subplot(3,2,2);
  324. plot(f,2*abs(Y3(1:NFFT/2+1)))
  325. title('Single-side Amplitude Spectrum of y(t)')
  326. ylabel('|Y (f)|')
  327.  
  328. %4
  329. subplot(3,2,3);
  330. plot(Fs*t(1:50), y4(1:50))
  331. title('Signal Corruped with Zero-Mean Random Noise')
  332. xlabel('time (Miliseconds)')
  333.  
  334. subplot(3,2,4);
  335. plot(f,2*abs(Y4(1:NFFT/2+1)))
  336. title('Single-side Amplitude Spectrum of y(t)')
  337. ylabel('|Y (f)|')
  338.  
  339. %5
  340. subplot(3,2,5);
  341. plot(Fs*t(1:50), y5(1:50))
  342. title('Signal Corruped with Zero-Mean Random Noise')
  343. xlabel('time (Miliseconds)')
  344.  
  345. subplot(3,2,6);
  346. plot(f,2*abs(Y5(1:NFFT/2+1)))
  347. title('Single-side Amplitude Spectrum of y(t)')
  348. ylabel('|Y (f)|')
  349.  
  350.  
  351. -------------------------------------------------------------
  352.  
  353. %0
  354. Fs= 1000;
  355. T= 1/Fs;
  356. L= 1000;
  357. t= (0:L-1)*T;
  358. An0= 0;
  359.  
  360. x= 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
  361. y0= x + An0*randn(size(t));
  362.  
  363. NFFT= 2^nextpow2(L);
  364. Y0= fft(y0,NFFT)/L;
  365. f= Fs/2*linspace(0,1,NFFT/2+1);
  366.  
  367. %1
  368. An1= 1;
  369.  
  370. y1= x + An1*randn(size(t));
  371. Y1= fft(y1,NFFT)/L;
  372.  
  373. %2
  374. An2= 2;
  375.  
  376. y2= x + An2*randn(size(t));
  377. Y2= fft(y2,NFFT)/L;
  378.  
  379. %3
  380. An3= 3;
  381.  
  382. y3= x + An3*randn(size(t));
  383. Y3= fft(y3,NFFT)/L;
  384.  
  385. %4
  386. An4= 4;
  387.  
  388.  
  389. y4= x + An4*randn(size(t));
  390. Y4= fft(y4,NFFT)/L;
  391.  
  392. %5
  393. An5= 5;
  394.  
  395.  
  396. y5= x + An5*randn(size(t));
  397. Y5= fft(y5,NFFT)/L;
  398.  
  399. figure(1)
  400. %0
  401. subplot(3,2,1);
  402. plot(Fs*t(1:50), y0(1:50))
  403. title('Signal Corruped with Zero-Mean Random Noise')
  404. xlabel('time (Miliseconds)')
  405.  
  406. subplot(3,2,2);
  407. plot(f,2*abs(Y0(1:NFFT/2+1)))
  408. title('Single-side Amplitude Spectrum of y(t)')
  409. ylabel('|Y (f)|')
  410.  
  411. %1
  412. subplot(3,2,3);
  413. plot(Fs*t(1:50), y1(1:50))
  414. title('Signal Corruped with Zero-Mean Random Noise')
  415. xlabel('time (Miliseconds)')
  416.  
  417. subplot(3,2,4);
  418. plot(f,2*abs(Y1(1:NFFT/2+1)))
  419. title('Single-side Amplitude Spectrum of y(t)')
  420. ylabel('|Y (f)|')
  421.  
  422. %2
  423. subplot(3,2,5);
  424. plot(Fs*t(1:50), y2(1:50))
  425. title('Signal Corruped with Zero-Mean Random Noise')
  426. xlabel('time (Miliseconds)')
  427.  
  428. subplot(3,2,6);
  429. plot(f,2*abs(Y2(1:NFFT/2+1)))
  430. title('Single-side Amplitude Spectrum of y(t)')
  431. ylabel('|Y (f)|')
  432.  
  433. figure(2)
  434. %3
  435. subplot(3,2,1);
  436. plot(Fs*t(1:50), y3(1:50))
  437. title('Signal Corruped with Zero-Mean Random Noise')
  438. xlabel('time (Miliseconds)')
  439.  
  440. subplot(3,2,2);
  441. plot(f,2*abs(Y3(1:NFFT/2+1)))
  442. title('Single-side Amplitude Spectrum of y(t)')
  443. ylabel('|Y (f)|')
  444.  
  445. %4
  446. subplot(3,2,3);
  447. plot(Fs*t(1:50), y4(1:50))
  448. title('Signal Corruped with Zero-Mean Random Noise')
  449. xlabel('time (Miliseconds)')
  450.  
  451. subplot(3,2,4);
  452. plot(f,2*abs(Y4(1:NFFT/2+1)))
  453. title('Single-side Amplitude Spectrum of y(t)')
  454. ylabel('|Y (f)|')
  455.  
  456. %5
  457. subplot(3,2,5);
  458. plot(Fs*t(1:50), y5(1:50))
  459. title('Signal Corruped with Zero-Mean Random Noise')
  460. xlabel('time (Miliseconds)')
  461.  
  462. subplot(3,2,6);
  463. plot(f,2*abs(Y5(1:NFFT/2+1)))
  464. title('Single-side Amplitude Spectrum of y(t)')
  465. ylabel('|Y (f)|')
  466.  
  467.  
  468. ______________________________________________
  469.  
  470.  
  471. fs = 10000;
  472. f= 60;
  473. t = 0:1/fs:4;
  474. y =4*square(2*pi*f*t);
  475.  
  476.  
  477. NFFT= 2^nextpow2(L);
  478. Y= fft(y,NFFT)/L;
  479. ff= Fs/2*linspace(0,1,NFFT/2+1);
  480.  
  481. plot(ff,2*abs(Y(1:NFFT/2+1)))
  482. title('Single-side Amplitude Spectrum of y(t)')
  483. ylabel('|Y (ff)|')
  484.  
  485. ___________________________________________
  486.  
  487.  
  488. A= audioread('17,5K_Hz.wav');
  489. B= A(:,1);
  490.  
  491. NFFT= 2^nextpow2(L);
  492. Y= fft(B,NFFT)/L;
  493. ff= Fs/2*linspace(0,1,NFFT/2+1);
  494.  
  495. plot(ff,2*abs(Y(1:NFFT/2+1)))
  496. title('Single-side Amplitude Spectrum of y(t)')
  497. ylabel('|Y (f)|')
  498.  
  499. _______________________________________
  500.  
  501.  
  502. Laplace Transform and Bode Plot
  503.  
  504. %Untuk men set sumbu X dalam Hz
  505. opts = bodeoptions;
  506. opts.FreqUnits = 'Hz';
  507. % untuk menset fungsi transfer
  508. % untuk tf([polynomial penyebut],[polynomial pembagi])
  509. G1 = tf([1],[0.001 1]) %Vc(s)/Vs(s)
  510. G2 = tf([-10^9-10^6 10^9],[10^3 10^6 0]) %Vr(s)/Vs(s)
  511. % untuk memplot bode plot
  512. figure(1)
  513. bode(G1,opts)
  514. grid on
  515. figure(2)
  516. bode(G2,opts)
  517. grid on
  518.  
  519. ____________________________________________
  520.  
  521. Transformasi Z
  522.  
  523. %18035(NIM 5 Digit Terakhir) x 3 = 54105
  524. %Ganti Semua 0 mejadi 1, 0=>1, =54115
  525. NIM_5_Digit= [5 4 1 1 5];
  526. NIM = NIM_5_Digit *0.2;
  527.  
  528. A=NIM(1,1);
  529. B=NIM(1,2);
  530. C=NIM(1,3);
  531. D=NIM(1,4);
  532. E=NIM(1,5);
  533.  
  534. %Tugas
  535. %1.
  536. x1 = [1 zeros(1,100)];
  537. y1 = [0 0];
  538. for i = 1:length(x1)
  539. n1 = i+2;
  540. y1(n1) = C*x1(i) + (-1*D*y1(n1-1)) + E*y1(n1-2);
  541. end
  542. y1 = y1(3:n1);
  543.  
  544. figure(1)
  545. subplot(3,1,1)
  546. stem(y1)
  547. title('Respon Impulse sistem')
  548.  
  549. subplot(3,1,2)
  550. m1 = 100; %jumlah sample
  551. BB1 = [1 0 0]; %numerator
  552. AA1 = [C -D E]; %denominator
  553. impz(BB1,AA1,m1)
  554.  
  555. [Z1,P1,K1] = tf2zp(BB1,AA1)
  556.  
  557. subplot(3,1,3)
  558. zplane(BB1,AA1)
  559.  
  560. %2.
  561. x2 = [1 zeros(1,100)];
  562. y2 = [0 0];
  563. for i = 1:length(x2)
  564. n2 = i+2;
  565. y2(n2) = x2(i)+((C+(-E))*y2(n2-1));
  566. end
  567. y2 = y2(3:n2);
  568.  
  569. figure(2)
  570. subplot(3,1,1)
  571. stem(y2)
  572. title('Respon Impulse sistem')
  573.  
  574. subplot(3,1,2)
  575. m2 = 100; %jumlah sample
  576. BB2 = [1 0 0]; %numerator
  577. AA2 = [1 C-E 0]; %denominator
  578. impz(BB2,AA2,m2)
  579.  
  580. [Z2,P2,K2] = tf2zp(BB2,AA2)
  581.  
  582. subplot(3,1,3)
  583. zplane(BB2,AA2)
  584.  
  585. %3
  586. x3 = [1 zeros(1,100)];
  587. y3 = [0 0];
  588. for i = 1:length(x3)
  589. n3 = i+2;
  590. y3(n3) = (A*x3(i) + (-1*C*y3(n3-1))) +(B*x3(i) + D*y3(n3-1));
  591. end
  592. y3 = y3(3:n3);
  593.  
  594. figure(3)
  595. subplot(3,1,1)
  596. stem(y3)
  597. title('Respon Impulse sistem')
  598.  
  599. subplot(3,1,2)
  600. m3 = 100; %jumlah sample
  601. BB3 = [1 0 0]; %numerator
  602. AA3 = [A-B -C-D 0]; %denominator
  603. impz(BB3,AA3,m3)
  604.  
  605. [Z3,P3,K3] = tf2zp(BB3,AA3)
  606.  
  607. subplot(3,1,3)
  608. zplane(BB3,AA3)
  609.  
  610.  
  611. %4.
  612. x4 = [1 zeros(1,100)];
  613. y4 = [0 0];
  614. for i = 1:length(x4)
  615. n4 = i+2;
  616. y4(n4) = exp(x4(i)) + (-1*A*y4(n4-1)) + (-1*B*y4(n4-2)) + (C*y4(n4-1)) + (D*y4(n4-2));
  617. end
  618. y4 = y4(3:n4);
  619.  
  620. figure(4)
  621. subplot(3,1,1)
  622. stem(y4)
  623. title('Respon Impulse sistem')
  624.  
  625. subplot(3,1,2)
  626. m4 = 100; %jumlah sample
  627. BB4 = [1 0 0]; %numerator
  628. AA4 = [exp(1) -A+C -B+D]; %denominator
  629. impz(BB4,AA4,m4)
  630.  
  631. [Z4,P4,K4] = tf2zp(BB4,AA4)
  632.  
  633. subplot(3,1,3)
  634. zplane(BB4,AA4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement