Sunteți pe pagina 1din 6

m

%FFT Computation
clc;
close all;
clear all;
Fs=1000;
T=1/Fs;
L=1000;
t=(0:L-1)*T;
x=sin(2*pi*50*t);
subplot(1,2,1);
plot(t,x,'k');
title('sin wave');
xlabel('time');
ylabel('amplitude');
NFFT=2^nextpow2(L);
Y=fft(x,NFFT)/L;
f=Fs/2*linspace(0,1,NFFT/2);
subplot(1,2,2);
plot(f,2*abs(Y(1:NFFT/2)));
title('single-sided amplitude spectrum of y(t)');
xlabel('frequency(hz)');
ylabel('|Y(f)|');

m
%Fourier Trans for Stationary Signal
clc;
close all;
clear all;
Fs=300;
T=1/Fs;
L=300;
t=(0:L-1)*T;
x=cos(2*pi*10*t)+cos(2*pi*25*t)+cos(2*pi*50*t)+cos(2*pi*100*t);
subplot(1,2,1);
plot(x);
title('signal');
xlabel('time');
ylabel('amplitude');
NFFT=2^nextpow2(L);
Y=fft(x,NFFT)/L;
f=Fs/2*linspace(0,1,NFFT/2);
subplot(1,2,2);
plot(f,2*abs(Y(1:NFFT/2)));
title(' amplitude spectrum ');
xlabel('frequency(hz)');
ylabel('|Y(f)|');

m
m
m
m
m

m
%Fourier Trans For Non- Stationary Signal
clc;
close all;
clear all;
Fs=500;
T=1/Fs;
L=500;
t=(0:L-1)*T;
y=cos(2*pi*10*t)+cos(2*pi*25*t)+cos(2*pi*50*t)+cos(2*pi*100*t);
x=y+2*randn(size(t));
subplot(1,2,1);
plot(x);
title('signal');
xlabel('time');
ylabel('amplitude');
NFFT=2^nextpow2(L);
Y=fft(x,NFFT)/L;
f=Fs/2*linspace(0,1,NFFT/2);
subplot(1,2,2);
plot(f,2*abs(Y(1:NFFT/2)));
title(' frequency spectrum ');
xlabel('frequency(hz)');
ylabel('|Y(f)|');

m
%Signal Generation
clc;
close all;
clear all;
n=0:1:127;
s=sin(2*pi*n);
figure(1);
subplot(1,2,1);
plot(n,s,'k');
grid;
title('not exactly sin signal');
xlabel('time');
ylabel('amplitude');
d=sin(2*pi*(4/128)*n);
subplot(1,2,2);
plot(n,d,'k');
title(' exact sin signal ');
xlabel('time');
ylabel('amplitude');

m
m
%3D Surface Plots
clc;
close all;
clear all;
x=-3:0.25:3;
y=-3:0.25:3;
[x,y]=meshgrid(x,y);
z=1.8.^(-1.5*sqrt(x.^2+y.^2)).*cos(0.5.*y).*sin(x);

m
figure(1);
mesh(x,y,z);
xlabel('x');
ylabel('y');
zlabel('z');

m
m
%3D Plots
clc;
clear all;
close all;
[x,y,z]=sphere(20);
subplot(231),surf(x,y,z),xlabel('x'),ylabel('y'),zlabel('z');
t=linspace(0,pi,50);
r=1+sin(t);
[x,y,z]=cylinder(r);
subplot(232),surf(x,y,z),xlabel('x'),ylabel('y'),zlabel('z');
y=[1 6.5 7;2 6 7;3 5.5 7;3 4 7;2 3 7;1 2 7];
subplot(233),bar3(y),xlabel('column'),ylabel('row'),zlabel('value');
t=0:0.2:10;
x=t;
y=sin(t);
z=t.^1.5;
subplot(234);
stem3(x,y,z,'fill');
grid on;
xlabel('x');
ylabel('y');
zlabel('t');
t=0:0.4:10;
x=t;
y=sin(t);
z=t.^1.5;
subplot(235);
scatter3(x,y,z,'filled'),grid on,xlabel('x'),ylabel('y'),zlabel('t');
x=[5 9 14 20];
explode=[0 0 1 0];
subplot(236),pie3(x,explode);
a 
 
 a  
clc;
clear all;
close all;
A=[1 2 3 4 5 6 7 8 ];
H=[.7071 .7071];
G=[-.7071 .7071];
H0=[0.7071 0.7071];
G0=[0.7071 -0.7071];
a1=conv(A,H);
l1=dyaddown(a1,0,'c');
(dyaddown - Dyadic downsampling,
b1=conv(A,G);
h1=dyaddown(b1,0,'c');

a11=conv(l1,H);
l1l1=dyaddown(a11,0,'c');
a12=conv(l1,G);
h1l1=dyaddown(a12,0,'c');
b11=conv(h1,H);
l1h1=dyaddown(b11,0,'c');
b12=conv(h1,G);
h1h1=dyaddown(b12,0,'c');
c11=dyadup(l1l1,0,'c');
rl1l1=conv(c11,H0);
c12=dyadup(h1l1,0,'c');
rh1l1=conv(c12,G0);
d11=dyadup(l1h1,0,'c');
rl1h1=conv(d11,H0);
d12=dyadup(h1h1,0,'c');
rh1h1=conv(d12,G0);
c1=dyadup((rl1l1+rh1l1),0,'c');
rl1=conv(c1,H0);
d1=dyadup((rl1h1+rh1h1),0,'c');
rh1=conv(d1,G0);
R=round(rl1+rh1);
disp(A);
disp(R)

aa 

 

I=imread('cameraman.tif');
x=size(I,1);
%mm = size(X,dim) returns the size of the dimension of X specified by scalar
dim.
y=size(I,2);
figure(1);subplot(2,3,1);imshow(I);xlabel(x);ylabel(y);title('original');
%(imshow(I) displays the grayscale image I.)
dwtmode('per');
[a1,v1,h1,d1]=dwt2(I,'db4');
subplot(2,3,2);imshow(uint8([a1,v1;h1,d1]));x=size(a1,1);y=size(a1,2);
xlabel(x);ylabel(y);title('Level1 DWT output');
[a2,v2,h2,d2]=dwt2(a1,'db4');
subplot(2,3,3);imshow(uint8([a2,v2;h2,d2]));x=size(a2,1);y=size(a2,2);
xlabel(x);ylabel(y);title('Level2 DWT output');
%Reconstruction images
A1=idwt2(a2,v2,h2,d2,'db4');
subplot(2,3,4);imshow(uint8(A1));x=size(A1,1);y=size(A1,2);
xlabel(x);ylabel(y);title('Level1 IDWT output');
A2=idwt2(a1,v1,h1,d1,'db4');
subplot(2,3,5);imshow(uint8(A2));x=size(A2,1);y=size(A2,2);
xlabel(x);ylabel(y);title('Level2 DWT output');

m
m

m
m
%WAVELET BASED COMPRESSION
%****************************
%removes all variables, globals, functions and
%MEX links(MATLAB loads and runs a different entry point symbol for C or
Fortran MEX-files)
clear all;
% CLOSE ALL closes all the open figure windows.
close all;
%read the image
input_image1=imread('Cameraman.tif');
%display input image
%add noise
figure;
imshow(input_image1);
%give the number of decomposition level which must be integer and should not
exceed 3
n=input('enter the decomposition level');
%****************************************************************************
*
[Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('haar');
% computes four filters associated with the orthogonal or biorthogonal
% wavelet named in the string 'wname'.
%
The four output filters are:
%
LO_D, the decomposition low-pass filter
%
HI_D, the decomposition high-pass filter
%
LO_R, the reconstruction low-pass filter
%
HI_R, the reconstruction high-pass filter
% Available wavelet names 'wname' are:
% Daubechies: 'db1' or 'haar', 'db2', ... ,'db45'
%Coiflets : 'coif1', ... , 'coif5'
%Symlets
: 'sym2' , ... , 'sym8', ... ,'sym45'
%Discrete Meyer wavelet: 'dmey'
%**********************************************************************
%wavedec2
- Multi-level 2-D wavelet decomposition.
[c,s]=wavedec2(input_image1,n,Lo_D,Hi_D);
% gives the wavelet decomposition of the matrix input_image at level n, using
the
% wavelet named in string 'wname' or low pass and high pass
% Outputs are the decomposition vector C and the
%corresponding bookkeeping matrix S.
disp(' the decomposition vector Output is');
disp(c);
%****************************************************************************
*********
%Thresholds for wavelet 2-D using Birge-Massart strategy.
[thr,nkeep] = wdcbm2(c,s,1.5,3*prod(s(1,:)));

m
% give level-dependent thresholds 'thr'and numbers of coefficients to be
kept 'nkeep'
% for compression. 'thr' is obtained using a wavelet coefficients
%selection rule based on Birge-Massart strategy.
%disp('level-dependent thresholds');
%disp(thr);
%disp(' numbers of coefficients to be');
%disp(nkeep);
%***************************************************************************
%compression using wavelet packets.
[compressed_image,TREED,comp_ratio,PERFL2]
=WPDENCMP(thr,'s',n,'haar','threshold',5,1);
disp('compression ratio in percentage');
disp(comp_ratio);
% returns a compressed version compressed_image of input
% signal 'thr' (2-D) obtained by wavelet packet coefficients thresholding.
% The additional output argument TREED is the
% wavelet packet best tree decomposition of compressed_image.
% PERFL2 and PERF0 are L^2 recovery and compression scores in percentages.
%Multi-level 2-D wavelet reconstruction.
re_ima1 = waverec2(c,s,'haar');
re_ima=uint8(re_ima1);
subplot(1,3,1);
imshow(input_image1);
title('i/p image');
subplot(1,3,2);
imshow(compressed_image);
title('compressed image');
subplot(1,3,3);
imshow(re_ima);
title('reconstructed image');

S-ar putea să vă placă și