Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Program No. 1
1. Verification of Sampling Theorem both in time and frequency domains.
tfinal=0.05;
t=0:0.00005:tfinal;
xt=cos(2*pi*fd*t);
fs1=1.3*fd;
n1=0:1/fs1 :tfinal;
xn=cos(2*pi*n1*fd);
subplot(3,1,1);
plot(t,xt,'b',n1,xn,'r*-');
title('Undersampling Plot');
fs2=2*fd;
n2=0:1/fs2 :tfinal;
xn=cos(2*pi*n2*fd);
subplot(3,1,2);
plot(t,xt,'b',n2,xn,'r*-');
title('Nyquist Plot');
fs3=5*fd;
n3=0:1/fs3 :tfinal;
xn=cos(2*pi*n3*fd);
subplot(3,1,3);
plot(t,xt,'b',n3,xn,'r*-');
title('Oversampling Plot');
xlabel('time');
ylabel('amplitude');
legend('analog','discrete');
Undersampling Plot
1
-1
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
Nyquist Plot
1
-1
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
Oversampling Plot
1
amplitude
analog
0 discrete
-1
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
time
Program No. 2
Evaluation of impulse response of a system
clc;
clear all;
close all;
% Difference equation of a second order system
% y(n) = x(n)+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2)
b=input('enter the coefficients of x(n),x(n-1)-----');
a=input('enter the coefficients of y(n),y(n-1)----');
N=input('enter the number of samples of imp response ');
[h,n]=impz(b,a,N);
stem(n,h);
title('plot of impulse response');
ylabel('amplitude');
xlabel('time index----->N');
disp(h);
grid on;
Output
enter the coefficients of x(n),x(n-1)-----[1 -2 -3 2]
enter the coefficients of y(n),y(n-1)----[2,-1,2,2]
enter the number of samples of imp response 10
h(n)={0.5000,-0.7500,-2.3750,0.0625,3.1563,3.8906,-1.2734,-7.6836,-
6.4590,5.7275}
0
amplitude
-2
-4
-6
-8
0 1 2 3 4 5 6 7 8 9
time index----->N
Program No. 3
Linear convolution of given sequences.
clc;
x1=input('enter the first sequence ');
subplot(3,1,1);
stem(x1);
xlabel('n');
ylabel('x1');
title('plot of the first sequence x1');
x2=input('enter 2nd sequence ');
subplot(3,1,2);
stem(x2);
xlabel('n');
ylabel('x2');
title('plot of 2nd sequence x2');
f=conv(x1,x2);
disp('output of linear convolution of two sequences is y = ');
disp(f);
xlabel('n');
ylabel('f');
subplot(3,1,3);
stem(f);
title('linear conv of two sequences x1 & x2 ');
OUTPUT:
enter the first sequence [1,2,-1,-2]
enter 2nd sequence [1,-2,-3,2,4]
output of linear convolution of two sequences is
y = 1 0 -8 -4 15 12 -8 -8
Output:
Enter The Input Sequence[1,2,3,4]
Enter The Impulse Response[4,3,2,1]
Circular Convolution of x(n) & h(n) is y(n)=
24 22 24 30
clc;
close all;
x1=input('Enter The First sequence x(n)');
h1=input('Enter The Second sequence h(n)');
N1=length(x1);
N2=length(h1);
N=max(N1,N2);
if(N1>N2)
h1=[h1,zeros(1,N1-N2)];
x1=[x1,zeros(1,N2-N1)];
end;
x=transpose(x1);
h=transpose(h1);
temp=h;
for i=1:N-1;
temp=circshift(temp,1);
h=horzcat(h,temp);
end;
h
x
y=h*x
disp('Circular convolved output y[n]=');y
subplot(3,1,1);
stem(x1);
xlabel('N-->');
ylabel('Amplitude-->');
title('Input Sequence x[n]');
subplot(3,1,2);
stem(h1);
xlabel('N-->');
ylabel('Amplitude-->');
title('Second Sequence h[n]');
subplot(3,1,3);
stem(y);
xlabel('N-->');
ylabel('Amplitude-->');
title('Circular convolved output y[n]');
Output:
Enter The First sequence x(n)[1 2 3 4 ]
Enter The Second sequence h(n)[4 3 2 1 ]
h=
4 1 2 3
3 4 1 2
2 3 4 1
1 2 3 4
x=
1
2
3
4
end
disp('Circular Convolution of x(n) & h(n) is y(n)=');
disp(y);
n1=0:N-1;
xlabel('n1');
ylabel('y');
subplot(3,1,3);
stem(n1,y);
title('Circular Convolution Output y(n)');
output:
Enter The Input Sequence[1,2]
Enter The Impulse Response[1,3,5,7,2]
xn = 1 2 0 0 0 0
hn = 1 3 5 7 2 0
Circular Convolution of x(n) & h(n) is y(n)=
1 5 11 17 16 4
Program No. 5.
Computation of N – point DFT and to plot the magnitude and phase
spectrum.
Aim: Write a program to compute N – point DFT and to plot the magnitude and phase
spectrum.
output;
Enter the the value of N 8
Enter the input sequence for which DFT is to be calculated [1,2,3,4,-1,-2,-3,-4]
MagX = Φ
Columns 1 through 5
Columns 6 through 8
PhaseX =
Columns 1 through 5
Columns 6 through 8
magnitude plot
15
10
x(n)
0
0 1 2 3 4 5 6 7
n
Phase plot
200
100
Q(n)
-100
0 1 2 3 4 5 6 7
n
Program No. 6.
LINEAR CONVOLUTION USING DFT AND IDFT
Aim: Write a program to perform linear convolution using DFT and IDFT.
clc;
clear all;
close all;
x=input('Enter x[n]:');
h=input('Enter h[n]:');
nx=length(x);
nh=length(h);
n=nx+nh-1;
xnew=[x zeros(1,n-nx)];
hnew=[h zeros(1,n-nh)];
xf=fft(xnew);
hf=fft(hnew);
zf=xf.*hf;
z=ifft(zf);
lx=0:1:nx-1;
lh=0:1:nh-1;
nz=0:1:length(z)-1;
subplot(3,1,1);
stem(lx,x);
xlabel('Time');ylabel('Amplitude');
title('Input sequence x[n]');
grid;
subplot(3,1,2);
stem(lh,h);
xlabel('Time');ylabel('Amplitude');
%Verification
z1=conv(xnew,hnew)
INPUT:
Enter x[n]:[1 2 3 4]
Enter h[n]:[4 3 2 1]
OUTPUT:
z1 = 4 11 20 30 20 11 4 0 0 0 0 0 0
b = [1];%x(n) coefficients
%impulse input
x = [1,zeros(1,N-1)];
n = 0:N-1;
% Impulse Response
h = filter(b,a,x);
subplot(2,1,1);
stem(n,x);
title('impulse input');
xlabel('n');
ylabel('?(n)');
subplot(2,1,2);
stem(n,h);
title('impulse response');
xlabel('n');
ylabel('h(n)');
Program No. 8.
Calculation of DFT and IDFT by FFT
Aim: Write a program to compute DFT and IDFT by FFT.
n = 0:6;
x = input('enter the i/p sequence ');
a = fft(x);
mag = abs(a);
pha = angle(a);
subplot(3,1,1);
stem(mag);
xlabel('k')
ylabel('|x(k)|');
grid on
title('Magnitude Response');
subplot(3,1,2);
stem(pha);
xlabel('k')
ylabel('?(k)');
grid on
title('phase Response');
xn= ifft(a);
subplot(3,1,3);
stem(xn);
xlabel('n')
ylabel('x(n)');
title('Input Sequence');
output:
enter the i/p sequence [1,2,3,1,-4,-5,-1,-2]
Magnitude Response
20
|x(k)|
10
0
1 2 3 4 5 6 7 8
k
phase Response
5
?(k)
-5
1 2 3 4 5 6 7 8
k
Input Sequence
5
x(n)
-5
1 2 3 4 5 6 7 8
n
Aim: Write a program to design digital Butterworth low pass filter for a given
specification
clc;
rp = input(‘Enter the pass band ripple freq’);
rs = input(‘Enter the stop ripple freq’);
fp = input(‘Enter the pass band freq’);
fs = input(‘Enter the stop band freq’);
f = input(‘Enter the sample freq’);
w1=2*fp/f;
w2=2*fs/f;
[n,wn]= buttord(w1,w2,rp,rs);
[b,a] = butter(n,wn);
w=0:.1:pi;
[h,p] = freqz(b,a,w);
g=20*log10(abs(h));
A=angle(h);
subplot (2,2,1); plot(p/pi,g);
ylabel(‘amp’);
xlabel(‘ferq’);
title(‘amp,freq’);
subplot (2,2,2); plot(p/pi,A);
xlabel(‘normal. freq’);
ylabel(‘phase’);
title(‘normal.freq,phase’);
Output:
Enter the pass band ripple freq= .5
Enter the stop band ripple freq= 40
Enter the pass band freq= 2000
Enter the stop band freq= 3000
sample freq= 10000
Output
Enter the pass ripple freq .5
Enter the stop ripple freq 40
Enter the pass band freq 2000
Enter the stop band freq 3000
Enter the sample freq 10000
amp,freq
0
-100
amp
-200
-300
-400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
ferq
normal.freq,phase
4
2
phase
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normal. freq
Output:
Output
Enter the pass ripple freq .3
Enter the stop ripple freq 30
Enter the pass band freq 2000
Enter the stop band freq 3000
Enter the sample freq 10000
clc;
clear all;
wc=input('enter the value of cut off frequency');
N=input('enter the order of filter');
alpha=(N-1)/2;
eps=0.001;
%Rectangular Window
n=0:1:N-1;
hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));
hn=hd
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
%Hamming Window
n=0:1:N-1;
wh=0.54-0.46*cos((2*pi*n)/(N-1));
hn=hd.*wh
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'ms');
hold off;
hold on
%Hanning Window
n=0:1:N-1;
wh=0.5-0.5*cos((2*pi*n)/(N-1));
hn=hd.*wh
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'blue');
hold off;
hold on
%Blackman Window
n=0:1:N-1;
wh=0.42-0.5*cos((2*pi*n)/(N-1))+0.08*cos((4*pi*n)/(N-1));
hn=hd.*wh
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'green');
hold off;
Output:
enter the value of cut off frequency2
enter the order of filter10
hn =
Columns 1 through 6
0.0293 0.0596 -0.1222 0.0304 0.5361 0.5353
Columns 7 through 10
0.0295 -0.1220 0.0599 0.0290
hn =
Columns 1 through 6
0.0023 0.0112 -0.0562 0.0234 0.5212 0.5205
Columns 7 through 10
0.0227 -0.0561 0.0112 0.0023
hn =
Columns 1 through 5
0 0.0070 -0.0505 0.0228 0.5199
Columns 6 through 10
0.5192 0.0221 -0.0504 0.0070 0
hn =
Columns 1 through 5
-0.0000 0.0030 -0.0315 0.0191 0.5099
Columns 6 through 10
0.5092 0.0186 -0.0315 0.0030 -0.0000
1.4
1.2
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
%Blackman Window
n=0:1:N-1;
wh=0.42-0.5*cos((2*pi*n)/(N-1))-0.08*cos((4*pi*n)/(N-1));
hn=hd.*wh
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'green');
hold off;
OUTPUT:
enter the value of cut off frequency2
enter the value of filter15
hn =
Columns 1 through 6
-0.0449 0.0284 0.0347 -0.0790 0.0302 0.1198
Columns 7 through 12
-0.2890 0.3634 -0.2899 0.1211 0.0291 -0.0784
Columns 13 through 15
0.0345 0.0285 -0.0452
hn =
Columns 1 through 6
-0.0036 0.0036 0.0088 -0.0346 0.0194 0.0991
Columns 7 through 12
-0.2758 0.3634 -0.2767 0.1001 0.0187 -0.0343
Columns 13 through 15
0.0087 0.0036 -0.0036
hn =
Columns 1 through 5
0 0.0014 0.0065 -0.0307 0.0185
Columns 6 through 10
0.0972 -0.2747 0.3634 -0.2755 0.0983
Columns 11 through 15
0.0178 -0.0305 0.0065 0.0014 0
hn =
Columns 1 through 5
0.0072 -0.0023 0.0044 -0.0301 0.0182
Columns 6 through 10
0.0898 -0.2371 0.3052 -0.2379 0.0908
Columns 11 through 15
0.0176 -0.0299 0.0044 -0.0023 0.0072
1.4
1.2
0.8
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
hn=hd.*Wn
W=0:0.01:pi;
h=freqz(hn,1,W);
plot(W/pi,abs(h),'red');
hold off;
%Blackman Window
n=0:1:N-1;
wh=042-0.5*cos((2*pi*n)/(N-1))-0.08*cos((4*pi*n)/(N-1));
hn=hd.*wh
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(W/pi,abs(h),'green');
hold off;
Output:
enter the value of Wc1=1
enter the value of Wc2=1.5
enter the value of N=12
hn =
Columns 1 through 6
-0.0816 -0.1194 0.0322 0.1668 0.0624 -0.1479
Columns 7 through 12
-0.1420 0.0609 0.1656 0.0326 -0.1189 -0.0819
hn =
Columns 1 through 6
-0.0065 -0.0183 0.0112 0.1010 0.0525 -0.1452
Columns 7 through 12
-0.1393 0.0512 0.1003 0.0114 -0.0182 -0.0066
hn =
Columns 1 through 6
0 -0.0095 0.0094 0.0953 0.0516 -0.1449
Columns 7 through 12
-0.1391 0.0504 0.0946 0.0095 -0.0094 0
hn =
Columns 1 through 5
-3.3807 -4.9610 1.3473 7.0313 2.6401
Columns 6 through 10
-6.2735 -6.0216 2.5781 6.9813 1.3647
Columns 11 through 12
-4.9405 -3.3920
40
35
30
25
20
15
10
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
subplot(212)
Fs=fft(s,512); AFs=abs(Fs);%transform to the frequency domain
f=(0:255)*fs/512;%frequency sampling
plot(f,AFs(1:256));%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain diagram before
filtering');
figure(3)
sf=filter(h,1,s);%use function filter
subplot(211)
plot(t,sf)%plot the diagram after filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram after filtering')
axis([0.2 0.25 -2 2]);%set the range of image coordinates
subplot(212)
Fsf=fft(sf,512); AFsf=abs(Fsf);%frequency-domain and the amplitude diagram
f=(0:255)*fs/512;%frequency sampling
plot(f,AFsf(1:256))%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain diagram after
filtering');
1
amplitude
-1
-2
0 0.05 0.1 0.15 0.2 0.25
time/s
Frequency-domain diagram before filtering
300
200
amplitude
100
0
0 100 200 300 400 500 600 700 800 900 1000
frequency/Hz
1
amplitude
-1
-2
0.2 0.205 0.21 0.215 0.22 0.225 0.23 0.235 0.24 0.245 0.25
time/s
Frequency-domain diagram after filtering
300
200
amplitude
100
0
0 100 200 300 400 500 600 700 800 900 1000
frequency/Hz
-5
-10
-15
-20
gian/dB
-25
-30
-35
-40
-45
-50
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
the normailzed frequency
2
amplitude
-2
-4
0 0.05 0.1 0.15 0.2 0.25
time/s
Frequency-domain diagram before filtering
300
200
amplitude
100
0
0 100 200 300 400 500 600 700 800 900 1000
frequency/Hz
1
amplitude
-1
-2
0.2 0.205 0.21 0.215 0.22 0.225 0.23 0.235 0.24 0.245 0.25
time/s
Frequency-domain diagram after filtering
300
200
amplitude
100
0
0 100 200 300 400 500 600 700 800 900 1000
frequency/Hz
Output:
enter the input sequence=[1 1 2 2]
enter the numerator polynomials=[1 2 3 4 ]
enter the denominator polynomials=[4 3 2 1 ]
type of realization=1
ans = 1 0 5 -3
Advantages
FIR IIR
Stable
Highly precise cost lesser
Finite duration impulse response Faster computations
Excellent phase response Less hardware, computations
The word-size effect such as round- Easier to design
off noise and coefficient Lower order required
quantization errors are much less
severe in FIR.
Disadvantages
FIR IIR
Require higher order Sensitive to data
Increased hardware round off and cutoff
More computations Make become
Larger input and unstable
output delays Poor phase response
Cost more
Raw Refined
Collector Processor
Data Data
Signal
33. What is meant by real time processing?
Ability to collect, analyze, and modify signals in real-time
Real-Time: As these signals are occurring
We can analyze and process signals while collecting them, not at a later time.
Real-Time
Signal Refined
Processor Data
Signal
36. Differentiate between General purpose MPU(Micro Processor Unit) and DSP Processor
MPU are built for a range of general-purpose functions such as:
Data manipulation
Math calculations
Control systems
They run large blocks of software
They are used in real-time and in unreal-time systems
DSPs are single-minded, dedicated to:
Perform mathematical calculations
Small blocks of software
Have a predictable execution time
Real-time only
Could assist a general-purpose host MPU
Microprocessor DSP
General purpose Arithmetic
Fixed internal format Varying internal format
Single memory access Multiple memory access
General addressing mode Special addressing mode
Very large external memory Very large internal memory
Pipeline
Description
Stage
Generate program fetch address
PF
Read opcode
Route opcode to functional unit
D
Decode instruction
E Execute instruction
i. cheaper
ii. smaller
iii. less power consuming
iv. Harder to program
References
Digital Signal Processing – Principles, Jhon G. Proakis 4th Edition,
Pearson
Algorithms, and Applications Dimitris G. Manolakis 2007.
st
1 Edition,
Digital Signal Processing Sanjith K Mitra McGraw Hill
2005
nd
2 Edition,
Digital Signal Processing A.NagoorKani McGraw Hill
2012
nd
2 Edition,
Digital Signal Processing Shaila D. Apte Wiley
2009
st
1 Edition,
Digital Signal Processing Ashok Amberdar Cengage
2007
st
1 Edition,
Digital Signal Processing Tarun Kumar Rawat Oxford
2015