george sebastian 12400026
TRANSCRIPT
-
8/17/2019 George Sebastian 12400026
1/122
COLLEGE OF ENGINEERING
THIRUVANANTHAPURAM
DIGITAL SIGNAL PROCESSING
LABORATORY RECORD
YEAR 2014
GEORGE SEBASTIAN
Uni.Reg.no. 12400026
COLLEGE OF ENGINEERING
THIRUVANANTHAPURAM
-
8/17/2019 George Sebastian 12400026
2/122
Date:
1
DIGITAL SIGNAL PROCESSING
LABORATORY RECORD
YEAR 2014
Uni.Reg.No 12400026
Name GEORGE SEBASTIAN
Roll no 27 Batch S5
Class EC from Page No 1 to Page No 120
Certified Bonafide Record of work done
by……………………………………………………
Thiruvananthapuram
Date Faculty-in-charge
-
8/17/2019 George Sebastian 12400026
3/122
Date:
2
CONTENTS
1. Mathematical Operations on signal 4
1.1
Time Shifting Operation 5
1.2
Time Scaling Operation 8
1.3
Amplitude Scaling 11
1.4
Addition 14
1.5
Multiplication 18
1.6
Convolution with built in function 21
1.7 Convolution without built-in function 24
2. Random Sequence Generation 29
2.1 Uniform distribution 29
2.2 Gaussian distribution 30
2.3 Rayleigh distribution
3. Convolution 34
3.1 Linear Convolution 35
3.2 Circular Convolution 37
3.3 Linear Convolution via circular convolution 39
4. Modulation 42
4.1 Amplitude Modulation 42
4.2 Frequency Modulation 44
4.3 Pulse Width Modulation 45
5. Discrete Fourier Transform 48
5.1 Finding N point DFT and IDFT 48
5.2 Magnitude and Phase plots 50
5.3 Spectral Analysis of signals 53
6. Convolution using DFT 60
6.1 Circular convolution using DFT 60
6.2 Linear convolution using DFT 62
-
8/17/2019 George Sebastian 12400026
4/122
Date:
3
7. Convolution using Overlap-save method 64
8. Convolution using Overlap-add method 68
9. IIR filters 72
9.1 Butterworth low pass filter 72
9.2 Butterworth high pass filter 74
9.3 Butterworth band pass filter 76
9.4 Butterworth band stop filter 77
9.5Chebyshev I low pass filter 80
9.6 Chebyshev I high pass filter 82
9.7 Chebyshev I band pass filter 83
9.8 Chebyshev I band stop filter 85
10. FIR filter design 87
10.1 Filter using hamming window 89
10.2 Filter using hanning window 90
10.3 filter using frequency sampling method 91
11. Sampling rate conversion by rational factor 94
12. Optimal Equiripple Design technique for FIR filters 97
12.1 FIR low pass filter
13. Introduction to DSP development system 103
14. Programs using Code Composer Studio 115
14.1 Sine wave generation 115
14.2 FIR filtering 117
14.3 IIR filtering 119
-
8/17/2019 George Sebastian 12400026
5/122
Date:
4
EXPERIMENT NO:1
MATHEMATICAL OPERATIONS ON SIGNALS
AIM:
To perform the basic mathematical operations on discrete and continuous signals
(a) time shifting
(b) time scaling
(c) amplitude scaling
(d) addition
(e) multiplication
(f) convolution (with and without using built-in function)
THEORY:
The basic mathematical operations that can be performed on signals are time shifting,
time scaling, amplitude scaling, addition, multiplication and convolution.
Time shif ting: Let x(t) denote a continuous-time signal. Then the signal y(t) obtained by
shifting the independent variable, time t, by a factor a is defined by
y(t) = x(t-a)
In discrete-time case, y[n] = x[n-k]
Time scal ing: Let x(t) denote a continuous-time signal. Then the signal y(t) obtained by
scaling the independent variable, time t, by a factor a is defined by
y(t) = x(at)
In discrete-time case, y[n] = x[kn]
Ampl itude scaling: Let x(t) denote a continuous-time signal. Then the signal y(t) resulting
from amplitude scaling applied to x(t) is defined by
y(t) = cx(t), where c is the scaling factor.
In a similar manner, for discrete-time signals, y[n] = cx[n]
Addition : The signal y(t) obtained by the addition of x1(t) and x2(t) is defined by
y(t) = x1(t) + x2(t)
-
8/17/2019 George Sebastian 12400026
6/122
Date:
5
For discrete-time signals, y[n] = x1[n] + x2[n]
Multiplication: The signal y(t) resulting from the multiplication of x1(t) and x2(t) is defined
by
y(t) = x1(t) x2(t)
For discrete-time signals, y[n] = x1[n] x2[n]
Convolution : Let x(t) be the input signal and h(t) be the impulse response. Then the output
signal y(t) is obtained by the convolution of x(t) and h(t).That is
y(t) =x(t) * h(t)
In discrete-time case, y[n] = x[n] * h[n].
The “conv” function is approximating the convolution integral by a summation. The data inthe 2 arrays x(t) and h(t) are samples of the continuous time signals with samples separated
by dt seconds. When the conv function is used with arrays x(t) and h(t) , the result is an array
of 2n-1 elements with data spacing of dt seconds. The first n elements correspond to the
correct output values over the same time interval for which the input signal and impulse
response have stored values. The remaining n-1 elements are computed based on the
assumption that both x(t) and h(t) are equal to 0 for all other time other than what was
represented by the arrays x(t) and h(t).
MATLAB Code:
PROGRAM 1.1
%TIME SHIFTING OPERATION
% Discrete Sequence-Time Shifting clcclose all clear all x=input('Enter the input sequence x[n] ');l=input('Enter the starting index ');a=input('Enter the shift value x[n-a] ');n=length(x);t=l:1:(n+l-1);subplot(2,1,1)
stem(t,x)xlabel('Time index')
-
8/17/2019 George Sebastian 12400026
7/122
Date:
6
ylabel('Amplitude')title('Input Signal x[n]')axis([-10 10 -5 5])t=a+l:1:(n+a+l-1);subplot(2,1,2)
stem(t,x)xlabel('Time index')ylabel('Amplitude')title('Time Shifted Signal x[n-a]')axis([-10 10 -5 5])gtext('George Sebastian 12400026')
% Continous Sequence-Time Shifting clcclose all
clear all A=input('Enter the max amplitude ');f=input('Enter the frequency ');a=input('Enter the time shift value x[t-a] ');
t=-3:0.001:3;x=A*sin(2*pi*f*t);subplot(2,1,1)plot(t,x)axis([-5 5 -5 5])xlabel('Time index')
ylabel('Amplitude')title('Input Signal x(t)')t=-3+a:0.001:3+a;y=A*sin(2*pi*f*(t));subplot(2,1,2)plot(t,y)axis([-5 5 -5 5])xlabel('Time index')ylabel('Amplitude')title('Time Shifted Signal x[t-a]')gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Discrete samples:
Enter the input sequence x[n] [1 2 3 1]Enter the starting index -3Enter the shift value x[n-a] 2
-
8/17/2019 George Sebastian 12400026
8/122
Date:
7
Figure 1.1: Time shifting operation-discrete
Continuous Functions:
Enter the max amplitude 4
Enter the frequency 3Enter the time shift value x[t-a] 3
-
8/17/2019 George Sebastian 12400026
9/122
Date:
8
Figure 1.1: Time shifting operation-continuous
PROGRAM 1.2:
%TIME SCALING OPERATION
%Discrete sequence
clcclose all
clear all x=input('Enter the input sequence x[n] ');l=input('Enter the starting index ');a=input('Enter the scale value x[an] ');n=length(x);t=l:1:(n+l-1);subplot(2,1,1)stem(t,x)m=1s=(l/a):1:((n+l-1)/a)
axis([-5 5 -5 5])
-
8/17/2019 George Sebastian 12400026
10/122
Date:
9
xlabel('Time index')ylabel('Amplitude')title('Input Signal x[n]')
for k=(l/a):1:((n+l-1)/a)y(m)=x((m*a)-(a-1))m=m+1;
end subplot(2,1,2)stem(s,y)axis([-5 5 -5 5])
xlabel('Time index')ylabel('Amplitude')title('Time Scaled Signal x[an]')gtext('George Sebastian 12400026')
%Continuous signal
clcclose all clear all A=input('Enter the max amplitude ');f=input('Enter the frequency ');
a=input('Enter the time scale value x(at) ');
t=-3:0.001:3;x=A*sin(2*pi*f*t);subplot(2,1,1)plot(t,x)axis([-5 5 -5 5])xlabel('Time index')ylabel('Amplitude')title('Input Signal x(t)')
y=A*sin(2*pi*f*a*(t));
subplot(2,1,2)plot(t,y)axis([-5 5 -5 5])
xlabel('Time index')ylabel('Amplitude')title('Time Scaled Signal x(at)')gtext('George Sebastian 12400026')
-
8/17/2019 George Sebastian 12400026
11/122
Date:
10
SAMPLE OUTPUT
DISCRETE SEQUENCE
Enter the input sequence x[n] [1 2 3 4 3 2 1 0 1]
Enter the starting index -3Enter the scale value x[an] 3
Figure 1.2: Time scaling operation-discrete
CONTINUOUS SIGNAL
Enter the max amplitude 5Enter the frequency 1Enter the time scale value x(at) 3
-
8/17/2019 George Sebastian 12400026
12/122
-
8/17/2019 George Sebastian 12400026
13/122
Date:
12
stem(t,y)axis([-5 5 -5 5])
xlabel('Time index')ylabel('Amplitude')title('Amplitude Scaled Signal ax[n]')
gtext('George Sebastian 12400026’)
% Continous Sequence-Amplitude Scaling clcclose all clear all A=input('Enter the max amplitude ');f=input('Enter the frequency ');a=input('Enter the amplitude scale ax[t] ');t=-3:0.001:3;x=A*sin(2*pi*f*t);
subplot(2,1,1)plot(t,x)axis([-5 5 -5 5])xlabel('Time index')ylabel('Amplitude')title('Input Signal x(t)')t=-3:0.001:3;y=a*A*sin(2*pi*f*(t));subplot(2,1,2)plot(t,y)axis([-5 5 -5 5])
xlabel('Time index')ylabel('Amplitude')title('Amplitude Scaled Signal x[t-a]')gtext('George Sebastian 12400026')
SAMPLE OUTPUT
DISCRETE SEQUENCE
Enter the input sequence x[n] [1 2 3 4 3 2 1]Enter the starting index -2Enter the amplitude scale value ax[n] 0.5
-
8/17/2019 George Sebastian 12400026
14/122
Date:
13
Figure 1.3: Amplitude scaling operation-discrete
CONTINUOUS SIGNAL
Enter the max amplitude 2Enter the frequency 2Enter the amplitude scale ax[t] 1.5
-
8/17/2019 George Sebastian 12400026
15/122
Date:
14
Figure 1.3: Amplitude scaling operation-continuous
PROGRAM 1.4:
%ADDITION OF SIGNALS
%Discrete Signal Addition clcclear all close all x=input('Enter the first signal x[n] ');lx=input('Enter its starting index ');
y=input('Enter the second signal y[n] ');ly=input('Enter its starting index ');mx=length(x);my=length(y);tx=lx:lx+mx-1;subplot(3,1,1)stem(tx,x)title('First signal x[n]')xlabel('Time index')ylabel('Amplitude')axis([-5 5 -5 5])
ty=ly:ly+my-1;subplot(3,1,2)
-
8/17/2019 George Sebastian 12400026
16/122
Date:
15
stem(ty,y)title('Second signal x[n]')xlabel('Time index')ylabel('Amplitude')axis([-5 5 -7 7])
p=abs(lx-ly);if(lx>ly)
t1=ly;x=[zeros(1,p) x];
else t1=lx;y=[zeros(1,p) y];
end mx1=length(x);my1=length(y);q=abs(mx1-my1);
if(mx1>my1)y=[y zeros(1,q)];
else x=[x zeros(1,q)];
end z=x+y;t2=length(z);tz=t1:t1+t2-1;subplot(3,1,3)stem(tz,z)title('Sum signal z[n]=x[n]+y[n]')
xlabel('Time index')ylabel('Amplitude')axis([-5 5 -7 7])gtext('George Sebastian 12400026')
%Continous signal addition clcclear all
close all t=-1:0.01:1;A1=input('Enter the amplitude of the first sinusoidal wavex(t) ');f1=input('Enter the frequency of the first sinusoidal wavex(t) ');x=A1*sin(2*pi*f1*t);A2=input('Enter the amplitude of the second sinusoidal wavey(t) ');f2=input('Enter the frequency of the second sinusoidal wavey(t) ');
y=A2*sin(2*pi*f2*t);subplot(3,1,1)
-
8/17/2019 George Sebastian 12400026
17/122
Date:
16
plot(t,x)title('First signal x(t) ')xlabel('Time index')ylabel('Amplitude')subplot(3,1,2)
plot(t,y)title('Second signal y(t) ')xlabel('Time index')ylabel('Amplitude')axis([-2 2 -5 5])z=x+y;subplot(3,1,3)plot(t,z)title('Sum signal z(t)=x(t)+y(t)')xlabel('Time index')ylabel('Amplitude')
gtext('George Sebastian 12400026')
SAMPLE OUTPUT
DISCRETE SEQUENCE
Enter the first signal x[n] [1 2 3 4 3 2 0]Enter its starting index -3
Enter the second signal y[n] [1 0 1 0 2 0]Enter its starting index -2
-
8/17/2019 George Sebastian 12400026
18/122
Date:
17
Figure 1.4: Addition of signals-discrete
CONTINUOUS SIGNAL
Enter the amplitude of the first sinusoidal wave x(t) 2Enter the frequency of the first sinusoidal wave x(t) 2Enter the amplitude of the second sinusoidal wave y(t) 2Enter the frequency of the second sinusoidal wave y(t) 1
-
8/17/2019 George Sebastian 12400026
19/122
Date:
18
Figure 1.4: Addition of signals-continuous
PROGRAM 1.5:
% MULTIPLICATION OF SIGNALS
%Discrete Signal Multiplication clcclear all close all x=input('Enter the first signal x[n] ');lx=input('Enter its starting index ');
y=input('Enter the second signal y[n] ');ly=input('Enter its starting index ');mx=length(x);my=length(y);tx=lx:lx+mx-1;subplot(3,1,1)stem(tx,x)title('First signal x[n]')xlabel('Time index')ylabel('Amplitude')axis([-5 5 -10 10])
ty=ly:ly+my-1;subplot(3,1,2)
-
8/17/2019 George Sebastian 12400026
20/122
Date:
19
stem(ty,y)title('Second signal x[n]')xlabel('Time index')ylabel('Amplitude')
p=abs(lx-ly);if(lx>ly)
t1=ly;x=[zeros(1,p) x];
else t1=lx;y=[zeros(1,p) y];
end mx1=length(x);my1=length(y);q=abs(mx1-my1);
if(mx1>my1)y=[y zeros(1,q)];
else x=[x zeros(1,q)];
end z=x.*y;t2=length(z);tz=t1:t1+t2-1;subplot(3,1,3)stem(tz,z)title('Product signal z[n]=x[n].*y[n]')
xlabel('Time index')ylabel('Amplitude')
gtext('George Sebastian 12400026')
%Continous signal multiplication clcclear all close all t=-1:0.01:1;
A1=input('Enter the amplitude of the first sinusoidal wavex(t) ');f1=input('Enter the frequency of the first sinusoidal wavex(t) ');x=A1*sin(2*pi*f1*t);A2=input('Enter the amplitude of the second square wave y(t)');f2=input('Enter the frequency of the second square wave y(t)');d=input('Enter the duty cycle of the second square wave y(t)');
y=A2*square(2*pi*f2*t,d*100);subplot(3,1,1)
-
8/17/2019 George Sebastian 12400026
21/122
Date:
20
plot(t,x)title('First signal x(t) ')xlabel('Time index')ylabel('Amplitude')subplot(3,1,2)
plot(t,y)title('Second signal y(t) ')xlabel('Time index')ylabel('Amplitude')
z=x.*y;subplot(3,1,3)plot(t,z)title('Product signal z(t)=x(t).*y(t)')xlabel('Time index')ylabel('Amplitude')
gtext('George Sebastian 12400026')
SAMPLE OUTPUT
DISCRETE SEQUENCE
Enter the first signal x[n] [4 2 3 0 5 2 6]Enter its starting index -1Enter the second signal y[n] [4 5 3 5 1 3 ]Enter its starting index -4
Figure 1.5: Multiplication of signals-discrete
-
8/17/2019 George Sebastian 12400026
22/122
Date:
21
CONTINUOUS SIGNAL
Enter the amplitude of the first sinusoidal wave x(t) 4
Enter the frequency of the first sinusoidal wave x(t) 2Enter the amplitude of the second square wave y(t) 2Enter the frequency of the second square wave y(t) 2Enter the duty cycle of the second square wave y(t) 0.5
Figure 1.5: Multiplication of signals-continuous
PROGRAM 1.6.1:
%Discrete Signal Convolution using built in function clcclear all close all x=input('Enter the input sequence x[n] ');lx=input('Enter its starting index ');h=input('Enter the impulse response h[n] ');lh=input('Enter its starting index ');mx=length(x);t=lx:lx+mx-1;
subplot(3,1,1)stem(t,x)
-
8/17/2019 George Sebastian 12400026
23/122
Date:
22
title('Input sequence x[n]')xlabel('Time index')ylabel('Amplitude')
mh=length(h);
t=lh:lh+mh-1;subplot(3,1,2)stem(t,h)title('Impulse Response h[n]')xlabel('Time index')ylabel('Amplitude')
z=conv(x,h);m=length(z);t=lx+lh:lx+lh+m-1;subplot(3,1,3)
stem(t,z)title('Convoluted sequence z[n]=x[n]*h[n]')xlabel('Time index')ylabel('Amplitude')gtext('George Sebastian 12400026')
%Continuous signal clc;clear;tx=-1:0.001:1;x=2*rectpuls(tx,2);
subplot(311);plot(tx,x,'k-','LineWidth',1.5);title('First signal x(t)');xlabel('Time index');ylabel('Amplitude');axis([-4 4 -5 5]);ty=-2:0.001:2;y=2*sawtooth(2*pi*0.25*ty+pi);subplot(312);plot(ty,y,'k-','LineWidth',1.5);title('Second signal y(t)');
xlabel('Time index');ylabel('Amplitude');axis([-4 4 -5 5]);t=-3:0.001:3;z=0.001*conv(x,y);subplot(313);plot(t,z,'r-','LineWidth',1.5);title('Linear convolution output y(t)=x(t)*h(t)');xlabel('Time index');ylabel('Amplitude');axis([-4 4 -5 5]);
gtext('George Sebastian 12400026')
-
8/17/2019 George Sebastian 12400026
24/122
Date:
23
SAMPLE OUTPUT
DISCRETE SEQUENCE
Enter the input sequence x[n] [1 2 3 4 1 0 1]Enter its starting index -2Enter the impulse response h[n] [1 1 1]Enter its starting index -2
Figure 1.6.1: Convolution of signals using built-in functions-discrete
-
8/17/2019 George Sebastian 12400026
25/122
Date:
24
CONTINUOUS SIGNAL
Figure 1.6.2: Convolution of signals using built-in functions – continuous
PROGRAM 1.6.2:
%Discrete Signal Convolution without using built in function clcclear all close all x=input('Enter the input sequence x[n] ');lx=input('Enter its starting index ');
h=input('Enter the impulse response h[n] ');lh=input('Enter its starting index ');mx=length(x);t=lx:lx+mx-1;subplot(3,1,1)stem(t,x)title('Input sequence x[n]')xlabel('Time index')ylabel('Amplitude')axis([-5 5 -5 5])mh=length(h);
t=lh:lh+mh-1;subplot(3,1,2)
-
8/17/2019 George Sebastian 12400026
26/122
Date:
25
stem(t,h)title('Impulse Response h[n]')xlabel('Time index')ylabel('Amplitude')
X=[x zeros(1,mh)];H=[h zeros(1,mx)];for i=1:mx+mh-1
y(i)=0;for j=1:mxfor k=1:mhif(j+k)==(i+1)
y(i)=y(i)+X(j).*H(k);end end end
end m=length(y);t=lx+lh:lx+lh+m-1;subplot(3,1,3)stem(t,y)title('Convoluted Response y[n]=x[n]*h[n]')xlabel('Time index')ylabel('Amplitude')gtext('George Sebastian 12400026')
%Continuous Convolution Without using built in function clcclear all close all l=input('Enter the width of the triangular pulse ');A=input('Enter the amplitude of the triangular pulse ');h=input('Enter the impulse response h(t) ');lh=input('Enter its starting index ');mh=length(h);t=lh:lh+mh-1;tx=-2:0.01:2;
x=A*tripuls(tx,l);subplot(3,1,1)plot(tx,x)title('Input signal x(t)')xlabel('Time index')ylabel('Amplitude')subplot(3,1,2)stem(t,h)title('Impulse Response h(t)')xlabel('Time index')ylabel('Amplitude')
X=[x zeros(1,mh)];H=[h zeros(1,l)];
-
8/17/2019 George Sebastian 12400026
27/122
Date:
26
for i=1:l+mhy(i)=0;for j=1:l
for k=1:mhif(j+k)==(i+1)
y(i)=y(i)+X(j).*H(k);end
end end
end t=(-l/2)+lh:(l/2)+lh+mh-1;subplot(3,1,3)plot(t,y)title('Convoluted signal y(t)=x(t)*h(t)')xlabel('Time index')ylabel('Amplitude')
gtext('George Sebastian 12400026')
SAMPLE OUTPUT
DISCRETE SEQUENCE
Enter the input sequence x[n] [1 2 3 4 0 2 1]
Enter its starting index -3
Enter the impulse response h[n] [1 1 1]
Enter its starting index -2
-
8/17/2019 George Sebastian 12400026
28/122
Date:
27
Convolution of signals without using built-in functions-discrete
CONTINUOUS SIGNAL
Enter the width of the triangular pulse 4Enter the amplitude of the triangular pulse 5Enter the impulse response h(t) [2 0 0 0 1]Enter its starting index -2
-
8/17/2019 George Sebastian 12400026
29/122
Date:
28
Convolution of signals without using built-in functions – continuous
RESULT:
The basic operations on continuous and discrete-time signals have been performed.
-
8/17/2019 George Sebastian 12400026
30/122
Date:
29
EXPERIMENT NO: 2
RANDOM SEQUENCE GENERATION
AIM:To generate uniformly distributed, Gaussian distributed and Rayleigh distributed random
number sequences and to plot their histograms.
THEORY:
Uniform distribution:
Uniform deviates are just random numbers that lie within a specified range. Other
deviates are almost always generated by performing appropriate operations on one or more of
uniform deviates.
The probability density function of a random variable X, uniformly distributed in (a,b)
is given by
f X(x) = 1/(b-a), a ≤ x ≤ b
= 0, otherwise
MATLAB Code:
PROGRAM 2.1:
%Random Signal Generation using random functions %Uniform Distribution clc;clear;a= input('Enter the value of a in interval [a,b] ');b= input('Enter the value of b in interval [a,b] ');
x= rand(1,100000);y = a + (b-a).*x;subplot(211);plot(y);xlabel('Index');ylabel('Amplitude');title('Uniform Random Signal');subplot(212);hist(y,10);xlabel('Values');ylabel('Frequency');title('Histogram');axis([0 8 0 12000]);
-
8/17/2019 George Sebastian 12400026
31/122
Date:
30
gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the value of a in interval [a,b] 2Enter the value of b in interval [a,b] 6
Figure 2.1: Uniform distribution
Gaussian distribution:
In probability theory, the normal (or Gaussian) distribution is a continuous probability
distribution that has a bell-shaped probability density function, known as the Gaussianfunction or informally as the bell curve.
The parameter μ is the mean or expectation (location of the peak) and σ 2 is the variance. σ isknown as the standard deviation. The distribution with μ = 0 and σ 2 = 1 is called the standardnormal distribution or the unit normal distribution. A normal distribution is often used as a
first approximation to describe real-valued random variables that cluster around a single
mean value.
http://en.wikipedia.org/wiki/Probability_theoryhttp://en.wikipedia.org/wiki/Continuous_probability_distributionhttp://en.wikipedia.org/wiki/Continuous_probability_distributionhttp://en.wikipedia.org/wiki/Probability_density_functionhttp://en.wikipedia.org/wiki/Gaussian_functionhttp://en.wikipedia.org/wiki/Gaussian_functionhttp://en.wikipedia.org/wiki/Meanhttp://en.wikipedia.org/wiki/Expected_valuehttp://en.wikipedia.org/wiki/Variancehttp://en.wikipedia.org/wiki/Standard_deviationhttp://en.wikipedia.org/wiki/Random_variablehttp://en.wikipedia.org/wiki/Random_variablehttp://en.wikipedia.org/wiki/Standard_deviationhttp://en.wikipedia.org/wiki/Variancehttp://en.wikipedia.org/wiki/Expected_valuehttp://en.wikipedia.org/wiki/Meanhttp://en.wikipedia.org/wiki/Gaussian_functionhttp://en.wikipedia.org/wiki/Gaussian_functionhttp://en.wikipedia.org/wiki/Probability_density_functionhttp://en.wikipedia.org/wiki/Continuous_probability_distributionhttp://en.wikipedia.org/wiki/Continuous_probability_distributionhttp://en.wikipedia.org/wiki/Probability_theory
-
8/17/2019 George Sebastian 12400026
32/122
Date:
31
PROGRAM 2.2:
%Gaussian Distribution clc;clear;
mu= input('Enter the mean: ');sd= input('Enter the standard deviation: ');x= randn(1,100000);y= mu + sd*x;subplot(211);plot(y);xlabel('Index');ylabel('Amplitude');title('Gaussian Random Signal');subplot(212);histfit(y,500);
xlabel('Values');ylabel('Frequency');title('Histogram');gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the mean: 7Enter the standard deviation: 1
Figure 2.2: Gaussian distribution
-
8/17/2019 George Sebastian 12400026
33/122
Date:
32
Rayleigh distribution:
In probability theory and statistics, the Rayleigh distribution is a continuous
probability distribution. A Rayleigh distribution is often observed when the overallmagnitude of a vector is related to its directional components. An example of the distribution
arises in the case of random complex numbers whose real and imaginary components are
i.i.d. (independently and identically distributed) Gaussian. In that case, the absolute value of
the complex number is Rayleigh-distributed. The distribution is named after Lord Rayleigh.
The Rayleigh probability density function is
for parameter and cumulative distribution function
for
PROGRAM 2.3:
%Rayleigh Distribution clc;
clear;b=input('Enter the value of the parameter "b"');x=random('rayl',b,1,100000);subplot(211);plot(x);xlabel('Index');ylabel('Amplitude');title('Rayleigh Random Signal');subplot(212);histfit(x,50,'rayleigh');xlabel('Values');
ylabel('Frequency');title('Histogram');gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the value of the parameter "b"8
http://en.wikipedia.org/wiki/Probability_theoryhttp://en.wikipedia.org/wiki/Statisticshttp://en.wikipedia.org/wiki/Continuous_probability_distributionhttp://en.wikipedia.org/wiki/Continuous_probability_distributionhttp://en.wikipedia.org/wiki/Euclidean_vector#Vector_componentshttp://en.wikipedia.org/wiki/Normal_distributionhttp://en.wikipedia.org/wiki/John_Strutt,_3rd_Baron_Rayleighhttp://en.wikipedia.org/wiki/Probability_density_functionhttp://en.wikipedia.org/wiki/Cumulative_distribution_functionhttp://en.wikipedia.org/wiki/Cumulative_distribution_functionhttp://en.wikipedia.org/wiki/Probability_density_functionhttp://en.wikipedia.org/wiki/John_Strutt,_3rd_Baron_Rayleighhttp://en.wikipedia.org/wiki/Normal_distributionhttp://en.wikipedia.org/wiki/Euclidean_vector#Vector_componentshttp://en.wikipedia.org/wiki/Continuous_probability_distributionhttp://en.wikipedia.org/wiki/Continuous_probability_distributionhttp://en.wikipedia.org/wiki/Statisticshttp://en.wikipedia.org/wiki/Probability_theory
-
8/17/2019 George Sebastian 12400026
34/122
Date:
33
Figure 2.3: Rayleigh distribution
RESULT:
Uniformly distributed, Gaussian distributed and Rayleigh distributed random number
sequences have been generated and verified by plotting their histograms.
-
8/17/2019 George Sebastian 12400026
35/122
-
8/17/2019 George Sebastian 12400026
36/122
Date:
35
Algorithm
X2(1) . . X2(M)
X1(1) X1(1)*x2(1) . . X1(1)*X2(M)
. . . . .
. . . . .
X1(N) X1(N)*X2(1) . . X1(N)*X2(M)
Take the sum of elements in each diagonal as shown by shaded cells, from left most
column to right. This gives the output sequence elements in order.
MATLAB code
PROGRAM 3.1:
%Linear Convolution clcclear all close all a=input('Enter the first sequence ');b=input('Enter the second sequence ');ma=length(a);mb=length(b);subplot(3,1,1)stem(a)title('Input signal a[n]')xlabel('Time index')ylabel('Amplitude')subplot(3,1,2)stem(b)title('Input signal b[n]')xlabel('Time index')
ylabel('Amplitude')c=zeros(1,ma+mb-1);
-
8/17/2019 George Sebastian 12400026
37/122
Date:
36
for i=1:maj=i-1;k=ma-i;c=[zeros(1,j) b*a(i) zeros(1,k)]+c;
end
disp('Output Sequence ');csubplot(3,1,3)stem(c)title('Output signal c[n]')xlabel('Time index')ylabel('Amplitude')gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the first sequence [1 1 1 1]Enter the second sequence [1 0 2 3 1]Output Sequence
c =
1 1 3 6 6 6 4 1
Figure 3.1: Input and output sequences
-
8/17/2019 George Sebastian 12400026
38/122
Date:
37
3.2) Circular Convolution
The N-point circular convolution of two sequences x1(n) and x2(n) of length N is given
by
()(( ))
Circular convolution involves basically the same 4 steps as the ordinary linear convolution.
Folding (time reversing) of one sequence, shifting the folded sequence, multiplying the two
sequences to obtain a product sequence and finally summing the values of the product
sequence. The basic difference between these two types of convolution is that, in circular
convolution the folding and shifting operations are performed in a circular fashion by
computing the index of one of the sequences modulo N. In circular convolution there is no
modulo N operation. N is the max of length of the sequence
MATLAB code
PROGRAM 3.2:
%Circular Convolution clc
clear all close all a=input('Enter the first sequence ');b=input('Enter the second sequence ');ma=length(a);mb=length(b);subplot(3,1,1)stem(a)title('Input signal a[n]')xlabel('Time index')ylabel('Amplitude')
subplot(3,1,2)stem(b)title('Input signal b[n]')xlabel('Time index')ylabel('Amplitude')N=max(ma,mb);a=[a zeros(1,N-ma)];b=[b zeros(1,N-mb)];for i=1:N
c(i)=0;for j=1:N
k=mod(i-j,N);
-
8/17/2019 George Sebastian 12400026
39/122
Date:
38
c(i)=c(i)+a(j)*b(k+1);end end disp('Output Sequence ');csubplot(3,1,3)
stem(c)title('Output signal c[n]')xlabel('Time index')ylabel('Amplitude')gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the first sequence [1 2 2 1]Enter the second sequence [1 2 3 1]
Output Sequence
c =
11 9 10 12
Figure 3.2: Input and output sequences
-
8/17/2019 George Sebastian 12400026
40/122
Date:
39
3.3) Linear Convolution via Circular Convolution
If x1(n) is of length M and x2(n) is of length .Append (N-1) zeros to x1(n) and (M-1) zeros to
x2(n) to make their lengths equal. Then the M+N-1 point circular convolution is same as
their linear convolution. The method used for computation is same as that of circular
convolution above.
MATLAB code
PROGRAM 3.3:
%Linear Convolution via Circular Convolution clcclear all
close all a=input('Enter the first sequence ');b=input('Enter the second sequence ');ma=length(a);mb=length(b);subplot(3,1,1)stem(a)title('Input signal a[n]')xlabel('Time index')ylabel('Amplitude')subplot(3,1,2)
stem(b)title('Input signal b[n]')xlabel('Time index')ylabel('Amplitude')N=ma+mb-1;a=[a zeros(1,N-ma)];b=[b zeros(1,N-mb)];for i=1:N
c(i)=0;for j=1:N
k=mod(i-j,N);c(i)=c(i)+a(j)*b(k+1);
end end disp('Output Sequence ');csubplot(3,1,3)stem(c)title('Output signal c[n]')xlabel('Time index')ylabel('Amplitude')gtext('George Sebastian 12400026')
-
8/17/2019 George Sebastian 12400026
41/122
Date:
40
SAMPLE OUTPUT
Enter the first sequence [1 1 0 1]
Enter the second sequence [1 2 3 1 2]Output Sequence
c =
1 3 5 5 5 5 1 2
Figure 3.3: Input and output sequences
CONCLUSION :
(1)
The MATLAB code linconv is used for implementing linear convolution without
matlab function.
This program can be used to verify the different properties of convolution sum
(commutative, distributive and assosiative laws) and also for polynomial
multiplication (algebraically convolution is the same operation as multiplying the
-
8/17/2019 George Sebastian 12400026
42/122
Date:
41
polynomials whose coefficients are the elements x1 and x2). But this approach is not
very efficient in speed for very long sequences.
(2)
The MATLAB code cconv finds circular convolution by direct implementation of
equ. For circular convolution. It can be verified using the code that for two different
sequences, N-point, N+1 – point...convolutions are different. This direct
implementation is inefficient in terms of speed for large sequences.
(3) The MATLAB code lin_circ finds linear convolution by padding the required number
of zeros to both input sequences and then finding circular convolution by the direct
method.
RESULT :
Linear convolution, Circular convolution and computation of Linear convolution via Circular
convolution of two finite length sequences were implemented using MATLAB commands.
-
8/17/2019 George Sebastian 12400026
43/122
Date:
42
EXPERIMENT NO : 4
MODULATED WAVEFORMS
AIM:To generate AM, FM and PWM waveforms using MATLAB.
THEORY:
4.1 AMPLITUDE MODULATION
In the amplitude modulation (AM), the instantaneous amplitude of a carrier signal having
high frequency is varied by the instantaneous amplitude of a modulating voltage having lowfrequency. Let the modulating signal be em(t)=Emsin(wmt) and the carrier signal be
ec(t)=Ecsin(wct).Then the modulating signal e(t) is expressed as
e(t)=[ Ec+ Emsin(wmt)]sin(wct).= Ec [1+msin(wmt)]sin(wct),
where m=Em/Ec is known as the modulation index. Emax and E min are the maximum and
minimum amplitudes of the signal in the positive side.
MATLAB code
PROGRAM 4.1 :
%Amplitude Modulation clc;clear all close all t=0:0.001:1;set(0,'defaultlinelinewidth',2);Ac=input('Enter carrier amplitude ');fc=input('Enter carrier frequency ');fm=input('Enter message frequency ');m=input('Enter modulation index ');
s=Ac*m*sin(2*pi*fm*t);subplot(3,1,1)plot(t,s)xlabel('Time')ylabel('Amplitude')title('Message Signal')c=Ac*sin(2*pi*fc*t);subplot(3,1,2)plot(t,c)xlabel('Time')ylabel('Amplitude')
title('Carrier Signal')am=(Ac+s).*sin(2*pi*fc*t);
-
8/17/2019 George Sebastian 12400026
44/122
Date:
43
subplot(3,1,3)plot(t,am)xlabel('Time')ylabel('Amplitude')title('AM Signal')
gtext('George Sebastian 12400026');
. SAMPLE OUTPUT
Enter carrier amplitude 8Enter carrier frequency 25Enter message frequency 5Enter modulation index 0.5
Figure 4.1: Amplitude modulation
-
8/17/2019 George Sebastian 12400026
45/122
Date:
44
4.2 FREQUENCY MODULATION
In the frequency modulation (FM), the frequency of a carrier signal having high frequency is
varied by the instantaneous amplitude of a modulating voltage having low frequency. Let the
modulating signal be em(t)=Emsin(wmt) and the carrier signal be ec(t)=Ecsin(wct).Then the
modulating signal e(t) is expressed as
e(t)= Ec sin(wct+(m sin(wmt))),where m is known as the modulation index.
PROGRAM 4.2 :
%Frequency Modulation clc;clear all
close all t=0:0.0001:0.1;set(0,'defaultlinelinewidth',1);fm=input('Enter message frequency ');Ac=input('Enter carrier amplitude ');fc=input('Enter carrier frequency ');B=input('Enter the modulation index ');s=sin(2*pi*fm*t);subplot(3,1,1)plot(t,s)xlabel('Time')
ylabel('Amplitude')title('Message Signal')c=Ac*sin(2*pi*fc*t);subplot(3,1,2)plot(t,c)xlabel('Time')ylabel('Amplitude')title('Carrier Signal')fmod=Ac*sin((2*pi*fc*t)+(B*cos(2*pi*fm*t)));subplot(3,1,3)plot(t,fmod)
xlabel('Time')ylabel('Amplitude')title('FM Signal')gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter message frequency 10Enter carrier amplitude 6
Enter carrier frequency 200Enter the modulation index 10
-
8/17/2019 George Sebastian 12400026
46/122
-
8/17/2019 George Sebastian 12400026
47/122
Date:
46
PROGRAM 4.3 :
%Code for PWM wave clc;clear all;close all;F2=input('Enter the Message frequency = ');F1=input('Enter the Carrier Sawtooth frequency = ');A=5;t=0:0.001:1;c=A.*sawtooth(2*pi*F1*t);m=0.75*A.*sin(2*pi*F2*t);n=length(c);for i=1:nif (m(i)>=c(i))pwm(i)=1;
else pwm(i)=0;end end plot(t,pwm,'-k',t,m,'--r',t,c,'--b');title('PWM wave');axis([0 1 -5 5]);gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the Message frequency = 2Enter the Carrier Sawtooth frequency = 12
-
8/17/2019 George Sebastian 12400026
48/122
Date:
47
Figure 4.3: PWM waveform
RESULT
AM, FM and PWM waveforms are plotted in MATLAB.
-
8/17/2019 George Sebastian 12400026
49/122
Date:
48
EXPERIMENT NO : 5
DISCRETE FOURIER TRANSFORM (DFT)
AIM:
To implement the DFT and IDFT of input sequences and to plot and study the magnitude and
phase responses of common test signals.
5.1 Finding the N point DFT and IDFT
Let () be finite length sequence of length N, that is,()= 0 outside the range 0≤n≤N -1
The DFT of (), denoted as () is defined by () = ∑ ()
where is the Nth root of unity given by
( )
The inverse DFT (IDFT) is given by
()= ∑ ()
The MATLAB code to implement DFT and IDFT are as follows
PROGRAM 5.1.1
%Discrete Fourier Transform using matrix multiplication clcclear all close all x=input('Enter the input sequence ');N=input('Enter the length of DFT ');len=length(x);if(N>len)
x=[x zeros(1,(N-len))];else
x=x(1:N);end;W=exp(-j*2*pi/N);n=0:1:(N-1);k=0:1:(N-1);nk=n'*k;W=W.^nk;
X=x*W;display(X)
-
8/17/2019 George Sebastian 12400026
50/122
Date:
49
display('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the input sequence [1 0 0 1]Enter the length of DFT 4
X =
2.0000 1.0000 + 1.0000i 0 - 0.0000i1.0000 - 1.0000i
George Sebastian 12400026
PROGRAM 5.1.2:
%Inverse Discrete Fourier Transform using matrixmultiplication clcclear all close all x=input('Enter the DFT sequence ');N=input('Enter the length of DFT ');len=length(x);
if(N>len)x=[x zeros(1,(N-len))];else
x=x(1:N);end;W=exp(-j*2*pi/N);n=0:1:(N-1);k=0:1:(N-1);nk=n'*k;W=W.^(-nk);X=(x*W)/N;
display(X)display('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the DFT sequence [2 1+i 0 1-i]Enter the length of DFT 4
X =
1.0000 -0.0000 + 0.0000i 0.0000 + 0.0000i
1.0000 - 0.0000iGeorge Sebastian 12400026
-
8/17/2019 George Sebastian 12400026
51/122
Date:
50
5.2 MAGNITUDE AND PHASE PLOTS
AIM:
To find the magnitude and phase response of common test signals
THEORY:
The choice of N in this eqn is not fixed.
() = ∑ ()
If x(n) has length N1 < N , we want to assume that x(n) has length N by simply adding (N-
N1) samples with a value of 0.This addition of dummy samples is known as zero padding.
Then the resultant x(n) is often referred to as an N-point sequence, and X(k) defined in the
eqn(a) is referred to as an N- point DFT. By a judicious choice of N ,such as choosing it to be
a power of 2,computational efficiencies can be gained.
It is a common practice to represent the DFT by the plots of | X (k )| versus k Ω and of the
phase angle ϕ(k) versus k Ω. This may be done in terms of harmonics of Ω or in terms offrequency if Ω is known. To find Ω it is necessary to know the value of T, the sampling
interval. Then Ω = 2Π/NT rad s-1.
An important property of the DFT is that X (k+N)=X(k),i.e., the DFT is periodic with period
N . This is the cyclical property of the DFT.T he values of the DFT components are repetitive.
The amplitude spectrum of an N-point DFT is symmetrical about harmonic N/2 when both
the zero and (N+1)th harmonics are included in the plot. Similarly ,the phase function being
odd exhibits anti-symmetry about harmonic N/2.if 2f max samples per second are taken of the
signal for t seconds, then 2f max = N , so 1/t =2f max /N is the first harmonic frequency. The
symmetry at harmonic N/2 therefore occurs at the frequency (N/2)/(2f max /N) = f max , themaximum frequency present in the signal. In this context, f max is known as the folding
frequency, since the spectrum between harmonics N/2 and N may be folded about the axis of
symmetry at f max to superimpose exactly the low frequency half of the spectrum. It is now
seen that N real data values transform to N/2 complex DFT values of practical significance.
The latter consist of N/2 real values and N/2 imaginary values giving a total of N values
derived from the initial N real data values.
-
8/17/2019 George Sebastian 12400026
52/122
Date:
51
PROGRAM 5.1.3:
%Magnitude and phase response of a rect signalN = input('Enter the length of the sequence ');m = floor(N/8);
rect = [ones(1,m) zeros(1,N-m)];subplot(4,2,1:2),stem(rect);title('INPUT SIGNAL');xlabel('Time');ylabel('Amplitude');
%Finding DFT w = exp(-1i*2*pi/N);n = 0:1:(N-1);k = 0:1:(N-1);nk = n'*k;
W = w.^nk;X = rect*W;
%Magnitude and phase plots subplot(423),stem(k,abs(X(1:N)));title('MANITUDE PLOT');xlabel('Discrete frequency');ylabel('Amplitude');subplot(424),stem(k,angle(X(1:N)));title('PHASE PLOT');xlabel('Discrete frequency');
ylabel('Phase angle');
%Unfolding the spectrum y = X(floor(N/2)+1:N);Y = [y X(1:floor(N/2))];subplot(425),stem(k,abs(Y(1:N)));title('MAGNITUDE PLOT(UNFOLDED SPECTRUM)');xlabel('Discrete frequeny');ylabel('Amplitude');subplot(4,2,6),stem(k,angle(Y(1:N)));title('PHASE PLOT(UNFOLDED SPECTRUM');
xlabel('Discrete frequeny');ylabel('Phase angle');
%Labelling the frequency axis with normalised frequency values if rem(N,2) == 0
t = 2*pi/N;n = [-pi:t:(pi-t)];
else t = pi/N;n = [-pi+t:2*t:pi-t];
end
subplot(427);stem((n/pi),abs(Y(1:N)));
-
8/17/2019 George Sebastian 12400026
53/122
Date:
52
xlabel('Frequency(pi units)');ylabel('Amplitude');title('MAGNITUDE PLOT');subplot(428);stem((n/pi),angle(Y(1:N)));
xlabel('Frequency(pi units)');ylabel('Phase(radians)');title('PHASE PLOT');gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the length of the sequence 28
Figure 5.1:Magnitude and phase plots
-
8/17/2019 George Sebastian 12400026
54/122
Date:
53
5.3 SPECTRAL ANALYSIS OF SIGNALS
AIM:
To draw the spectrum of sinusoids, sum of sinusoids, AM wave and random signal.
FREQUENCY SPECTRUM USING DFT:
When harmonic components of a signal are known, the signal can be presented in a different
way that highlights its frequency content rather than its time domain content. Introducing the
third axis of frequency perpendicular to the amplitude-time plane the harmonic components
can be plotted in the plane that corresponds to their frequencies. This is the frequency
domain spectrum. Components of this spectrum appear as lines to reflect the fact that they
are planes in which the cosines are placed. A spectrum however can be plotted showing onlythe end points of each line connected together. For a spectrum with a large number of points
the gaps between the lines are barely visible and the spectrum appears continuous. Magnitude
spectrum is not sufficient to fully define the signal. The phase spectrum of each frequency
component must be known in order to unambiguously describe it. It is clear now that a
component of the spectrum at the given frequency must be described with two parameters.
In engineering practice signals are usually not described by mathematical functions but come
from measurement acquired with a selected sampling interval Δt (its inverse is the samplingfrequency or rate fs ). Thus the signal is not continuous but discrete. The duration of a signal
is finite and in most cases it will not be the same as the period required by the Fourier
Theorem. The signal may not be periodic at all. The purpose of frequency analysis is to
devise a method to extract an estimate of frequency components which are not known a
priori. The process is known as the Discrete Fourier Transform.
The choice of sampling frequency is arbitrary. The signal contains various frequency
components to be detected If the frequency to be detected is f and the sampling frequency is
too low, i.e. fs
-
8/17/2019 George Sebastian 12400026
55/122
Date:
54
The FFT does not directly give you the spectrum of a signal. The FFT can vary dramatically
depending on the number of points ( N ) of the FFT, and the number of periods of the signal
that are represented. There is another problem as well. The FFT contains information
between 0 and fs, however, we know that the sampling frequency must be at least twice the
highest frequency component. Therefore, the signal's spectrum should be entirely below fs/2 ,the Nyquist frequency. A real signal should have a transform magnitude that is symmetrical
for for positive and negative frequencies. So instead of having a spectrum that goes from 0 to
fs, it would be more appropriate to show the spectrum from -fs/2 to fs/2.
PROGRAM 5.3.1:
%MATLAB CODE FOR SPECTRAL ANALYSIS %Spectrum of a sinusoidal signal
clc;clear;f = input('Enter the frequency of sine wave ');fs=10*f;t=0:(1/fs):.1;x=sin(2*pi*f*t);n= 2^(nextpow2(length(x)));fftx=fft(x,n);mx = abs(fftx);mx=mx/(length(x))*2;mx = fftshift(mx);k=(-(n/2):(n/2)-1)/n*fs;
subplot(211);plot(t,x);title('Input signal');xlabel('Time(s)')ylabel('Amplitude')subplot(212);plot(k,mx);title('Spectrum of input signal') ;xlabel('Analog frequency (Hz)')ylabel('Amplitude')gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the frequency of sine wave 250
-
8/17/2019 George Sebastian 12400026
56/122
Date:
55
Figure 5.3.1: Spectrum of sinusoidal signal
PROGRAM 5.3.2:
%Spectrum analysis of a sum of sinusoids clc;clear;f1 = input('Enter the frequency of first sinewave ');f2 = input('Enter the frequency of second sinewave ');f=max(f1,f2)fs=10*f; %selecting sampling frequency t=0:(1/fs):.1;x=sin(2*pi*f1*t)+sin(2*pi*f2*t);
n= 2^(nextpow2(length(x)));fftx=fft(x,n);mx = abs(fftx);mx=mx/(length(x))*2;mx = fftshift(mx);k=(-(n/2):(n/2)-1)/n*fs;
subplot(211);plot(t,x);title('Input signal') ;xlabel('Time(s)')ylabel('Amplitude')subplot(212);plot(k,mx);
-
8/17/2019 George Sebastian 12400026
57/122
Date:
56
title('Spectrum of input signal') ;xlabel('Analog frequency (Hz)')ylabel('Amplitude')gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the frequency of first sinewave 250Enter the frequency of second sinewave 500
f =
500
Figure 5.3.2: Spectrum of sum of sinusoids
PROGRAM 5.3.3:
%Spectrum analysis of a AM signal clc;clear;fc = input('Enter the frequency of carrier wave ');fm = input('Enter the frequency of modulating wave ');m=input('modulating index');f=fm+fc;
fs=5*f; %selecting sampling frequency t=0:(1/fs):.1;
-
8/17/2019 George Sebastian 12400026
58/122
-
8/17/2019 George Sebastian 12400026
59/122
Date:
58
PROGRAM 5.3.4:
%Spectrum analysis of a random signal %selecting sampling frequency
fs=100;t=0:(1/fs):.1;x=randn(1,100)n= 2^(nextpow2(length(x)));
fftx=fft(x,n);mx = abs(fftx);mx=mx/(length(x))*2;mx = fftshift(mx);k=(-(n/2):(n/2)-1)/n*fs;subplot(211);plot(x);
title('Random signal')xlabel('Time(s)')ylabel('Amplitude')subplot(212);plot(k,mx);title('Spectrum of random signal') ;xlabel('Analog frequency (Hz)')ylabel('Amplitude')gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Figure 5.3.4: Spectrum of a random signal
-
8/17/2019 George Sebastian 12400026
60/122
Date:
59
CONCLUSION:
1.The amplitude spectrum of an N – point DFT is symmetrical about harmonic N/2. The DFTobtained by code DFT_matrix starts from 0 only and so, in order to satisfy this property as
well as the anti-symmetry of the phase function about harmonic N/2, the spectrum is folded
about the axis of symmetry. Then the discrete frequency N/2-1 corresponds to the normalized
frequency Π and -N/2 corresponds to Π.If 2f max smples per second were taken of the signal, then the discrete frequency N/2-1 corresponds to f max and -N/2 corresponds to - f max.. .All
these have been done in code ma_ph_rect.
2. The FFT of a signal can be used to obtain the spectrum of it. For that sampling frequency
(fs)selected such that fs >= 2fm,where fm is the maximum frequency in the signal otherwise
aliasing will happen.
RESULT:
The computation of DFT and IDFT using matrix multiplication is implemented. The
magnitude and phase response of a rect signal has been plotted. Spectral analysis of a
sinusoid, sum of sinusoids, AM wave and a random signal is done.
-
8/17/2019 George Sebastian 12400026
61/122
Date:
60
EXPERIMENT NO : 6
CONVOLUTION USING DFT
AIM:
To implement circular and linear convolution using DFT.
THEORY:
6.1 CIRCULAR CONVOLUTION USING DFT
Let x1(n) and x2(n) be two finite length sequence of length N and let y(n) be the N- point
circular convolution of x1(n) and x2(n).Let X1(k),X2(k) and Y(k) be the DFTs of x1(n),x2(n)
and y(n) respectively. Then,
Y(k)=X1(k)X2(k)
The IDFT of Y(k) will give the circular convolution of x1(n) and x2(n).
The matlab code for implementing circular convolution of two finite-length sequences using
DFT is as follows:
PROGRAM 6.1
% uses DFT to find circular convolution % N- point circular convolution between x1 and x2 %------------------------------------------------ % y = output sequence containing the circular convolution % x1 = input sequence of length N1
-
8/17/2019 George Sebastian 12400026
62/122
Date:
61
if length(x2)>Nerror('N must be greater than length of x2')
end
%Taking DFT
X1 = fft(x1,N);X2 = fft(x2,N);Y = X1.*X2;y = ifft(Y,N);stem(y);title('Circular convolution using DFT')xlabel('Time Index')ylabel('Amplitude')gtext('George Sebastian 12400026')
SAMPLE OUTPUTEnter the first sequence [0 1 0 0 0]Enter the second sequence [0 1 2 3 4]Enter the size of the circular convolution 5
Figure 6.1: Circular convolution using DFT
-
8/17/2019 George Sebastian 12400026
63/122
-
8/17/2019 George Sebastian 12400026
64/122
Date:
63
Figure 6.2: linear convolution using DFT
RESULT:
Implemented linear and circular convolution using DFT.
-
8/17/2019 George Sebastian 12400026
65/122
Date:
64
EXPERIMENT NO : 7
OVERLAP-SAVE METHOD
AIM:To find the convolution of two sequences using overlap-save method.
THEORY:
Overlap – save is the traditional name for an efficient way to evaluate the discrete convolution
between a very long signal x[n] and a finite impulse response (FIR) filter h[n]:
Where h[m]=0 for m outside the region [1, M ].
The concept is to compute short segments of y[n] of an arbitrary length L, and concatenate
the segments together. Consider a segment that begins at n = kL + M , for any integer k , and
define:
Then, for kL + M ≤ n ≤ kL + L + M − 1, and equivalently M ≤ n − kL ≤ L + M − 1, wecan write:
The task is thereby reduced to computing yk [n], for M ≤ n ≤ L + M − 1.
Now note that if we periodically extend xk [n] with period N ≥ L + M − 1, according to:
-
8/17/2019 George Sebastian 12400026
66/122
Date:
65
the convolutions and are equivalent in the region
M ≤ n ≤ L + M − 1. So it is sufficient to compute the -point circular convolution of
with h[n] in the region [1, N ]. The subregion [ M , L + M − 1] is appended to the outputstream, and the other values are discarded.
The advantage is that the circular convolution can be computed very efficiently as follows,
according to the circular convolution theorem:
where FFT and IFFT refer to the fast Fourier transform and inverse fast Fourier transform,
respectively, evaluated over N discrete points.
The overlap-save algorithm may be extended to include other common operations of a
system additional channels can be processed more cheaply than the first by reusing the
forward FFT
sampling rates can be changed by using different sized forward and inverse FFTs
frequency translation (mixing) can be accomplished by rearranging frequency bins
MATLAB CODE:
%Overlap Save method clcclear all close all h1=input('Enter the input sequence ');Ls=length(h1);h2=input('Enter the impulse sequence ');M=length(h2);L=input('Enter the length of each block ');h=[h2 zeros(1,L-(M-1))];x=[zeros(1,M-1) h1 zeros(1,L-1)];N=Ls+M-1;l1=length(x);i=1;j=1;while (i
-
8/17/2019 George Sebastian 12400026
67/122
Date:
66
y=y(:,M:n)'y=y(1:N)subplot(3,1,1)stem(h1)title('Input Sequence')
xlabel('Time Index')ylabel('Amplitude')subplot(3,1,2)stem(h2)title('Impulse Sequence')xlabel('Time Index')ylabel('Amplitude')subplot(3,1,3)stem(y)title('Linear Convolved signal using Overlap Save Method')xlabel('Time Index')
ylabel('Amplitude')gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the input sequence [1 2 -1 2 3 -2 -3 -1 1 1 2 -1]Enter the impulse sequence [1 2]Enter the length of each block 4
Figure 7 : Linear Convolution using overlap save method
-
8/17/2019 George Sebastian 12400026
68/122
Date:
67
RESULT:
The convolution of two sequences are obtained by using overlap-save method.
-
8/17/2019 George Sebastian 12400026
69/122
Date:
68
EXPERIMENT NO.8
OVERLAP-ADD METHOD
AIM:
To find the convolution of two sequences using overlap-add method.
THEORY:
The overlap – add method (OA, OLA) is an efficient way to evaluate the discrete
convolution of a very long signal x[n] with a finite impulse response (FIR) filter h[n]:
Where h[m] = 0 for m outside the region [1, M ].
The concept is to divide the problem into multiple convolutions of h[n] with short segments
of x[n]:
Where L is an arbitrary segment length. Then:
And y[n] can be written as a sum of short convolutions:
where is zero outside the region [1, L + M − 1].
And for any parameter it is equivalent to the -point circular
convolution of with h[n] in the region [1, N ].
-
8/17/2019 George Sebastian 12400026
70/122
Date:
69
The advantage is that the circular convolution can be computed very efficiently as follows,
according to the circular convolution theorem:
where FFT and IFFT refer to the fast Fourier transform and inverse fast Fourier transform,
respectively, evaluated over discrete points.
ALGORITHM:
Figure sketches the idea of the overlap – add method. The signal x[n] is first partitioned into
non-overlapping sequences, then the discrete Fourier transforms of the sequences are
evaluated by multiplying the FFT of with the FFT of . After recovering of
by inverse FFT, the resulting output signal is reconstructed by overlapping and adding
the as shown in the figure. The overlap arises from the fact that a linear convolution is
always longer than the original sequences. In the early days of development of the fast
Fourier transform, was often chosen to be a power of 2 for efficiency, but further
development has revealed efficient transforms for larger prime factorizations of L, reducing
computational sensitivity to this parameter.
MATLAB CODE :
%Overlap Add method clcclear all
-
8/17/2019 George Sebastian 12400026
71/122
Date:
70
close all h1=input('Enter the input sequence ');Ls=length(h1);h2=input('Enter the impulse sequence ');M=length(h2);
L=input('Enter the length of each block ');h=[h2 zeros(1,L-1)];x=[h1 zeros(1,L-1)];N=Ls+M-1;k=ceil(Ls/L);j=1;for i=1:1:kxk=[x(j:j+L-1)];xk=[xk zeros(1,M-1)];
y(i,:)=cconv(xk,h,length(h));j=i*L+1;
end y(i+1,1)=0;[m n]=size(y);for i=1:1:m-1for j=1:1:M-1
y(i+1,j)=y(i,n-(M-1)+j)+y(i+1,j);end end y=[y(:,1:L)]';y=y(1:N);subplot(3,1,1)
stem(h1)title('Input Sequence')xlabel('Time Index')ylabel('Amplitude')subplot(3,1,2)stem(h2)title('Impulse Sequence')xlabel('Time Index')ylabel('Amplitude')subplot(3,1,3)stem(y)
title('Linear Convolved signal using Overlap Add Method')xlabel('Time Index')ylabel('Amplitude')gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the input sequence [1 2 -1 2 3 -2 -3 -1 1 1 2 -1]Enter the impulse sequence [1 2]Enter the length of each block 3
-
8/17/2019 George Sebastian 12400026
72/122
Date:
71
Figure 8: Linear convolution using overlap add method
RESULT:
The convolution of two sequences are obtained by using overlap-add method.
-
8/17/2019 George Sebastian 12400026
73/122
Date:
72
EXPERIMENT NO : 9
IIR FILTERS
AIM:
To realize IIR filters using matlab
THEORY:
9.1 BUTTERWORTH LOW PASS FLTER
This filter is characterized the property that its magnitude response is flat in both passband
and stopband the magnitude of an Nth order low pass filter is given by
│Ha(jΩ)│² = 1/1+(Ω/Ωc)^2N
Where N is the order of filter and Ωc is the cutoff frequency
The analog filter is specified by Parameters Ωp, Rp, Ωs, and As
Filter order
N = [log[(10^(Rp/10)-1)/ (10^(As/10)-1)]/2log(Ωp/Ωs)]
To satisfy the specifications exactly at Ωp
Ωc = Ωp/(10^(Rp/10)-1)^(1/2N)
PROGRAM 9.1:
% Butterworth Low pass filterclc;clear;alphap=input('Enter the Passband attenuation in dB ');alphas=input('Enter the Stopband attenuation in dB ');
fp=input('Enter the Passband frequency in hertz ');fs=input('Enter the Stopband frequency in hertz ');F=input('Enter the Sampling frequency in hertz ');normfp=2*fp/F;normfs=2*fs/F;[n,normf]=buttord(normfp,normfs,alphap,alphas);fn=normf*F/2;display('The order of the filter is = ');ndisplay('The cut off frequency in hertz of the filter is =');fn[b,a]=butter(n,normf);
display('The Numerator coefficients of the filter is = ');bdisplay('The Denominator coefficients of the filter is = ');a
-
8/17/2019 George Sebastian 12400026
74/122
Date:
73
[h,f]=freqz(b,a,512,F);Av=abs(h);an=angle(h)*180/pi;subplot(211);plot(f,Av);
title('Magnitude Response');xlabel('Frequency in hertz');ylabel('Magnitude');grid on;subplot(212);plot(f,an);title('Phase Response');xlabel('Frequency in hertz');ylabel('Phase in degrees');grid on;gtext('George Sebastian 12400026');
SAMPLE OUTPUT
Enter the Passband attenuation in dB .4Enter the Stopband attenuation in dB 30Enter the Passband frequency in hertz 400Enter the Stopband frequency in hertz 800Enter the Sampling frequency in hertz 2000The order of the filter is =
n =
4
-
8/17/2019 George Sebastian 12400026
75/122
Date:
74
Figure 9.1: Butterworth lowpass filter
PROGRAM 9.2:
% Butterworth High pass filterclc;clear;alphap=input('Enter the Passband attenuation in dB ');alphas=input('Enter the Stopband attenuation in dB ');fp=input('Enter the Passband frequency in hertz ');fs=input('Enter the Stopband frequency in hertz ');F=input('Enter the Sampling frequency in hertz ');normfp=2*fp/F;normfs=2*fs/F;
[n,normf]=buttord(normfp,normfs,alphap,alphas);fn=normf*F/2;display('The order of the filter is = ');ndisplay('The cut off frequency in hertz of the filter is =');fn[b,a]=butter(n,normf,'high');display('The Numerator coefficients of the filter is = ');bdisplay('The Denominator coefficients of the filter is = ');a[h,f]=freqz(b,a,512,F);Av=abs(h);an=angle(h)*180/pi;
subplot(211);plot(f,Av);
-
8/17/2019 George Sebastian 12400026
76/122
Date:
75
title('Magnitude Response');xlabel('Frequency in hertz');ylabel('Magnitude');grid on;subplot(212);
plot(f,an);title('Phase Response');xlabel('Frequency in hertz');ylabel('Phase in degrees');grid on;gtext('George Sebastian 12400026');
SAMPLE OUTPUT
Enter the Passband attenuation in dB 0.4
Enter the Stopband attenuation in dB 50Enter the Passband frequency in hertz 800Enter the Stopband frequency in hertz 500Enter the Sampling frequency in hertz 2000The order of the filter is =
n =
7
Figure 9.2: Butterworth High Pass Filter
-
8/17/2019 George Sebastian 12400026
77/122
Date:
76
PROGRAM 9.3:
% Butterworth Band pass filterclc;clear;
alphap=input('Enter the Passband attenuation in dB ');alphas=input('Enter the Stopband attenuation in dB ');fp=input('Enter the Passband frequencies in hertz in an array');fs=input('Enter the Stopband frequencies in hertz in an array');F=input('Enter the Sampling frequency in hertz');
normfp=2*fp/F;normfs=2*fs/F;[n,normf]=buttord(normfp,normfs,alphap,alphas);
fn=normf*F/2;
display('The order of the filter is = ');ndisplay('The cut off frequencies in hertz of the filter are =');fn
[b,a]=butter(n,normf);display('The Numerator coefficients of the filter is = ');bdisplay('The Denominator coefficients of the filter is = ');a
[h,f]=freqz(b,a,512,F);
Av=abs(h);an=angle(h)*180/pi;
subplot(211);plot(f,Av);title('Magnitude Response');xlabel('Frequency in hertz');ylabel('Magnitude');grid on;subplot(212);plot(f,an);
title('Phase Response');xlabel('Frequency in hertz');ylabel('Phase in degrees');grid on;gtext('George Sebastian 12400026');
SAMPLE OUTPUT
Enter the Passband attenuation in dB 2Enter the Stopband attenuation in dB 30
Enter the Passband frequencies in hertz in an array [350 800]Enter the Stopband frequencies in hertz in an array [200 900]
-
8/17/2019 George Sebastian 12400026
78/122
Date:
77
Enter the Sampling frequency in hertz 5000The order of the filter is =
n =
13
Figure 9.3: Butterworth Band pass filter
PROGRAM 9.4:
% Butterworth Band reject filter
clc;clear;alphap=input('Enter the Passband attenuation in dB ');alphas=input('Enter the Stopband attenuation in dB ');fp=input('Enter the Passband frequencies in hertz in an array');fs=input('Enter the Stopband frequencies in hertz in an array');F=input('Enter the Sampling frequency in hertz ');normfp=2*fp/F;normfs=2*fs/F;
[n,normf]=buttord(normfp,normfs,alphap,alphas);fn=normf*F/2;
-
8/17/2019 George Sebastian 12400026
79/122
Date:
78
display('The order of the filter is = ');ndisplay('The cut off frequencies in hertz of the filter are =');fn[b,a]=butter(n,normf,'stop');
display('The Numerator coefficients of the filter is = ');bdisplay('The Denominator coefficients of the filter is = ');a[h,f]=freqz(b,a,512,F);Av=abs(h);an=angle(h)*180/pi;
subplot(211);plot(f,Av);title('Magnitude Response');xlabel('Frequency in hertz');ylabel('Magnitude');
grid on;subplot(212);plot(f,an);title('Phase Response');xlabel('Frequency in hertz');ylabel('Phase in degrees');grid on;gtext('George Sebastian 12400026');
SAMPLE OUTPUT
Enter the Passband attenuation in dB 2Enter the Stopband attenuation in dB 30Enter the Passband frequencies in hertz in an array [200 900]Enter the Stopband frequencies in hertz in an array [350 750]Enter the Sampling frequency in hertz 2000The order of the filter is =
n =
5
-
8/17/2019 George Sebastian 12400026
80/122
-
8/17/2019 George Sebastian 12400026
81/122
Date:
80
The sum of the number of maxima and minima in the passband equal the order of
filter
The lowpass normalized Chebyshev 1 filter is characterized by following magnitude squared
frequency response
| HN (Ω)| 2 = [1 + є2TN 2(Ω)]-1
FILTER DESIGN EQUATIONS
є=100.1Rp -1]
A=10(As/20)
Ωc= Ωp
Ωr= Ωs/Ωp
g=(A2-1)/ є2]N=[(log10 g+(g2-1))/(log10Ωr +( Ωr2-1))]
PROGRAM 9.5:
%Chebyshev Low Pass Filter clc;clear all;close all;format long;pr=input('Enter the pass band ripple ');sr=input('Enter the stop band ripple ');pf=input('Enter the pass band frequency ');sf=input('Enter the stop band frequency ');
fs=input('Enter the sampling frequency in hz ');w1=2*pf/fs;w2=2*sf/fs;[n,wn]=cheb1ord(w1,w2,pr,sr,'s');[b,a]=cheby1(n,pr,wn,'s');w=0:0.01:pi;[h,om]=freqs(b,a,w);m=20*log10(abs(h));ang=angle(h);subplot(2,1,1);plot(om/pi,m);
title('Magnitude Response of the low pass filter:');xlabel('Normalized Frequency');
-
8/17/2019 George Sebastian 12400026
82/122
Date:
81
ylabel('Magnitude');grid on;subplot(2,1,2);plot(om/pi,ang);title('Phase Response of the low pass filter:');
xlabel('Normalized Frequency');ylabel('Phase in degree');grid on;gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the pass band ripple 0.5Enter the stop band ripple 40Enter the pass band frequency 5000
Enter the stop band frequency 6000Enter the sampling frequency in hz 10000
Figure 9.5: Chebyshev type I low pass filter
-
8/17/2019 George Sebastian 12400026
83/122
Date:
82
PROGRAM 9.6
%Chebyshev High Pass Filter clc;clear all;
close all;format long;pr=input('Enter the pass band ripple ');sr=input('Enter the stop band ripple ');pf=input('Enter the pass band frequency ');sf=input('Enter the stop band frequency ');fs=input('Enter the sampling frequency in hz ');w1=2*pf/fs;w2=2*sf/fs;[n,wn]=cheb1ord(w1,w2,pr,sr,'s');[b,a]=cheby1(n,pr,wn,'high','s');
w=0:0.01:pi;[h,om]=freqs(b,a,w);m=20*log10(abs(h));ang=angle(h);subplot(2,1,1);plot(om/pi,m);title('Magnitude Response of the High pass filter:');xlabel('Normalized Frequency');ylabel('Magnitude');grid on;subplot(2,1,2);
plot(om/pi,ang);title('Phase Response of the High pass filter:');xlabel('Normalized Frequency');ylabel('Phase in degree');grid on;gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the pass band ripple 0.7Enter the stop band ripple 30Enter the pass band frequency 6000Enter the stop band frequency 7000Enter the sampling frequency in hz 10000
-
8/17/2019 George Sebastian 12400026
84/122
Date:
83
Figure 9.6: Chebyshev I High Pass Filter
PROGRAM 9.7:
%Chebyshev Band Pass Filter clc;clear all;close all;format long;pr=input('Enter the pass band ripple ');sr=input('Enter the stop band ripple ');pf=input('Enter the pass band frequency as an interval ');sf=input('Enter the stop band frequency as an interval ');fs=input('Enter the sampling frequency in hz ');w1=2*pf/fs;w2=2*sf/fs;[n,wn]=cheb1ord(w1,w2,pr,sr,'s');[b,a]=cheby1(n,pr,wn,'bandpass','s');w=0:0.01:pi;[h,om]=freqs(b,a,w);m=20*log10(abs(h));ang=angle(h);subplot(2,1,1);plot(om/pi,m);
title('Magnitude Response of the Band pass filter:');xlabel('Normalized Frequency');
-
8/17/2019 George Sebastian 12400026
85/122
Date:
84
ylabel('Magnitude');grid on;subplot(2,1,2);plot(om/pi,ang);title('Phase Response of the Band pass filter:');
xlabel('Normalized Frequency');ylabel('Phase in degree');grid on;gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the pass band ripple 0.4Enter the stop band ripple 30Enter the pass band frequency as an interval [3000 5000]
Enter the stop band frequency as an interval [1000 8000]Enter the sampling frequency in hz 10000
Figure 9.7: Chebyshev I Band pass filter
-
8/17/2019 George Sebastian 12400026
86/122
Date:
85
PROGRAM 9.8:
%Chebyshev Band Stop Filter clc;clear all;
close all;format long;pr=input('Enter the pass band ripple ');sr=input('Enter the stop band ripple ');pf=input('Enter the pass band frequency as an interval ');sf=input('Enter the stop band frequency as an interval ');fs=input('Enter the sampling frequency in hz ');w1=2*pf/fs;w2=2*sf/fs;[n,wn]=cheb1ord(w1,w2,pr,sr,'s');[b,a]=cheby1(n,pr,wn,'stop','s');
w=0:0.01:pi;[h,om]=freqs(b,a,w);m=20*log10(abs(h));ang=angle(h);subplot(2,1,1);plot(om/pi,m);title('Magnitude Response of the Band stop filter:');xlabel('Normalized Frequency');ylabel('Magnitude');grid on;subplot(2,1,2);
plot(om/pi,ang);title('Phase Response of the Band stop filter:');xlabel('Normalized Frequency');ylabel('Phase in degree');grid on;gtext('George Sebastian 12400026')
SAMPLE OUTPUT
Enter the pass band ripple 0.4Enter the stop band ripple 30Enter the pass band frequency as an interval [1000 8000]Enter the stop band frequency as an interval [3000 5000]Enter the sampling frequency in hz 10000
-
8/17/2019 George Sebastian 12400026
87/122
Date:
86
Figure 9.8: Chebyshev Band stop filter
RESULT:
IIR filters are designed and implemented using MATLAB.
-
8/17/2019 George Sebastian 12400026
88/122
Date:
87
EXPERIMENT NO.10
FIR FILTER DESIGN
AIM:To design FIR low pass filters using
i) Window method
a) Hamming Window
b) Hanning Window
ii) Frequency sampling method
THEORY:
1) Window method: The desired frequency response H d (e jw ) of a filter is periodic in
frequency and can be expanded in Fourier series is given by
H d (e jw ) () hd(n) e -jwn
where hd (n) = ∫ ( 1/2Π H d (e jw ) e jwn dω
and known as Fourier coefficients having infinite length. One possible way of obtaining FIR
filter is to truncate the infinite Fourier series at n= ± (
), where N is the length of thedesired sequence. The Fourier coefficients of the filter are modified by multiplying the
infinite impulse response with a finite sequence w(n) called window.
For an ideal low pass filter of cut off frequency w c and sample delay α, the impulse responseis given by
hd (n) = sin(ωN/2)/sin(ω/2)
To obtain an FIR filter from hd(n), one has to truncate it on both sides. Thus
h(n)= hd (n)w(n) where w(n) represents the window.
Hamming and Hanning windows:
The hamming window is similar to a raised cosine window function, but with a small amount
of discontinuity and is given by
-
8/17/2019 George Sebastian 12400026
89/122
Date:
88
wham(n) = 0.54 – 0.46cos(2Πn/N-1) , -(N-1)/2≤n≤(N-1)/2
0 , otherwise
The hanning window sequence is given by
whann(n) = 0.5 + 0.5cos(2Πn/N-1) , -(N-1)/2≤n≤(N-1)/2
0
, otherwise
At higher frequencies, the stop band attenuation is low when compared to that of hanning
window. Since the hamming window generates lesser oscillations in the side lobes than the
hanning window for the same main lobe width, the Hamming window is generally
preferred.
2) Frequency sampling method: Transfer function H(z) of an FIR filter is given by
H(z) = ∑ () (n) z-n
where h(n)= ∑ () , n=0,1,2...N-1
The DFT samples H(k) for an FIR sequence can be regarded as samples of the filter Ztransform evaluated at N points equally spaced along the unit circle. That is
H(k)= H(z)| z=e j2Πk/N
Thus H(z) =
∑()
H(k)/(1- e
j2Πk/N z -1 )
That is H(k) is kth DFT component obtained by sampling the frequency response H(e jw). As
such this approach for designing FIR filter is called the frequency sampling method.
-
8/17/2019 George Sebastian 12400026
90/122
Date:
89
MATLAB CODE:
PROGRAM 10.1:
%Designing an FIR low pass filter using Hamming window wc=0.5*pi;N=60;alpha=(N-1)/2;eps=0.001;n=0:1:N-1;hd=sin(wc*(n-alpha + eps))./(pi*(n-alpha + eps));wh=hamming(N);hn=hd.*wh';
w=0:0.01:pi;h=freqz(hn,1,w);subplot(311);stem(n,wh);xlabel('n');ylabel('wh(n)');title('hamming window');subplot(312);stem(n,hn);xlabel('n');ylabel('hn');
title('ideal impulse response');subplot(313);plot(w/pi,abs(h));grid;xlabel('Normalized frequency');ylabel('Magnitude');title('Magitude response');gtext('George Sebastian 12400026');
-
8/17/2019 George Sebastian 12400026
91/122
-
8/17/2019 George Sebastian 12400026
92/122
Date:
91
stem(n,hn);xlabel('n');ylabel('hn');title('ideal impulse response');subplot(313);
plot(w/pi,abs(h));grid;xlabel('Normalized frequency');ylabel('Magnitude');title('magitude response');gtext('George Sebastian 12400026');
SAMPLE OUTPUT
Figure 10.2: Filter using hanning window
PROGRAM 10.3:
% Designing a FIR low pass filter using Frequency samplingmethod
% wc=0.5pi N=33;
-
8/17/2019 George Sebastian 12400026
93/122
Date:
92
alpha=(N-1)/2;Hrk=[ones(1,9),zeros(1,16),ones(1,8)];%samples of magnitude response k1=0:(N-1)/2;k2=(N+1)/2:N-1;
theetak=[(-alpha*(2*pi)/N)*k1,(alpha*(2*pi)/N)*(N-k2)];Hk=Hrk.*(exp(1i*theetak));w=0:0.01:pi; hn=real(ifft(Hk,N));H=freqz(hn,1,w);plot(w/pi,20*log10(abs(H)));ylabel('Magnitude in db');xlabel('Normalized frequency \omega/\pi');gtext('George Sebastian 12400026');
SAMPLE OUTPUT
Figure 10.3: Filter design using frequency sampling
-
8/17/2019 George Sebastian 12400026
94/122
Date:
93
CONCLUSION:
The rectangular windowing, being a direct truncation of the infinite length hd(n), suffers from
Gibbs phenomenon. If we increase N, the width of each side lobe will decrease but the area
under each lobe will remain constant. This implies that all ripples will bunch up near the band
edges.
For the Hamming window, the main lobe width is equal to 8π/N and the peak side lobe levelis down about 41 dB from the main lobe peak.
It can be seen that for the same design specifications, the Hamming Window provides lower
filter order than the Blackman window, but the latter provides more stopband attenuation and
smaller passband ripple.
Frequency sampling method is attractive for narrow band frequency selective filters where
only a few of the samples of the frequency response are non zero.
RESULT:
FIR low pass filters have been designed by using, Hamming Window, Hanning Window, and
using Frequency sampling method. And the frequency responses in each case have been
plotted.
-
8/17/2019 George Sebastian 12400026
95/122
Date:
94
EXPERIMENT NO.11
SAMPLING RATE CONVERSION BY RATIONAL FACTOR
AIM:To implement sampling rate conversion by rational factor.
THEORY:
Sample rate conversion is the process of converting a (usually digital) signal from
one sampling rate to another, while changing the information carried by the signal as little as
possible. Sampling rate conversion is a typical example where it is required to determine the
values between existing samples. The computation of a value between existing samples can
alternatively be regarded as delaying the underlying signal by a fractional sampling period.
The fractional-delay filters are used in this context to provide a fractional-delay adjustable to
any desired value and are therefore suitable for both integer and non-integer factors.
MATLAB CODE:
%Sampling rate conversion by rational factor clc; clear all; close all;disp('Sampling rate conversion by rational factor ');f=input('Enter frequency of the signal ');Fs=input('Enter sampling rate in samples/sec ');
N=input('Enter number of samples N = ');L=input('Enter up-sampling factor L = ');M=input('Enter down-sampling factor M(
-
8/17/2019 George Sebastian 12400026
96/122
Date:
95
ni=0:length(xi)-1;subplot(4,1,2); stem(ni,xi);xlabel('Time index n'); ylabel('xi(n)');Fsu=Fs*L;title(['Up sampled signal with sampling rate Fs =
',num2str(Fsu),' Hz']);%Down-sampled sequence nd=0:length(xd)-1;subplot(4,1,3); stem(nd,xd);xlabel('Time index n'); ylabel('xd(n)');Fsd=Fs/M;title(['Down sampled signal with sampling rate Fs =',num2str(Fsd),' Hz']);%Re-sampled sequence ny=0:length(y)-1;subplot(4,1,4); stem(ny,y);
xlabel('Time index n'); ylabel('y(n)');Fssc=Fs*L/M;title(['Sampling rate converted signal with sampling rate L/M= ',num2str(Fssc),' Hz']);gtext('George Sebastian 12400026');
SAMPLE OUTPUT
Sampling rate conversion by rational factorEnter frequency of the signal 20Enter sampling rate in samples/sec 50Enter number of samples N = 20Enter up-sampling factor L = 2Enter down-sampling factor M(
-
8/17/2019 George Sebastian 12400026
97/122
Date:
96
Figure 11: Sampling rate conversion by a rational number
RESULT:
Sampling rate conversion by a rational factor is implemented in MATLAB.
-
8/17/2019 George Sebastian 12400026
98/122
Date:
97
EXPERIMENT NO.12
OPTIMAL EQUIRIPPLE DESIGN TECHNIQUE FOR FIR
FILTERS
AIM:
To design FIR lowpass, bandpass and highpass filters using the optimal equiripple design
technique and to obtain the frequency response.
Optimal Design MethodThe disadvantage of the window design are that (i) we cannot specify the band frequencies ω p and ωs precisely in the design, (ii) we cannot specify both (δ1 = δ2), and the approximationerror – that is, the difference between the ideal response the actual response – is notuniformly distributed over the band intervals (higher near the band edges and smaller in the
regions away from band edges). The idea behind the optimal method is that by distributing
the error uniformly, we can obtain a lower order filter satisfying the same specifications. For
linear – phase FIR filters it is possible to derive a set of conditions for which it can be provedthat the design solution is optimal in the sense of minimizing the maximum approximation
error (sometimes called the minimax or the Chebyshev error). Filters that have this propertyare called equiripple filters because the approximation error is uniformly distributed in both
the passband and the stopband. This results in lower-order filters.
The MATLAB code to design the FIR lowpass filter using the Parks-McClellan algorithms is
as follows:
MATLAB CODE:
%Pgm to design FIR low-pass filter using Parks-McClellan%algorithm to meet the desired specifications wp=input('Enter the passband edge frequency ');ws=input('Enter the stopband edge frequency ');Rp=input('Enter the passband ripple in dB ');As=input('Enter the stopband attenuation in dB ');
delta_w=2*pi/1000;wsi=ws/delta_w+1;delta1=(10^(Rp/20)-1)/(10^(Rp/20)+1);
delta2=(1+delta1)*(10^(-As/20));deltaH=max(delta1,delta2);
-
8/17/2019 George Sebastian 12400026
99/122
Date:
98
deltaL=min(delta1,delta2);weights=[delta2/delta1 1];deltaf=(ws-wp)/(2*pi);f=[0 wp/pi ws/pi 1];m=[1 1 0 0];
M=ceil((-20*log10(sqrt(delta1*delta2))-13)/(14.6*deltaf)+1);while(1);
h=firpm(M-1,f,m,weights);[db,mag,pha,grd,w]=freqz_m(h,[1]);Asd=-max(db(wsi:1:501));if Asd >= As
break else
M=M+1;end
end
Mdisp('Actual stopband attenuation');Asd%Plotting n=0:1:(M-1);subplot(211); stem(n,h);axis([0 M-1 -0.1 0.3]);title('Actual Impulse Response'); xlabel('n'); ylabel('h[n]');
subplot(212); plot(w/pi,db);gridaxis([0 1 -80 10]);
title('Magnitude Response in dB'); xlabel('Frequency in piunits'); ylabel('Decibels');gtext('George Sebastian 12400026');figure,plot(w/pi,mag);gridaxis([0 1 -0.2 1.2]);title('Amplitude Response'); xlabel('Frequency in pi units');ylabel('Hr(w)');gtext('George Sebastian 12400026');%Error L1=wp/delta_w + 1;for l=1:1:L1
e1(l)=1-mag(l);end L2=ws/delta_w + 1;L=501-L2+1;for l=1:1:L
e2(l)=mag(L2+l-1);end w1=w(1:1:L1);w2=w(L2:1:501);figure,subplot(211); plot(w1/pi,e1);title('Error response in passband');
xlabel('Frequency in pi units'); ylabel('E(w)');subplot(212); plot(w2/pi,e2);
-
8/17/2019 George Sebastian 12400026
100/122
-
8/17/2019 George Sebastian 12400026
101/122
Date:
100
Figure 12.1.1: Response of FIR LPF designed using Parks-McClellan algorithm
-
8/17/2019 George Sebastian 12400026
102/122
Date:
101
Figure 12.1.2: Amplitude Response
-
8/17/2019 George Sebastian 12400026
103/122
Date:
102
Figure 12.1.3: Weighted Error Response
CONCLUSION:
1. Comparing with the results of window design technique, it can be seen that the filter order
resulting from the optimal method is lower for the same design specifications.
2. The equiripple behaviour is seen in the plots of the weighted response.
RESULT:
FIR lowpass filter have been designed using the Parks-McClellan algorithm and their
frequency and error responses have been obtained.
-
8/17/2019 George Sebastian 12400026
104/122
Date:
103
EXPERIMENT NO.13
INTODUCTION TO DSP DEVELOPMENT SYSTEM
AIM:
To study the tools available for digital signal processing, including Code Composer
Studio (CCS), this provides an integrated development environment (IDE), and the DSP
starter kit (DSK) with the TMS320C6713 floating-point processor on-board.
INTRODUCTION:
Components of a typical DSP system
Typical DSP systems consist of a DSP chip, Memory, possibly an analog-to-digital converter
(ADC), a digital-to-analog converter (DAC), and communication channels. Not all DSP
systems have the same architecture with the same components. The selection of components
in a DSP system depends on the application. For example, a sound system would probably
require A/D and D/A converters, whereas an image processing system may not.
-
8/17/2019 George Sebastian 12400026
105/122
Date:
104
DSP chip
A DSP chip can contain many hardware elements; some of the more common ones are listed
below.
1. Central Arithmetic Unit
This part of the DSP performs major arithmetic functions such as multiplication and addition.
It is the part that makes the DSP so fast in comparison with traditional processors.
2. Auxiliary Arithmetic Unit
DSPs frequently have an auxiliary arithmetic unit that performs pointer arithmetic,
mathematical calculations, or logical operations in parallel with the main arithmetic unit.
3. Serial Ports
DSPs normally have internal serial ports for high-speed communication with other DSPs and
data converters.
These serial ports are directly connected to the internal buses to improve performance, to
reduce external address decoding problems, and to reduce cost.
4. Memory
Memory holds information, data, and instructions for DSPs and is an essential part of any
DSP system.
Although DSPs are intelligent machines, they still need to be told what to do. Memory
devices hold a series of instructions that tell the DSP which operations to perform on the data
(i.e., information). In many cases, the DSP reads some data, operates on it, and writes it back.
Almost all DSP systems have some type of memory device, whether it is on-chip memory or
off-chip memory; however, on-chip memory operates faster.
5. A/D and D/A Converter
Converters provide the translator function for the DSP. Since the DSP can only operate on
digital data, analog signals from the outside world must be converted to digital signals. Whenthe DSP provides an output, it may need to be converted back to an analog signal to be
perceived by the outside world.
Analog-to-digital converters (ADCs) accept analog input and turn it into digital data that
consist of only 0s and 1s. Digital-to-analog converters (DACs) perform the reverse process;
they accept digital data and convert it to a continuous analog signal.
6. Ports
Communication ports are necessary for a DSP system. Raw information is received and
process information is transmitted to the outside world through these ports. For example, a
-
8/17/2019 George Sebastian 12400026
106/122
Date:
105
DSP system could output information to a printer through a port. The most common ports are
serial and parallel ports. A serial port accepts a serial (single) stream of data and converts it to
the processor format. When the processor wishes to output serial data, the port accepts
processor data and converts it to a serial stream (e.g., modem connections
On PCs). A parallel port does the same job, except the output and input are in parallel
(simultaneous)format. The most common example of a parallel port is a printer port on a PC.
Digital signal processors such as the TMS320C6x (C6x) family of processors are like fast
special-purpose microprocessors with a specialized type of architecture and an instruction set
appropriate for signal processing. The C6x notation is used to designate a member of Texas
Instruments’ (TI) TMS320C6000 family of digital signal processors. The architecture of theC6x digital signal processor is very well suited for numerically intensive calculations. Based
on a very-long-instruction-word (VLIW) architecture, the C6x is considered to be TI’s most powerful processor.
DSK support tools
To perform the design of a program to implement a DSP application, the following tools are
to be used:
1. TI’s DSP starter kit (DSK). The DSK package includes:
(a) Code Composer Studio (CCS), which provides the necessary software support
tools. CCS provides an integrated development environment (IDE), bringing
together the C compiler, assembler, linker, debugger, and so on.
(b) A board, that contains the TMS320C6713 (C6713) floating-point digital signal
processor as well as a 32-bit stereo codec for input and output (I/O) support.
(c) A universal synchronous bus (USB) cable that connects the DSK board to a PC.
(d) A 5V power supply for the DSK board.
2. An I BM -compatible PC . The DSK board connects to the USB port of the PC through the
USB cable included with the DSK package.
3. An oscil loscope, signal generator , and speakers . A signal/spectrum analyzer is optional.Shareware utilities are available that utilize the PC and a sound card to create a virtual
instrument such as an oscilloscope, a function generator, or spectrum analyser.
The 6713 DSK is a low-cost standalone development platform that enables us to evaluate and
develop applications for the TI C67XX DSP family. The DSK als