0% found this document useful (0 votes)
138 views2 pages

DCT Matlab

The document shows the steps to perform DCT compression on an image. It loads an image, converts it to grayscale and double format. It takes the DCT of the image and sorts the coefficients by power. It reconstructs the image keeping only the top 20000 coefficients, compressing the image. It displays the original and reconstructed images.

Uploaded by

milericar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views2 pages

DCT Matlab

The document shows the steps to perform DCT compression on an image. It loads an image, converts it to grayscale and double format. It takes the DCT of the image and sorts the coefficients by power. It reconstructs the image keeping only the top 20000 coefficients, compressing the image. It displays the original and reconstructed images.

Uploaded by

milericar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

DCT Syntax

%%%%%%%%% START %%%%%%%


clc
close all
im=imread('a.bmp');
im = double(im)/255;
im = rgb2gray(im);
subplot(211)
imshow(im)
title('Original image');
img_dct=dct2(im);
img_pow=(img_dct).^2;
img_pow=img_pow(:);
[B,index]=sort(img_pow);%no zig-zag
B=flipud(B);
index=flipud(index);
compressed_dct=zeros(size(im));
coeff = 20000;% maybe change the value
for k=1:coeff
compressed_dct(index(k))=img_dct(index(k));
end
im_dct=idct2(compressed_dct);
subplot(212)
imshow(im_dct)
title('DCT Compress Image');
% for saving this image use "imwrite" command
imwrite(im_dct, 'compress.bmp')
%%%%%%%% END %%%%%%%
ASK Syntax
clear all;
clc;
close all;
F1=input('Enter the frequency of carrier=');
F2=input('Enter the frequency of pulse=');
A=3;%Amplitude
t=0:0.001:1;
x=A.*sin(2*pi*F1*t);%Carrier Sine wave
u=A/2.*square(2*pi*F2*t)+(A/2);%Square wave message
v=x.*u;
subplot(3,1,1);
plot(t,x);
xlabel('Time');
ylabel('Amplitude');
title('Carrier');
grid on;
subplot(3,1,2);
plot(t,u);
xlabel('Time');
ylabel('Amplitude');
title('Square Pulses');
grid on;subplot(3,1,3);
plot(t,v);
xlabel('Time');
ylabel('Amplitude');

title('ASK Signal');
grid on;
ASK, FSK, PKS
%matlab code for digital modulation(ask, fsk and psk)
pi=3.14;
f=5;
f2=10;
phi=pi;
x=[1 0 1 1 0];
nx=size(x,2);
i=1;
while i<nx+1
t = i:0.001:i+1;
if x(i)==1
ask=sin(2*pi*f*t);
fsk=sin(2*pi*f*t);
psk=sin(2*pi*f*t);
else
ask=0;
fsk=sin(2*pi*f2*t);
psk=sin(2*pi*f*t+phi);
end
subplot(3,1,1);
plot(t,ask);
hold on;
grid on;
axis([1 10 -2 2]);
subplot(3,1,2);
plot(t,fsk);
hold on;
grid on;
axis([1 10 -2 2]);
subplot(3,1,3);
plot(t,psk);
hold on;
grid on;
axis([1 10 -2 2]);
i=i+1;
end

You might also like