DSP Lab Record
DSP Lab Record
EXPERIMENT –01
INTRODUCTION TO MATLAB
AIM :
To generate and plot sum of sinusoidal signals using MATLAB.
EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.
THEORY:
Sinusoidal signal:
A signal, which is continuous in nature is known as continuous signal. General format of a
sinusoidal signal is
x(t)=Asin(ωt+ϕ)
Here,
A = amplitude of the signal
ω = Angular frequency of the signal Measured in radians
φ = Phase angle of the signal Measured in radians
The tendency of this signal is to repeat itself after certain period of time, thus is called periodic
signal. The time period of signal is given as;
T=2πω
1
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
A continuous-time signal x(t) is said to be periodic with period T if it satisfy the condition
A signal is periodic if the above condition is not satisfied for at least one value of T.
The smallest value of T that satisfies the above condition is known as fundamental period.
Complex exponential and sinusoidal signals are examples for continuous time periodic signals.
Consider a sinusoidal signal.
x(t)=Asin(wt+θ)
Where A is the amplitude, w is the frequency in radians per second (rad/sec), and θ the phase
in radians. The frequency f0 in hertz is given by f0 = w /2π or periodic signal we have
X(t+T)=x(t)
For x(t)=Asin(wt+θ)
= Asin[wt+wT+θ]
wT = 2π , T =2π/ w
2
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
ALGORITHM :
Step : 1 Get/Read the frequencies of sinusoidal signals.
Step : 5 Plot the graph of all sinusoidal signals and sum signal.
PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window
2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.
PROGRAM :
clc;
clear all;
close all;
t=0:0.01:3;
freq1 = input('Frequency of first signal :');
freq2 = input('Frequency of second signal :');
freq3 = input('Frequency of third signal :');
amp1 = input('Amplitude of first signal :');
amp2 = input('Amplitude of second signal :');
amp3 = input('Amplitude of third signal :');
sig1 = amp1 * sin(2*pi*freq1*t);
sig2 = amp2 * sin(2*pi*freq2*t);
sig3 = amp3 * sin(2*pi*freq3*t);
3
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
4
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Input :
Frequency of 1st signal: 5
Output :
5
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Result:
Sum of Sinusoidal Signals is performed using MATLAB Software.
6
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
7
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO – 2
LINEAR CONVOLUTION OF TWO SEQUENCES
AIM :
To perform the linear convolution of given sequences using MATLAB.
EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.
THEORY:
Convolution
Convolution is a mathematical operation used to express the relation between input and
output of an LTI system. It relates input, output and impulse response of an LTI system as
y (t) = x(t) * h(t)
Where y (t )= output of LTI
x (t) = input of LTI
h (t) = impulse response of LTI
There are two types of convolutions:
● Continuous convolution
● Discrete convolution
Continuous Convolution
8
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Discrete Convolution
9
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Algorithm :
Step : 1 Get/Read the samples of x[n] to x.
10
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
THEORITICAL CALCULATIONS:
X[n]
2 3 4 2
3 6 9 12 6
h[n] 4 8 12 16 8
1 2 3 4 2
2 4 6 8 4
y[n] = [6 17 26 29 18 10 4]
11
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window
2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.
PROGRAM :
clc;
clear all;
close all;
n2=length(x);
n4=length(h);
n5=n1+n2-1;
n6=n3+n4-1;
y=conv(x,h);
n=n1:n5;
subplot(3,1,1);
stem(n,x);
12
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
xlabel('Time');
ylabel('Amplitude');
n=n3:n6;
subplot(3,1,2);
stem(n,h);
xlabel('Time');
ylabel('Amplitude');
n=n1+n3:n5+n6;
subplot(3,1,3);
stem(n,y);
xlabel('Time');
ylabel('Amplitude');
disp(y);
13
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Input :
Enter the sequence x[n] : [2 3 4 2]
Output :
Linear convolution of x[n] and h[n] is
y[n] = [6 17 26 29 18 10 4]
14
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
15
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
RESULT:
Linear convolution of given sequences is performed and output is verified theoretically
and practically using MATLAB.
16
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
17
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO – 3
CIRCULAR CONVOLUTION OF TWO SEQUENCE
AIM :
To perform the circular convolution of given sequences using MATLAB.
EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.
THEORY:
x[n] and h[n] are two finite sequences of length N with DFTs denoted by X[k] and H[k],
respectively. Let us form the product
W[k] = X[k]H[k],
and determine the sequence w[n] of length N for which the DFT is W[k].
First, extend x[n] and h[n] to periodic sequences with period N, x h ˜[n] and [n], respectively. ˜
Then, the periodic convolution of x h ˜[n] and [n] corresponds to multiplication of the
corresponding periodic sequences of Fourier series coefficients.
N −1
¿ ∑ ❑ x [m] h[((n−m))N ]
m =0
18
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Algorithm :
Step : 1 Get/Read the samples of x[n] to x.
19
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
THEORITICAL CALCULATIONS:
20
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window
2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window..
PROGRAM :
clc;
clear all;
close all;
x=input('Enter input sequence x[n] :');
h=input('Enter the sequence h[n] :');
n1=length(x);
n2=length(h);
N=max(n1,n2);
if n1>n2
h=[h,zeros(1,n1-n2)];
else
x=[x,zeros(1,n2-n1)];
end
y=cconv(x,h,N);
n=0:N-1;
subplot(3,1,1);
21
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
stem(n,x);
xlabel('n----->');
ylabel('Amplitude');
title('Input sequence x[n]:');
n=0:N-1
subplot(3,1,2);
stem(n,h);
xlabel('n----->');
ylabel('Amplitude');
title('Impulse sequence h[n]:');
n=0:N-1;
subplot(3,1,3);
stem(n,y);
xlabel('n----->');
ylabel('Amplitude');
title('Output sequence y[n]:');
disp(y);
22
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Input :
Output :
Circular convolution of x[n] and h[n] is
23
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
RESULT:
Circular convolution of given sequences is performed and output is verified theoretically
and practically using MATLAB.
24
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO – 4
FAST FOURIER TRANSFORM OF TWO SEQUENCE
AIM :
To obtain the fast fourier transform of given sequence using MATLAB Software.
EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.
THEORY:
DFT:
The discrete Fourier transform (DFT) is the primary transform used for numerical computation
in digital signal processing. It is very widely used for spectrum analysis, fast convolution, and
many other applications. The DFT transforms NN discrete-time samples to the same number of
discrete frequency samples, and is defined as
X(k)=∑n=0N−1x(n)e−(i2πnkN)X k n N 1 0 x n 2 n k N
The DFT is widely used in part because it can be computed very efficiently using fast Fourier
transform (FFT) algorithms.
IDFT
x(n)=1N∑k=0N−1X(k)ei2πnkNx n 1 N k N 1 0 X k 2 n k N
25
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Algorithm :
Step : 1 Get/Read the samples of x[n] to x.
Step : 8 Now find DFT using FFT with inbuilt function fft.
Step : 11 Now find IDFT using IFFT with inbuilt function ifft.
PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window
2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.
26
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
THEORITICAL CALCULATIONS:
27
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
PROGRAM :
clc;
clear all;
close all;
x=input('Enter the sequence x[n]:');
n1=input('Enter the legth of sequence s[n]:');
n2=length(x);
N=n2-n1;
n=0:n2-1;
subplot(4,1,1);
stem(n,x);
xlabel('n----------->');
ylabel('Amplitude');
title('Input sequence x[n]');
disp('The input sequence is:');
disp(x);
if(n1>n2)
x=[x,zeros(1,N)];
end
y=fft(x,n1);
disp('FFT of input sequence is');
disp(y);
n = 0:n1-1;
subplot(4,1,2);
stem(n,real(y));
xlabel('n------->');
ylabel('Amplitude');
title('(REAL part) FFt of sequence');
subplot(4,1,3);
stem(n,imag(y));
28
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
xlabel('n------->');
ylabel('Amplitude');
title('(IMAG part) FFt of sequence');
X=ifft(y,n1)
disp('IFFt of sequence is');
disp(i);
n = 0:n1-1;
subplot(4,1,4);
stem(n,X);
xlabel('n------->');
ylabel('Amplitude');
title('IFFt of sequence');
29
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Input :
Output :
30
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
RESULT:
DFT and IDF of given sequences is performed and output is verified theoretically and
practically using MATLAB
31
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
32
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO – 5
FREQUENCY RESPONSE OF SYSTEM IN DIFFERENTIAL
EQUATION FORM
Aim:
To plot & observe the frequency response of a system given in difference equation form.
EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.
THEORY:
Given an LTI difference equation describing a filter, it is easy to analytically find an expression
for the frequency response. Recall that if the input x is a complex exponential, then the
output y will be the same complex exponential scaled by the frequency response evaluated at
the frequency of the complex exponential.
x(n) = e jωn.
where H(ω) is the frequency response evaluated at the frequency ω. Plugging the form of the
input and output into the difference equation we get
H(ω) e jωn (a1 + a2 e -jω + a3 e -2jω)
= e jωn (b1 + b2 e -jω + b3 e -2jω).
33
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
This form of the frequency response can be generalized to LTI difference equations with an
arbitrary number of terms.
Algorithm :
Step : 1 Get/Read the numerator coefficients to b.
Step : 4 Find out the frequency response using function freqz and store it into g.
PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window
2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.
PROGRAM :
clc;
clear all;
close all;
b=input('Enter the numerator coefficients: ');
a=input('Enter the denominator coefficients: ');
34
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
w=-pi:0.01:pi;
g=freqz(b,a,w);
subplot(2,1,1);
plot(w,abs(g));
xlabel('Normalized Frequency');
ylabel('Magnitude');
title('Magnitude-Frequency Response:');
subplot(2,1,2);
plot(w,angle(g));
xlabel('Normalized Frequency');
ylabel('Phase');
title('Phase-Frequency Response');
Input :
35
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Output :
RESULT:
36
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
37
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO – 6
38
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
THEORY:
A Power Spectral Density (PSD) is the measure of signal's power content versus
frequency. A PSD is typically used to characterize broadband random signals. The amplitude of
the PSD is normalized by the spectral resolution employed to digitize the signal.
Consider a WSS random process X(t) with autocorrelation function RX(τ). We define the
Power Spectral Density (PSD) of X(t) as the Fourier transform of RX(τ). We show the PSD of X(t),
by SX(f). More specifically, we can write
∞
From this definition, we can conclude that RX(τ) can be obtained by the inverse Fourier
transform of SX(f). That is
∞
RX(τ)=F−1{SX(f)}= ∫ ❑ S X (f )e 2 jπfτ df .
−∞
As we have seen before, if X(t) is a real-valued random process, then RX(τ) is an even, real-
valued function of τ. From the properties of the Fourier transform, we conclude that SX(f) is
also real-valued and an even function of f. Also, from what we will discuss later on, we can
conclude that SX(f) is non-negative for all f.
Before going any further, let's try to understand the idea behind the PSD. To do so, let's choose
τ=0. We know that expected power in X(t) is given by
∞ ∞
39
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
We conclude that the expected power in X(t) can be obtained by integrating the PSD of X(t).
This fact helps us to understand why SX(f) is called the power spectral density. In fact, as we will
see shortly, we can find the expected power of X(t) in a specific frequency range by integrating
the PSD over that specific range.
Algorithm :
Step : 1 Get/Read the samples of x[n] to N.
Step : 3 Define a for loop for 1 to N and store sinusoidal signal for different N values to X.
Step : 5 Find the Auto Correlation using sum=sum+(X(k)*X(k+n-1)) and store it to y(n).
Step : 7 Find the fft of the signal y and plot the magnitude and phase Response.
PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window
2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.
40
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
PROGRAM :
clc;
clear all;
close all;
N=input('Enter the N value: ');
f=input('Enter the Frequency: ');
for n=1:N
X(n)=sin((2*pi*f*n)/N);
end
subplot(4,1,1);
plot(X);
title('Input Sequence');
xlabel('N');
ylabel('Amplitude');
for n=1:1:N
sum=0;
for k=1:1:N-n+1
sum=sum+(X(k)*X(k+n-1));
end
y(n)=sum;
end
display(y(n));
subplot(4,1,2);
plot(y);
title('Auto Correlation');
xlabel('Time');
ylabel('Amplitude');
41
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
n=0:1:N-1;
y1=fft(y);
subplot(4,1,3);
plot(n,abs(y1));
title('PSD Magnitude Response');
xlabel('Frequency');
ylabel('Amplitude');
subplot(4,1,4);
plot(n,angle(y1));
title('PSD Phase Response');
xlabel('Frequency');
ylabel('Amplitude');
42
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Input :
Output :
43
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
RESULT:
Hence the power density spectrum of given input signal is observed.
44
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
45
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO – 7
DESIGN OF IIR LOW PASS FILTER
Aim:
To design an IIR low pass filter using Butterworth & Chebyshev approximation.
EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.
THEORY:
BUTTERWORTH FILTER :-
The Butterworth filter has a maximally flat response that is, no passband ripple and roll-
off of minus 20db per pole. It is “flat maximally magnitude” filters at the frequency of jω= 0, as
the first 2N - 1 derivatives of the transfer function when jω = 0 are equal to zero [5]. The phase
response of the Butterworth filter becomes more nonlinear with increasing N. This filter is
completely defined mathematically by two parameters; they are cut off frequency and number
of poles.
Filter Selectivity,
Attenuation,
CHEBYSHEV FILTER :-
46
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
The absolute difference between the ideal and actual frequency response over the entire pass
band is minimized by Chebyshev Type I filter by incorporating equal ripple in the pass band.
Stop band response is maximally flat. The transition from pass band to stop band is more rapid
than for the Butterworth filter. The magnitude squared Chebyshev response is:
Algorithm :
Step : 1 Get/Read the sampling frequency.
Step : 2 Get/Read the pass band frequency and multiply the pass band frequency by 2 and
divide by sampling frequency.
Step : 3 Get/Read the stop band frequency and multiply the stop band frequency by 2 and
divide by sampling frequency.
Step : 5 create a Butterworth filter using the inbuilt function buttord and butter.
Step : 8 create a chebyshev filter using the inbuilt function cheb1ord and cheby1.
47
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window
2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.
PROGRAM :
clc;
clear all;
close all;
fs=input('enter the sampling frequency');
wpa=input('enter the passband frequency');
wp=2*wpa/fs;
wsa=input('enter the stopband frequency');
ws=2*wsa/fs;
rp=input('enter the passband attenuation');
rs=input('enter the stopband attenuation');
[n,wn]=buttord(wp,ws,rp,rs);
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,w]=freqz(b,a,w);
48
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
m=20*log10(abs(h));
an=angle(h);
subplot(3,2,1);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('butter magn response');
grid on;
subplot(3,2,2);
plot(w/pi,an);
xlabel('normalized frequency');
ylabel('phase');
title('butter phase response');
grid on;
[n,wp]=cheb1ord(wp,ws,rp,rs);
[b,a]= cheby1(n,5,wp);
w=0:0.01:pi;
[h,w]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(3,2,3);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('cheby1 magn response');
grid on;
subplot(3,2,4);
plot(w/pi,an);
49
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
xlabel('normalized frequency');
ylabel('phase');
title('cheby1 phase response');
grid on;
[n,ws]=cheb2ord(wp,ws,rp,rs);
[b,a]= cheby2(n,5,ws);
w=0:0.01:pi;
[h,w]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(3,2,5);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('cheby2 magn response');
grid on;
subplot(3,2,6);
plot(w/pi,an);
xlabel('normalized frequency');
ylabel('phase');
title('cheb2 phase response');
grid on;
50
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Input :
Output :
51
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
RESULT:
Hence an IIR low pass filter is designed and its response is observed.
52
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
53
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO – 8
DESIGN OF IIR HIGH PASS FILTER
Aim:
To design an IIR high pass filter using Butterworth & Chebyshev approximation.
EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.
THEORY:
The infinite impulse response (IIR) filter is a recursive filter in that the output from the filter is
computed by using the current and previous inputs and previous outputs.
Because the filter uses previous values of the output, there is feedback of the output in the
filter structure. The design of the IIR filter is based on identifying the pulse transfer function
G(z) that satisfies the requirements of the filter specification. This can be undertaken either by
developing an analogue prototype and then transforming it to the pulse transfer function, or by
designing directly in digital.
BUTTERWORTH FILTER :-
The Butterworth filter has a maximally flat response that is, no passband ripple and roll-
off of minus 20db per pole. It is “flat maximally magnitude” filters at the frequency of jω= 0, as
the first 2N - 1 derivatives of the transfer function when jω = 0 are equal to zero [5]. The phase
response of the Butterworth filter becomes more nonlinear with increasing N. This filter is
completely defined mathematically by two parameters; they are cut off frequency and number
of poles.
Filter Selectivity,
54
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Attenuation,
CHEBYSHEV FILTER :-
The absolute difference between the ideal and actual frequency response over the entire pass
band is minimized by Chebyshev Type I filter by incorporating equal ripple in the pass band.
Stop band response is maximally flat. The transition from pass band to stop band is more rapid
than for the Butterworth filter. The magnitude squared Chebyshev response is:
Algorithm :
Step : 1 Get/Read the sampling frequency.
Step : 2 Get/Read the pass band frequency and multiply the pass band frequency by 2 and
divide by sampling frequency.
Step : 3 Get/Read the stop band frequency and multiply the stop band frequency by 2 and
divide by sampling frequency.
55
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Step : 5 create a Butterworth filter using the inbuilt function buttord and butter.
Step : 8 create a chebyshev filter using the inbuilt function cheb1ord and cheby1.
PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window
2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.
PROGRAM :
clc;
clear all;
close all;
fs=input('enter the sampling frequency');
wpa=input('enter the passband frequency');
wp=2*wpa/fs;
wsa=input('enter the stopband frequency');
ws=2*wsa/fs;
rp=input('enter the passband attenuation');
rs=input('enter the stopband attenuation');
[n,wn]=buttord(wp,ws,rp,rs);
[b,a]=butter(n,wn,'high');
w=0:0.01:pi;
56
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
[h,w]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(3,2,1);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('butter magn response');
grid on;
subplot(3,2,2);
plot(w/pi,an);
xlabel('normalized frequency');
ylabel('phase');
title('butter phase response');
grid on;
[n,wp]=cheb1ord(wp,ws,rp,rs);
[b,a]= cheby1(n,5,wp,'high');
w=0:0.01:pi;
[h,w]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(3,2,3);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('cheby1 magn response');
grid on;
subplot(3,2,4);
plot(w/pi,an);
xlabel('normalized frequency');
57
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
ylabel('phase');
title('cheby1 phase response');
grid on;
[n,ws]=cheb2ord(wp,ws,rp,rs);
[b,a]= cheby2(n,5,ws,'high');
w=0:0.01:pi;
[h,w]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(3,2,5);
plot(w/pi,m);
xlabel('normalized frequency');
ylabel('magnitude');
title('cheby2 magn response');
grid on;
subplot(3,2,6);
plot(w/pi,an);
xlabel('normalized frequency');
ylabel('phase');
title('cheb2 phase response');
grid on;
58
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Input :
Output :
59
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
RESULT:
Hence an IIR high pass filter is designed and its response is observed.
60
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
61
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO – 9
DESIGN OF FIR LOW PASS FILTER
Aim:
To design an FIR low pass filter using windowing technique.
EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.
THEORY:
In digital signal processing, an FIR is a filter whose impulse response is of finite period, as
a result of it settles to zero in finite time. This is often in distinction to IIR filters, which can have
internal feedback and will still respond indefinitely. The impulse response of an Nth order
discrete time FIR filter takes precisely N+1 samples before it then settles to zero. FIR filters
are most popular kind of filters executed in software and these filters can be continuous time,
analog or digital and discrete time. Special types of FIR filters are namely, Boxcar, Hilbert
Transformer, Differentiator, Lth-Band and Raised-Cosine.
FIR filter design based on windows is simple and robust, however, it is not optimal. The
resulting pass-band and stop-band parameters are equal even though often the specification is
more strict in the stop band than in the pass band unnecessary high accuracy in the pass band.
The ripple of the window is not uniform (decays as we move away from discontinuity points
according to side-lobe pattern of the window) by allowing more freedom in the ripple
behaviour we may be able to reduce filter’s order and hence its complexity.
Algorithm :
Step : 1 Get/Read the sampling frequency.
62
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Step : 2 Get/Read the pass band frequency and multiply the pass band frequency by 2 and
divide by sampling frequency.
Step : 3 Get/Read the stop band frequency and multiply the stop band frequency by 2 and
divide by sampling frequency.
Step : 5 create a rectangular window filter using the inbuilt function rectwin.
Step : 8 create a hamming window filter using the inbuilt function hamming.
Step : 10 create a hanning window filter using the inbuilt function hann.
Step : 12 create a barlett window filter using the inbuilt function barlett.
Step : 14 create a blackman window filter using the inbuilt function blackman.
PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window
2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.
PROGRAM :
63
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
clc;
clear all;
close all;
fp=input('enter the pass band frequency');
fs=input('enter the stop band frequency');
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
f=input('enter the sampling frequency');
wp=2*(fp/f);
ws=2*(fs/f);
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*((fs-fp)/f);
n=ceil(num/den);
%n=abs(n);
if(rem(n,2)~=0)
n1=n;
n=n-1;
else
n1=n+1;
end
%rectangle
y1=rectwin(n1);
wn=(wp+ws)/2;
b=fir1(n,wn,'low',y1);
w=0:0.01:pi;
[h1,w]=freqz(b,1,w);
magnitude1=(abs(h1));
phase1=angle(h1);
%hamming
y2=hamming(n1);
64
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
b=fir1(n,wp,'low',y2);
w=0:0.01:pi;
[h2,w]=freqz(b,1,w);
magnitude2=(abs(h2));
phase2=angle(h2);
%hanning
y3=hann(n1);
b=fir1(n,wp,'low',y3);
w=0:0.01:pi;
[h3,w]=freqz(b,1,w);
magnitude3=(abs(h3));
phase3=angle(h3);
%barlett
y4=bartlett(n1);
b=fir1(n,wp,'low',y4);
w=0:0.01:pi;
[h4,w]=freqz(b,1,w);
magnitude4=(abs(h4));
phase4=angle(h4);
%blackman
y5=blackman(n1);
b=fir1(n,wp,'low',y5);
w=0:0.01:pi;
[h5,w]=freqz(b,1,w);
magnitude5=(abs(h5));
phase5=angle(h5);
%kaiser
y6=kaiser(n1);
b=fir1(n,wp,'low',y6);
w=0:0.01:pi;
65
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
[h6,w]=freqz(b,1,w);
magnitude6=(abs(h6));
phase6=angle(h6);
subplot(3,2,1);
plot(w/pi,magnitude1);
xlabel('normalized frequency');
ylabel('magnitude');
title('rectangular window');
subplot(3,2,2);
plot(w/pi,magnitude2);
xlabel('normalized frequency');
ylabel('magnitude');
title('hamming window');
subplot(3,2,3);
plot(w/pi,magnitude3);
xlabel('normalized frequency');
ylabel('magnitude');
title('hanning window');
subplot(3,2,4);
plot(w/pi,magnitude4);
xlabel('normalized frequency');
ylabel('magnitude');
title('barlett window');
subplot(3,2,5);
plot(w/pi,magnitude5);
xlabel('normalized frequency');
ylabel('magnitude');
title('blackman window');
subplot(3,2,6);
plot(w/pi,magnitude6);
66
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
xlabel('normalized frequency');
ylabel('magnitude');
title('kaiser window');
figure;
subplot(3,2,1);
plot(w/pi,phase1);
xlabel('normalized frequency');
ylabel('phase');
title('rectangular window');
subplot(3,2,2);
plot(w/pi,phase2);
xlabel('normalized frequency');
ylabel('phase');
title('hamming window');
subplot(3,2,3);
plot(w/pi,phase3);
xlabel('normalized frequency');
ylabel('phase');
title('hanning window');
subplot(3,2,4);
plot(w/pi,phase4);
xlabel('normalized frequency');
ylabel('phase');
title('barlett window');
subplot(3,2,5);
plot(w/pi,phase5);
xlabel('normalized frequency');
ylabel('phase');
title('blackman window');
subplot(3,2,6);
67
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
plot(w/pi,phase6);
xlabel('normalized frequency');
ylabel('phase');
title('kaiser window');
Input :
Output :
68
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
RESULT:
Hence an FIR Low pass filter is designed and its response is observed.
69
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
70
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO – 10
DESIGN OF HIGH LOW PASS FILTER
Aim:
To design an FIR High pass filter using windowing technique.
EXPERIMENTAL REQUIREMENTS :
A PC loaded with MATLAB software.
THEORY:
In digital signal processing, an FIR is a filter whose impulse response is of finite period, as
a result of it settles to zero in finite time. This is often in distinction to IIR filters, which can have
internal feedback and will still respond indefinitely. The impulse response of an Nth order
discrete time FIR filter takes precisely N+1 samples before it then settles to zero. FIR filters
are most popular kind of filters executed in software and these filters can be continuous time,
analog or digital and discrete time. Special types of FIR filters are namely, Boxcar, Hilbert
Transformer, Differentiator, Lth-Band and Raised-Cosine.
FIR filter design based on windows is simple and robust, however, it is not optimal. The
resulting pass-band and stop-band parameters are equal even though often the specification is
more strict in the stop band than in the pass band unnecessary high accuracy in the pass band.
The ripple of the window is not uniform (decays as we move away from discontinuity points
according to side-lobe pattern of the window) by allowing more freedom in the ripple
behaviour we may be able to reduce filter’s order and hence its complexity.
Algorithm :
Step : 1 Get/Read the sampling frequency.
Step : 2 Get/Read the pass band frequency and multiply the pass band frequency by 2 and
divide by sampling frequency.
71
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Step : 3 Get/Read the stop band frequency and multiply the stop band frequency by 2 and
divide by sampling frequency.
Step : 5 create a rectangular window filter using the inbuilt function rectwin.
Step : 8 create a hamming window filter using the inbuilt function hamming.
Step : 10 create a hanning window filter using the inbuilt function hann.
Step : 12 create a barlett window filter using the inbuilt function barlett.
Step : 14 create a blackman window filter using the inbuilt function blackman.
PROCEDURE:
1) Click on the MATLAB icon on the desktop (or go to Start – All programs and click on MATLAB)
to get into the Command Window
2) Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
6) Result is displayed in the Command window and the graphical output is displayed in the
Figure Window.
72
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
PROGRAM :
clc;
clear all;
close all;
fp=input('enter the pass band frequency');
fs=input('enter the stop band frequency');
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
f=input('enter the sampling frequency');
wp=2*(fp/f);
ws=2*(fs/f);
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*((fp-fs)/f);
n=ceil(num/den);
%n=abs(n);
if(rem(n,2)~=0)
n1=n;
n=n-1;
else
n1=n+1;
end
%rectangle
y1=rectwin(n1);
wn=(wp+ws)/2;
b=fir1(n,wn,'high',y1);
w=0:0.01:pi;
73
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
[h1,w]=freqz(b,1,w);
magnitude1=(abs(h1));
phase1=angle(h1);
%hamming
y2=hamming(n1);
b=fir1(n,wp,'high',y2);
w=0:0.01:pi;
[h2,w]=freqz(b,1,w);
magnitude2=(abs(h2));
phase2=angle(h2);
%hanning
y3=hann(n1);
b=fir1(n,wp,'high',y3);
w=0:0.01:pi;
[h3,w]=freqz(b,1,w);
magnitude3=(abs(h3));
phase3=angle(h3);
%barlett
y4=bartlett(n1);
b=fir1(n,wp,'high',y4);
w=0:0.01:pi;
[h4,w]=freqz(b,1,w);
magnitude4=(abs(h4));
phase4=angle(h4);
%blackman
y5=blackman(n1);
b=fir1(n,wp,'high',y5);
w=0:0.01:pi;
[h5,w]=freqz(b,1,w);
magnitude5=(abs(h5));
74
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
phase5=angle(h5);
%kaiser
y6=kaiser(n1);
b=fir1(n,wp,'high',y6);
w=0:0.01:pi;
[h6,w]=freqz(b,1,w);
magnitude6=(abs(h6));
phase6=angle(h6);
subplot(3,2,1);
plot(w/pi,magnitude1);
xlabel('normalized frequency');
ylabel('magnitude');
title('rectangular window');
subplot(3,2,2);
plot(w/pi,magnitude2);
xlabel('normalized frequency');
ylabel('magnitude');
title('hamming window');
subplot(3,2,3);
plot(w/pi,magnitude3);
xlabel('normalized frequency');
ylabel('magnitude');
title('hanning window');
subplot(3,2,4);
plot(w/pi,magnitude4);
xlabel('normalized frequency');
ylabel('magnitude');
title('barlett window');
subplot(3,2,5);
plot(w/pi,magnitude5);
75
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
xlabel('normalized frequency');
ylabel('magnitude');
title('blackman window');
subplot(3,2,6);
plot(w/pi,magnitude6);
xlabel('normalized frequency');
ylabel('magnitude');
title('kaiser window');
figure;
subplot(3,2,1);
plot(w/pi,phase1);
xlabel('normalized frequency');
ylabel('phase');
title('rectangular window');
subplot(3,2,2);
plot(w/pi,phase2);
xlabel('normalized frequency');
ylabel('phase');
title('hamming window');
subplot(3,2,3);
plot(w/pi,phase3);
xlabel('normalized frequency');
ylabel('phase');
title('hanning window');
subplot(3,2,4);
plot(w/pi,phase4);
xlabel('normalized frequency');
ylabel('phase');
title('barlett window');
subplot(3,2,5);
76
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
plot(w/pi,phase5);
xlabel('normalized frequency');
ylabel('phase');
title('blackman window');
subplot(3,2,6);
plot(w/pi,phase6);
xlabel('normalized frequency');
ylabel('phase');
title('kaiser window');
77
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Input :
Output :
78
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
RESULT:
Hence an FIR High pass filter is designed and its response is observed.
79
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
80
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO: 11
LINEAR CONVOLUTION USING CODE COMPOSER STUDIO
AIM:
To perform Linear Convolution of two sequences using code composer studio.
EXPERIMENTAL REQUIREMENTS:
1. A PC loaded with Code composer studio.
2. TMS320C6713 kit.
THEORY:
Convolution
Convolution is a mathematical operation used to express the relation between input and
output of an LTI system. It relates input, output and impulse response of an LTI system as
y (t) = x(t) * h(t)
Where y (t )= output of LTI
x (t) = input of LTI
h (t) = impulse response of LTI
There are two types of convolutions:
● Continuous convolution
● Discrete convolution
Continuous Convolution
81
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
Discrete Convolution
82
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
ALGORITHM :
Step : 1 Get/Read the samples of x[n] to x.
Step : 2 Get/Read the samples of h[n] to h.
Step : 3 Get/Read the length of x to m.
Step : 4 Get/Read the length of h to n.
Step : 5 Use 2 for loops and repeat it upto m+n-1.
Step : 6 Determine the convolution of x and h using
y[n] = ∑ X(k) H(n-k).
Step : 7 Plot the graph of y[n].
PROCEDURE:
1. Open CC Studio by clicking on the icon.
2. Go to file, click on new cc project for creating new file.
3. Select target as C671X floating point DSP.
4. In connections, select spectrum digital DSK-EVM-ezdsp onboard USB emulator.
5. Name the project and click on finish.
6. Write the program, and save the file.
7. To check whether some space has been created in stack memory or not, go to
properties in select project and select C600 linker and click on basic options and then
click ok.
8. Then build the program by clicking on the hammer symbol.
9. Click on the user defined on right side. Select new target configuration and then
select launch select configuration.
10. Go to Run and Connect target.
11. If the kit is not connected, it will display as disconnected otherwise no issues.
12. Again go to Run, click on load and select load program.
13. Select our project and click on debug and select output file and then press ok.
14. Then go to run and click on resume or press F8 to start execution.
15. Give the required inputs and observe the output.
16. For graphs, go to view and click on expressions.
17. Right click on output and select graph.
18. To convert continous signal into digital, go to graph properties.
19. Then click on style and select Bar.
20. Then note down the output waveforms and values.
PROGRAM:
83
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
#include<stdio.h>
int x[15],h[15],y[15];
main()
{
int i,j,m,n;
printf(“\n enter value for m :”);
scanf(“%d”,&m);
printf(“\n enter value for n :”);
scanf(“%d”,&n);
printf(“\n enter value for input x[n] ”);
for(i=0;i<m;i++)
scanf(“%d”,&x[i]);
printf(“\n enter value for input h[n] ”);
for(i=0;i<n;i++)
scanf(“%d”,&h[i]);
//padding zeroes
for(i=m;i<m+n-1;i++)
{
x[i]=0;
}
for(i=n;i<m+n-1;i++)
{
h[i]=0;
}
//Convolution operation
for(i=0;i<m+m-1;i++)
{
84
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]= y[i] + (x[j] * h[i-j]);
}
}
//Displaying output
for(i=0;i<m+n-1;i++)
{
printf(“\n The value of output y[%d] = %d”,i,y[i]);
}
}
OBSERVATIONS:
RESULT:
Linear Convolution of two sequences is performed and output is verified using code
composer studio.
85
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
86
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO: 12
THEORY :
x[n] and h[n] are two finite sequences of length N with DFTs denoted by X[k] and H[k],
respectively. Let us form the product
W[k] = X[k]H[k],
and determine the sequence w[n] of length N for which the DFT is W[k].
First, extend x[n] and h[n] to periodic sequences with period N, x h ˜[n] and [n], respectively. ˜
Then, the periodic convolution of x h ˜[n] and [n] corresponds to multiplication of the
corresponding periodic sequences of Fourier series coefficients.
N −1
¿ ∑ ❑ x [m] h[((n−m))N ]
m =0
87
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
ALGORITHM:
Step : 1 Get/Read the samples of x[n] to x.
Step : 2 Get/Read the samples of h[n] to h.
Step : 3 Get/Read the length of x to m.
Step : 4 Get/Read the length of h to n.
Step : 5 If m is greater than n, then padding of zeros is done on h(n) and zeros are ranging from
1 to (m – n).
Step : 6 If n is greater than m, then padding of zeros is done on x(n) and zeros are ranging from 1
to (n – m).
Step : 7 Use 2 for loops to determine convolution.
Step : 8 Determine the convolution of x and h using
y[n] = x[n] h[n].
Step : 9 Plot the graph of y[n].
PROCEDURE:
1. Open CC Studio by clicking on the icon.
2. Go to file, click on new cc project for creating new file.
3. Select target as C671X floating point DSP.
4. In connections, select spectrum digital DSK-EVM-ezdsp onboard USB emulator.
5. Name the project and click on finish.
6. Write the program, and save the file.
7. To check whether some space has been created in stack memory or not, go to
properties in select project and select C600 linker and click on basic options and then
click ok.
8. Then build the program by clicking on the hammer symbol.
9. Click on the user defined on right side. Select new target configuration and then
select launch select configuration.
10. Go to Run and Connect target.
11. If the kit is not connected, it will display as disconnected otherwise no issues.
12. Again go to Run, click on load and select load program.
13. Select our project and click on debug and select output file and then press ok.
14. Then go to run and click on resume or press F8 to start execution.
15. Give the required inputs and observe the output.
16. For graphs, go to view and click on expressions.
17. Right click on output and select graph.
18. To convert continous signal into digital, go to graph properties.
19. Then click on style and select Bar.
20. Then note down the output waveforms and values.
88
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
PROGRAM:
#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0) /*If length of both sequences are not equal*/
{
if(m>n) /* Pad the smaller sequence with zero*/
{
for(i=n;i<m;i++)
{
h[i]=0;
n=m;
}
}
for(i=m;i<n;i++)
{
89
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
x[i]=0;
m=n;
}
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++) /*folding h(n) to h(-n)*/
a[j]=h[n-j];
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
printf(" the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);
}
OBSERVATIONS:
90
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
RESULT:
Circular Convolution of given sequences is performed and output is verified using code
composer studio.
91
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
92
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
EXPERIMENT NO: 13
GENERATION OF SINE AND SQUARE WAVEFORMS USING
CODE COMPOSER STUDIO
AIM:
To generate Sine and square waveforms using Code Composer Studio.
EXPERIMENTAL REQUIREMENTS:
1. A PC loaded with Code composer studio.
2. TMS320C6713 kit.
THEORY:
Sinusoidal signal:
A signal, which is continuous in nature is known as continuous signal. General format of a
sinusoidal signal is
x(t)=Asin(ωt+ϕ)
Here,
A = amplitude of the signal
ω = Angular frequency of the signal Measured in radians
φ = Phase angle of the signal Measured in radians
The tendency of this signal is to repeat itself after certain period of time, thus is called periodic
signal. The time period of signal is given as;
T=2πω
93
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
A continuous-time signal x(t) is said to be periodic with period T if it satisfy the condition
A signal is periodic if the above condition is not satisfied for at least one value of T.
The smallest value of T that satisfies the above condition is known as fundamental period.
Complex exponential and sinusoidal signals are examples for continuous time periodic signals.
Consider a sinusoidal signal.
x(t)=Asin(wt+θ)
Where A is the amplitude, w is the frequency in radians per second (rad/sec), and θ the phase
in radians. The frequency f0 in hertz is given by f0 = w /2π or periodic signal we have
X(t+T)=x(t)
For x(t)=Asin(wt+θ)
= Asin[wt+wT+θ]
wT = 2π , T =2π/ w
94
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
ALGORITHM:
For Sine wave:
Step : 1 Get/Read the frequency f.
Step : 2 Get/Read number of samples n.
Step : 3 Use a for loop to generate a sinusoidal signal.
For Square wave:
Step : 1 Get/Read the frequency f.
Step : 2 Use a for loop to generate a Square waveform
Step : 3 If ((i*2)/f)%2==0, set value of y as 1 else set as -1.
PROCEDURE:
1. Open CC Studio by clicking on the icon.
2. Go to file, click on new cc project for creating new file.
3. Select target as C671X floating point DSP.
4. In connections, select spectrum digital DSK-EVM-ezdsp onboard USB emulator.
5. Name the project and click on finish.
6. Write the program, and save the file.
7. To check whether some space has been created in stack memory or not, go to
properties in select project and select C600 linker and click on basic options and
then click ok.
8. Then build the program by clicking on the hammer symbol.
9. Click on the user defined on right side. Select new target configuration and then
select launch select configuration.
10. Go to Run and Connect target.
11. If the kit is not connected, it will display as disconnected otherwise no issues.
12. Again go to Run, click on load and select load program.
13. Select our project and click on debug and select output file and then press ok.
14. Then go to run and click on resume or press F8 to start execution.
15. Give the required inputs and observe the output.
16. For graphs, go to view and click on expressions.
17. Right click on output and select graph.
18. To convert continous signal into digital, go to graph properties.
19. Then click on style and select Bar.
20. Then note down the output waveforms and values.
PROGRAMS:
/*Sine wave generation*/
#include<stdio.h>
#include<math.h>
#define pi 3.14
float y[500];
95
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
void main()
{
int t,f,n;
printf("enter the frequency");
scanf("%d",&f);
printf("enter the n value");
scanf("%d",&N);
for(t=0;t<=500;t++)
y[t]=sin(2*pi*f*t/N);
}
96
Digital signal processing lab
DATE: Prasad V Potluri Siddhartha institute of technology
RESULT:
Sinusoidal and square waveforms are generated using Code Composer Studio.
97
Digital signal processing lab