Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % DCT 1D
- clear all
- close all
- N=8;
- G = zeros(N,N);
- alpha_u=1;
- for u = 0:N-1
- for x = 0:N-1
- G(u+1,x+1) = alpha_u * cos(pi*u*(x+1/2)/N);
- end
- end
- figure(1);
- for i=1:8
- subplot(4,2,i)
- bar(G(i,:))
- end
- %%%%%
- %% DCT 2D
- close all
- clear all
- N=8;
- G=zeros(N,N,N,N);
- alpha_u=1;
- alpha_v=1;
- for u = 0:N-1
- for v = 0:N-1
- for x = 0:N-1
- for y = 0:N-1
- 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);
- end
- end
- end
- end
- figure(1);
- for i=1:8
- for j=1:8
- subplot(8,8,(i-1)*8+j)
- imagesc(reshape(G(i,j,:,:),8,8))
- end
- end
- %%%%%%
- %%%%%%
- close all
- clear all
- N=8;
- g=zeros(N,N);
- t=linspace(0,pi,N); %cut 0~pi into N pieces
- for i = 1:N
- g(i,:)=cos((i-1)*t);
- end
- G = zeros(N,N);
- alpha_u=1;
- n=1:N;
- for i = 0:N-1
- for u = 0:N-1
- G(i+1,u+1) = sum(alpha_u.*g(i+1,:).*cos(u*pi/N*(n + 1/2)));
- end
- end
- figure(1)
- for i=1:8
- subplot(4,2,i)
- bar(G(i,:));
- end
- %%%%%
Advertisement
Add Comment
Please, Sign In to add comment