RenHao

20150602_multimedia_finalexam_pra

Jun 2nd, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.05 KB | None | 0 0
  1. % DCT 1D
  2.  
  3. clear all
  4. close all
  5.  
  6. N=8;
  7. G = zeros(N,N);
  8. alpha_u=1;
  9.  
  10. for u = 0:N-1
  11.     for x = 0:N-1
  12.         G(u+1,x+1) = alpha_u * cos(pi*u*(x+1/2)/N);
  13.     end
  14. end
  15.  
  16. figure(1);
  17. for i=1:8
  18.     subplot(4,2,i)
  19.     bar(G(i,:))
  20. end
  21.  
  22. %%%%%
  23.  
  24. %% DCT 2D
  25.  
  26. close all
  27. clear all
  28.  
  29. N=8;
  30. G=zeros(N,N,N,N);
  31. alpha_u=1;
  32. alpha_v=1;
  33.  
  34. for u = 0:N-1
  35.     for v = 0:N-1
  36.         for x = 0:N-1
  37.             for y = 0:N-1
  38.                 G(u+1,v+1,x+1,y+1) = alpha_u * alpha_v * cos(pi*u*(x+1/2)/N) * cos(pi*v*(y+1/2)/N);
  39.             end
  40.         end
  41.     end
  42. end
  43.  
  44. figure(1);
  45. for i=1:8
  46.     for j=1:8
  47.         subplot(8,8,(i-1)*8+j)
  48.         imagesc(reshape(G(i,j,:,:),8,8))
  49.     end
  50. end
  51.  
  52.  
  53. %%%%%%
  54.  
  55. %%%%%%
  56.  
  57. close all
  58. clear all
  59.  
  60. N=8;
  61. g=zeros(N,N);
  62. t=linspace(0,pi,N); %cut 0~pi into N pieces
  63.  
  64. for i = 1:N
  65.     g(i,:)=cos((i-1)*t);
  66. end
  67.  
  68. G = zeros(N,N);
  69. alpha_u=1;
  70. n=1:N;
  71.  
  72. for i = 0:N-1
  73.     for u = 0:N-1
  74.         G(i+1,u+1) = sum(alpha_u.*g(i+1,:).*cos(u*pi/N*(n + 1/2)));
  75.     end
  76. end
  77.  
  78. figure(1)
  79. for i=1:8
  80.     subplot(4,2,i)
  81.     bar(G(i,:));
  82. end
  83.  
  84. %%%%%
Advertisement
Add Comment
Please, Sign In to add comment