Digital Signal Processing
Digital Signal Processing
Processing
Index:
• Standard discrete time signals
• Z-Transforms
• Flipping and scaling
• Folding
• Time shifting
• Even and Odd signals
• Sampling
• Quantization
• Nyquist criterion
• Filters
• Windowing Techniques
• Convolution
• Fourier transform
Standard discrete time signals:
• Impulse signal
• Step signal
• Ramp signal
• Falling exponential signal
• Rising exponential signal
• Sinusoidal signal
• Cosine signal
Unit Impulse signal
%% sine signal
f=1/20;
x=sin(2*pi*f*n)
stem(n,x);
xlabel('n');ylabel('x(n)');
title('sine signal');
Cosine signal
%% cosine signal
f=1/20;
x=cos(2*pi*f*n)
stem(n,x);
xlabel('n');ylabel('x(n)');
title('cosine signal');
Z-Transforms
syms n a b;
%% example-1
x=n;
disp('(a) z-transform of n is:');
ztrans(x)
%% example-2
x=a^n;
disp('(b) z-transform of a^n is:');
ztrans(x)
%% example-3
x=n*(a^n);
disp('(c) z-transform of n*(a^n) is:');
ztrans(x)
%% example-4
x=n^2*a^n;
disp('(d) z-transform of n^2*a^n is:');
ztrans(x)
%% example-5
x=exp(a*n);
disp('(e) z-transform of exp(a*n) is:');
ztrans(x)
%% example-6
x=exp(-a*n);
disp('(f) z-transform of exp(-a*n) is:');
ztrans(x)
%% example-7
x=n*exp(a*n);
disp('(g) z-transform of n*exp(a*n) is:');
ztrans(x)
%% example-8
x=sin(a*n);
disp('(h) z-transform of sin(a*n) is:');
ztrans(x)
%% example-9
x=cos(a*n);
disp('(i) z-transform of cos(a*n) is:');
ztrans(x)
%% example-10
x=b^n*sin(a*n);
disp('(j) z-transform of b^n*sin(a*n) is:');
ztrans(x)
%% example-11
x=b^n*cos(a*n);
disp('(k) z-transform of b^n*cos(a*n) is:');
ztrans(x)
Mathematical operations on Discrete Time Signals:
• Scaling: amplitude scaling and time scaling
• Folding
• Shifting: right shift and left shift
Amplitude Scaling:
Amplitude scaling of a discrete time signal is accomplished by
multiplying the value of every signal sample by the constant A.
function [ x ] = y( n )
x=n.*(n>=0)+0.*(n<0);
end
subplot(1,2,2);stem(n,y1);
xlabel('n');ylabel('y1');title('signal y(-n)');
Example-1 output:
Example-2
n=-2:5;
x=[4,3,-1,4,2,6,-3,-1];
% fold signal
m=-fliplr(n);
y=fliplr(x);
% display signal
subplot(2,1,1);stem(n,x);
title('Input Signal');
subplot(2,1,2);stem(m,y);
title('After folding');
Example-2 output:
Shifting:
Shifting can be in two ways:
When a discrete time signal exhibits symmetry with respect to n=0 then
it is called an even signal.
A discrete time signal x(n) which is neither even nor odd can be
expressed as sum of even and odd signal.
x(n)=xe(n)+xo(n)
Where,
xe(n)=even part of x(n)
xo(n)=odd part of x(n)
NOTE:
If x(n) is even then its odd part will be zero.
If x(n) is odd then its even part will be zero.
%% cosine signal
f=1/20;
x1=cos(2*pi*f*n);
subplot(2,2,1);stem(n,x1);
xlabel('n');ylabel('x(n)');
title('cosine signal');
%% cosine signal (folded)
f=1/20;
x2=cos(2*pi*f*-n);
subplot(2,2,2);stem(n,x2);
xlabel('n');ylabel('x(n)');
title('cosine signal (folded)');
%% check if odd or even
if x2==x1
disp('"even signal"');
elseif x2==(-x1)
disp('"odd signal"');
else
disp('"neither even or odd"');
end
%% compute even and odd part
xe=(x1+x2)/2;
xo=(x1-x2)/2;
subplot(2,2,3);stem(n,xe);
xlabel('n');ylabel('x(n)');
title('even part of x(n)');
subplot(2,2,4);stem(n,xo);
xlabel('n');ylabel('x(n)');
title('odd part of x(n)');
Sampling theorem and Nyquist criterion:
“A band limited signal can be reconstructed exactly if it is sampled at a
rate at least twice the maximum frequency component in it.”
Types:
Low pass filter
High pass filter
Band pass filter
Band stop filter
Windowing techniques:
Windows are sometimes used in the design of digital filters, in particular
to convert an "ideal" impulse response of infinite duration, such as a sinc
function, to a finite impulse response (FIR) filter design. That is called
the window method.
Types of windows:
Rectangular window
Blackman window
Hamming window
Hanning window
Convolution:
Let x1(n) and x2(n) be the input sequences
x3(n) be the output sequence
Multiply each column element with row elements and fill up the matrix
array
Now the sum of the diagonal elements gives the samples of output
sequence x3(n)
clc
clear all
close all
%% first sequence
x=input('Enter the first sequence: ');
l1=input('Enter the lower limit: ');
u1=input('Enter the upper limit: ');
x1=l1:1:u1;
%% second sequence
h=input('Enter the second sequence: ');
l2=input('Enter the lower limit: ');
u2=input('Enter the upper limit: ');
h1=l2:1:u2;
%% output sequence
l=l1+l2;
u=u1+u2;
n=l:1:u;
y=conv(x,h);
%% plot
subplot(2,2,1);stem(x1,x);
xlabel('n');ylabel('x(n)');title('signal x(n)');
subplot(2,2,2);stem(h1,h);
xlabel('n');ylabel('h(n)');title('signal h(n)');
subplot(2,2,[3 4]);stem(n,y);
xlabel('n');ylabel('y(n)');title('signal y(n)');
Fourier transform:
Stage - 1
Stage - 2
Stage - 3
>> fft([1 0.7071 0 -0.7071 -1 -0.7071 0 0.7071],8)
ans =
Columns 1 through 4
0 4.0000 0 0.0000
Columns 5 through 8
0 0.0000 0 4.0000