ADSP Lab Manual
ADSP Lab Manual
ADSP Lab Manual
% Perform convolution
y = conv(xn,hn);
ylabel('Amplitude');
title('The first input sequence');
Program
clc;
Results:
1 3 5 4 2 3 0
% inputs: x[n],h[n]
xn = input('Enter the first sequence: '); % [1 1 0 1]
hn = input('Enter the second sequence: '); % [1 2 3 0]
(OR)
clc;
clear all;
x1=input('enter the first sequence');
x2=input('enter the second sequence');
n1 = length(x1);
n2 = length(x2);
subplot(3,1,1);
stem(x1,'filled');
title('plot of first sequence');
subplot(3,1,2);
stem(x2,'filled');
title('plot the second sequnce');
y1=fft(x1,n);
y2=fft(x2,n);
y3=y1.*y2;
y=ifft(y3,n);
disp('the circular convolution result is ......');
disp(y);
subplot(3,1,3);
stem(y,'filled');
Results:
3 6 5 4
clc;
clear
all;
x1=input(‘enter the first sequence’);
x2=input(‘enter the second sequence’);
n=input(‘enter the no of points of the
dft’); subplot(3,1,1);
stem(x1,’filled’);
title(‘plot of first sequence’);
subplot(3,1,2);
stem(x2,’filled’);
title(‘plot the second sequnce’);
n1 =length(x1);
n2 = length(x2);
m = n1+n2-1; % Length of linear convolution
x = [x1 zeros(1,n2-1)]; % Padding of zeros to make it of
% length m
y = [x2 zeros(1,n1-1)];
x_fft = fft(x,m);
y_fft = fft(y,m);
dft_xy =
x_fft.*y_fft;
y=ifft(dft_xy,m);
disp(‘the circular convolution result is ......’);
disp(y);
subplot(3,1,3);
stem(y,’filled’);
title(‘plot of circularly convoluted sequence’);
VTU CPGSB Muddenhalli Page 9
ADSP Lab Manual
Output
n = 0:N-1;
ylabel('Amplitude');
title('INPUT SEQUENCE');
xn = xn/N;
n = 0:N-1;
xlabel('Samples');
ylabel('Amplitude');
title('INPUT SEQUENCE');
% Plot the magnitude of output
subplot(3,1,2);
stem(n,round(real(xn)));
xlabel('Samples');
ylabel('Amplitude');
title('MAGNITUDE');
% Plot the phase of output sequence
subplot(3,1,3);
stem(n,angle(xn));
xlabel('Samples');
ylabel('Amplitude');
title('DEGREE');
Results:
1 3 -1 -2
disp(yn);
n = 1:N;
Results
3 6 5 4
(a)Let X[k]=DFT{x[n]}. For various values of L , set to zero “high frequency coefficients ”
X[64-1]=………….X[64]=……X[64+L]=0 and take the inverse DFT .plot the results
(b)Let XDCT[k]=DCT(x[n]).For the same values of L ,set to zero “high frequency coefficient ”
XDCT[127-L]=….. XDCT[127]. Take the inverse DCT for each case and compare the
reconstruction with the previous case.
% X[k] = DFT(x[n])
Xk = fft(x);
plot(x);
title('INPUT SEQUENCE');
% XDCT[k] = DCT(x[n])
XDCTk = dct(z);
(OR)
Program:
clc;
clear all;
close all;
n=0:127;
x=n-64;
z=x;
xk=fft(x);
L=32;
xk((64-L):(L+64))=0;
yf=ifft(xk);
figure;
subplot(2,2,1);
plot(x);
title('input sequence');
subplot(2,2,2);
plot(real(yf(1:128)));
title('IFFT output sequence');
xk=dct(z);
xk((128-L):(128+L))=0;
x1=idct(xk);
subplot(2,2,3);
plot(x);
title('input sequence');
subplot(2,2,4);
plot(x1);
title('IDCT output sequence');
PROGRAM:
%Power spectral density
t = 0:0.001:0.6;
x = sin(2*pi*50*t)+sin(2*pi*120*t);
y = x + 2*randn(size(t));
subplot(2,1,1);
% figure(1);
plot(1000*t(1:50),y(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('time (milliseconds)');
Y = fft(y,512);
%The power spectral density, a measurement of the energy at various frequencies, is:
Pyy = Y.* conj(Y) / 512;
f = 1000*(0:256)/512;
subplot(2,1,2);
% figure(2);
plot(f,Pyy(1:257))
title('Frequency content of y');
xlabel('frequency (Hz)');
OUTPUT
as:
The simplest method to interpolate by a factor of L is to add L-1 zeros in between the samples,
multiply the amplitude by L and filter the generated signal, with a so-called anti-imaging low
pass filter at the high sampling frequency.
Program
clc;
clear all;
close all;
t=0:0.01:1;
d=input('enter number D/I');
x=sin(2*pi*5*t);
y=decimate(x,d);
subplot(3,1,1);
stem(x(1:25));
title('original input signal');
xlabel('samples');
ylabel('amplitude');
subplot(3,1,2);
stem(y);
title('decimated output');
xlabel('samples');
ylabel('amplitude');
y1=interp(y,d);
subplot(3,1,3);
stem(y1(1:25));
title('interpolation output');
xlabel('samples');
ylabel('amplitude');
Results:
6) Image Denoising
The denoising method described for the one-dimensional case applies also to images and applies
well to geometrical images. The two-dimensional denoising procedure has the same three steps
and uses two-dimensional wavelet tools instead of one-dimensional ones. For the threshold
selection, prod(size(y)) is used instead of length(y) if the fixed form threshold is used.
Program:
load woman
init = 2055615866; rng(init);
x = X + 15*randn(size(X));
[thr,sorh,keepapp] = ddencmp('den','wv',x);
thr =557.9838
xd = wdencmp('gbl',x,'sym4',2,thr,sorh,keepapp);
figure('Color','white')
colormap(pink(255)), sm = size(map,1);
image(wcodemat(X,sm)), title('Original Image')
figure('Color','white')
colormap(pink(255))
image(wcodemat(x,sm)), title('Noisy Image')
image(wcodemat(xd,sm)), title('De-Noised Image')
h0=[0.7071 0.7071];
h1=[0.7071 -0.7071];
% disp('2D-DWT Decomposition')
[A,H,V,D]=dwt2(x,h0,h1);
for i=1:m/2
for j=1:n/2
% disp('2D-DWT Decomposition of A using formula')
Ad(i,j)=(x(2*i-1,2*j-1)+x(2*i-1,2*j)+x(2*i,2*j-1)+x(2*i,2*j))*h0(1)*h0(1);
end
end
figure
imshow(y)
figure
Atemp=uint8(Ad);
imshow(Atemp)
OutPut
Original Image
Compressed Image