0% found this document useful (0 votes)
24 views74 pages

DSP-Manual - R19

This experiment involves calculating the discrete Fourier transform (DFT) and inverse discrete Fourier transform (IDFT) of a discrete-time signal. The student is asked to take an input sequence, use the direct equations to calculate the DFT and IDFT, and then plot the original, DFT, and IDFT sequences to observe the transformations between the time and frequency domains. Calculating the DFT and IDFT helps introduce these important signal processing concepts and tools.

Uploaded by

Ragha Ramoju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views74 pages

DSP-Manual - R19

This experiment involves calculating the discrete Fourier transform (DFT) and inverse discrete Fourier transform (IDFT) of a discrete-time signal. The student is asked to take an input sequence, use the direct equations to calculate the DFT and IDFT, and then plot the original, DFT, and IDFT sequences to observe the transformations between the time and frequency domains. Calculating the DFT and IDFT helps introduce these important signal processing concepts and tools.

Uploaded by

Ragha Ramoju
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 74

(19PC2EC06) DIGITAL SIGNAL PROCESSING

LABORATORY REGULATION: R19


VNR Vignana Jyothi Institute of Engineering and Technology

III Year B.Tech ECE – V Sem L T/P/D C


0 3 1.5
COURSE PRE-REQUISITES: Signal and Systems
COURSE OBJECTIVES: Simulation and implementation on DSP processor
• To verify properties of a discrete system
• To learn various transforms on digital signals
• To understand the design of digital filters
• To verify basic properties of multirate systems
COURSE OUTCOMES: after completion of the course, the student should be able to
CO-1: Analyze the effect of various transformations on discrete signals
CO-2: Design digital filters for the given specifications
CO-3: Design multi rate signal processing of signals through systems
CO-4: Implement real-time applications

The following experiments are to be performed using appropriate Software At least 3


experiments are to be implemented using model-based design

1. Circular Convolution
2. Discrete Fourier Transform / Inverse Discrete Fourier Transform
3. Power Density Spectrum
4. Implementation of Filters using IIR
5. Implementation of Filters using FIR
6. Generation of Sinusoidal signal through filtering
7. Generation of DTMF Signals
8. Implementation of Decimation and Interpolation processes, I/D sampling Rate Converters.

The following Experiments are to be performed using Code Composer Studio


a) Introduction to Code Composer Studio
b) Procedure to Work on CCS
1. To Verify Linear Convolution.
2. To Verify Circular Convolution.
3. Real-time Implementation of FIR (Low Pass/High Pass) using Rectangular, Triangular,
Hanning, Kaiser Windowing techniques.
4. Real-time Implementation of IIR Filter (Low Pass and High pass).
5. To find the FFT of given 1-D signal.
6. To compute Power Density Spectrum (PDS) of a sequence and signal.
7. Real-time audio applications such as audio effects, Interpolation, Decimation effects

S.NO. EXPERIMENT PAGE NO.

1
Experiments performed using MATLAB

1 Circular Convolution 3

2 Discrete Fourier Transform / Inverse Discrete Fourier 6


Transform
3 Power Density Spectrum 9

4 Implementation of Filters using IIR 13

5 Implementation of Filters using FIR 18

6 Generation of Sinusoidal signal through filtering 26

7 Generation of DTMF Signals 29

8 Implementation of Decimation and Interpolation processes, 33


I/D sampling Rate Converters

The following experiments performed using Code Composer Studio

9 To Verify Linear Convolution 50

10 To Verify Circular Convolution 52

11 Real-time Implementation of FIR (Low Pass/High Pass) 56


using Rectangular, Triangular, Hanning, Kaiser Windowing
techniques

12 Real-time Implementation of IIR Filter (Low Pass and High 60


pass)

13 To find the FFT of given 1-D signal 63

14 To compute Power Density Spectrum (PDS) of a sequence 67


and signal

2
1. CIRCULAR CONVOLUTION
Purpose of Experiment

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˜[n] and h˜[n], respectively.
Then, the periodic convolution of x˜[n] and h˜[n] corresponds to multiplication of the
corresponding periodic sequences of Fourier series coefficients
N−1
~ ~ ~ ~ ~
w [ n ]= ∑ ~
x [n] h [n−m] W [ k ] = X [ k ] H [k ]
m=0

~
The periodic sequence ~ w [ n ] for which the DFS coefficients are W [ k ] corresponds to the
periodic extension of the finite length sequence w[n] with period N. We can recover w[n] by
extracting one period of ~
w [ n ]:

W[n] = ~
w [ n ] RN [n]
N−1
= ∑ ~x [ m ] ~h[n−m]
m =0

N−1
= ∑ x [ m ] h[((n−m))¿¿ N ]¿
m =0

This operation is called circular convolution and denoted

W[n] = x[n] N h[n]

Methods of Circular Convolution


Generally, there are two methods, which are adopted to perform circular convolution and
they are:

 Concentric circle method,


 Matrix multiplication method.

Concentric Circle Method

Let x1(n) and x2(n) be two given sequences. The steps followed for circular convolution of
x1(n) and x2(n) are
3
 Take two concentric circles. Plot N samples of x1(n) on the circumference of the
outer circle maintaining equal distance between successive points in anti-clockwise
direction.
 For plotting x2(n), plot N samples of x2(n) in clockwise direction on the inner circle,
starting sample placed at the same point as 0th sample of x1(n)
 Multiply corresponding samples on the two circles and add them to get output.
 Rotate the inner circle anti-clockwise with one sample at a time.

Matrix Multiplication Method

Matrix method represents the two-given sequence x1(n)x1(n) and x2(n)x2(n) in matrix form.
 One of the given sequences is repeated via circular shift of one sample at a time to
form a N X N matrix.
 The other sequence is represented as column matrix.
 The multiplication of two matrices gives the result of circular convolution.

Experimental Steps

ALGORITHM:

Step 1: Start
Step 2: Read the first sequence
Step 3: Read the second sequence
Step 4: Find the length of the first sequence
Step 5: Find the length of the second sequence
Step 6: Make the length of both sequences equal if they are having different length by
padding
zeros at last.
Step 7: Perform circular convolution by using matrix multiplication
Step 8: Display the output sequence
Step 9: Stop

4
STAR

INPUTS: Enter the input


sequences

Index of one of the sequences is


equal to mod of its original
index and total No. of samples

Perform circular convolution


using FFT

STOP

Sample Code
clc; clear all; close all
x=[1 2 3 4]; % Input Sequence
h=[4 3 2 1]; % Impulse response sequence
n=length(x);
c=zeros(1,n);
h1=[h(1) h(end:-1:2)];
for i=1:n
c(i)=x*h1';
h1=[h1(end) h1(1:end-1)];
end

%verification
x1=fft(x,n);
h2=fft(h,n);
p=x1.*h2;
c1=ifft(p);
c1

Expected Outputs

14 16 14 16

5
c1 = 14 16 14 16

2. Discrete Fourier Transform / Inverse Discrete


Fourier Transform
Purpose of Experiment

The purpose of this experiment is to introduce another representation of discrete-time signals,


the discrete Fourier transform (DFT), which is closely related to the discrete-time Fourier
transform, and can be implemented either in digital hardware or in software. The DFT is of
great importance as an efficient method for computing the discrete-time convolution of two
signals, as a tool for filter design, and for measuring spectra of discrete-time signals. While
computing the DFT of a signal is generally easy (requiring no more than the execution of a
simple program) the interpretation of these computations can be difficult because the DFT
only provides a complete representation of finite-duration signals.

Basic equation to find the DFT of a sequence is given below


N−1
X(k) = ∑ x (n)W nkN k= 0, 1, . . . . , N-1
n =0

− j2 πnk
Where W nk
N = e N = 𝑇𝑤𝑖𝑑𝑑𝑙𝑒 𝑓𝑎𝑐𝑡𝑜r

Basic equation to find the IDFT of a sequence is given below.


N−1 j 2 πkn
1
X(n) =
N ∑ X (k )e N
n=0, 1. . . . . , N-1
k =0

Experimental Steps

Step 1: Start

Step 2: Get the input sequence.

Step 3: Find the DFT of the input sequence using direct equation of DFT.

Step 4: Find the IDFT using the direct equation.

Step 5: Plot DFT and IDFT of the given sequence using matlab command stem.

Step 6: Display the above outputs.

Step: Stop

6
STAR

INPUTS: Enter the


input sequence

Compute DFT using the


standard equation

Plot the input and


output DFT sequences

STOP

Sample Code
%Program to find dft and idft for a given DT signal
clear all;
clc;
x=[1 1 1 1 1 1 1 1]; %Input
Xk=dft(x); %calling function
xhat=idft(Xk); %calling function
subplot(2,1,1)
stem(1:length(x),x)
xlabel('time');
ylabel('amplitude');
title('input signal');
subplot(2,1,2)
stem(1:length(xhat),xhat)
xlabel('time');
ylabel('magnitude');
title('reconstructed signal');

%Calling function for dft

function Xk=dft(x)

7
[N,M]=size(x);
if M~=1
x=x';
N=M;
end
Xk=zeros(N,1);
n=1:N
for k=1:N
Xk(k)=exp(-j*2*pi*k*n/N)*x;
end
%Calling function for idft

function[x]=idft(Xk)
[N,M]=size(Xk);
if M~=1
Xk=Xk';
N=m;
end
x=zeros(N,1);
k=1:N;
for n=1:N
x(n)=exp(j*2*pi*k*n/N)*Xk;
end
x=x/N;

Expected Outputs

8
input signal
1

amplitude

0.5

0
1 2 3 4 5 6 7 8
time
reconstructed signal
1
magnitude

0.5

0
1 2 3 4 5 6 7 8
time

3. Power Density Spectrum


Purpose of Experiment
When the energy of the signal is concentrated around a finite time interval, especially if its
total energy is finite, one may compute the energy spectral density. More commonly used is
the power spectral density (or simply power spectrum), which applies to signals existing
over all time, or over a time period large enough (especially in relation to the duration of a
measurement) that it could as well have been over an infinite time interval. The power
spectral density (PSD) then refers to the spectral energy distribution that would be found per
unit time, since the total energy of such a signal over all time would generally be
infinite. Summation or integration of the spectral components yields the total power (for a
physical process) or variance (in a statistical
process), identical to what would be obtained by integrating x2(t) over the time domain, as
dictated by Parseval's theorem.

Experimental Steps

Algorithm
9
Step 1: Start
Step 2: Get the input sequence.
Step 3: Find the DFT of the input sequence using direct equation of DFT.
Step 4: Obtain complex component DFT sequence.
Step 5: Compute PSD using the product of DFT and its complex component
Step 6: Plot PSD of the given sequence using Matlab command stem.
Step 7: Display the above outputs.
Step: Stop STAR

INPUTS: Enter the input sequence

Compute DFT using the standard equation

Compute absolute value of DFT

Compute the PSD

Plot the input and output PSD sequences

STOP

Sample Code
%implementation of FFT of a given signal or sequence

clear all;
clc;
fs=8000;
f1=1000;
f2=2000;
N=200;
n=0:N-1;
x=sin(2*pi*f1*n/fs)+2*sin(2*pi*2000*n/fs);
xf=abs(fft(x))/N;
power_two=xf.*xf;
f=(0:N-1)*fs/N;
subplot(2,1,1);
plot(f,xf);
xlabel('frequency in hz');
ylabel('magnitude of the spectrum');
10
title(['two sided magnitude spectrum at' , num2str(f1),' and at',num2str(f2),'with
reference to ',num2str(fs/2)]);
subplot(2,1,2);
plot(f,power_two);
xlabel('frequency in hz');
ylabel('power spectrum');
title(['two sided power spectrum at' , num2str(f1),' and t',num2str(f2),'with reference
to ',num2str(fs/2)]);

Expected Outputs

11
two sided magnitude spectrum at1000 and at2000with reference to 4000

magnitude of the spectrum


1

0.5

0
0 1000 2000 3000 4000 5000 6000 7000 8000
frequency in hz
two sided power spectrum at1000 and t2000with reference to 4000
1
power spectrum

0.5

0
0 1000 2000 3000 4000 5000 6000 7000 8000
frequency in hz

%One Sided Magnitude and Power Spectral Density


xf=2*xf;
xf(1)=xf(1)/2;
power_one=xf.*xf;
f=(0:(N-1)/2+1)*fs/N;
figure(2);
subplot(2,1,1)
plot(f,xf(1:N/2+1));
xlabel('frequency in hz');
ylabel('magnetude of spectrum');
title(['one sided magnitute spectrum at',num2str(f1),'ana at',num2str(f2),'with reference to
',num2str(fs/2)]);
subplot(2,1,2)
plot(f,power_one(1:N/2+1));
xlabel('frequency in hz');
ylabel('power spectrum');
title(['one sided magnitute spectrum at',num2str(f1),'ana at',num2str(f2),'with reference to
',num2str(fs/2)]);

12
Expected Outputs

one sided magnitute spectrum at1000ana at2000with reference to 4000


2
magnetude of spectrum

1.5

0.5

0
0 500 1000 1500 2000 2500 3000 3500 4000
frequency in hz
one sided magnitute spectrum at1000ana at2000with reference to 4000
4
power spectrum

0
0 500 1000 1500 2000 2500 3000 3500 4000
frequency in hz

13
4. Implementation of IIR filter for a given input
sequence
Purpose of Experiment

The following parameters are commonly used to specify the frequency response:
2
ϵ : pass band ripple parameter.
δ p: passband deviations
δ s: stop band deviations
f p 1 and f p 2: Passband edge frequencies
f s 1and f s 2: Stopband edge frequencies
The band edge frequencies are sometimes given in normalized form, i.e., a fraction of the sampling
f
frequency .
Fs
Passband and stopband deviations many be expressed as ordinary numbers or in decibels: The
passband ripples in decibels is

A p =10 log 10 ( 1+ ϵ 2) =−20 log 10 (1−δ p )

And the stop band attenuation in decibel is

A s=−20 log 10 (δ s )

Experimental Steps

IIR filter design steps:

1. Determining specifications
2. Design Analog filter according to the specifications.
-Butterworth, Chebyshev, Elliptic, etc.
3. Design digital filter from analog prototypes.
-Impulse invariance, Bilinear transformation, etc.
4. Choosing a realization structure.
- Direct form, Cascade, Parallel, Transpose or Lattice form
5. Implementing the filter-Software implementation (such as MATLAB or C code) or Hardware
implementation (such as a DSP, a microcontroller, or an ASIC)
The rationale behind the design of IIR filter is that there already exist a wealth of information on
analog filters in the literature, which can be utilized. There are two common approaches used to
convert analog filters into equivalent digital filters: (1) Impulse invariant and bilinear transformation
methods. In above design steps, step 3. Implements the mapping from analog to digital.

14
Sample Code

A.) Implementation of High Pass IIR filter for a given input


sequence

clear all;
close all;
clc;
%fs=input('enter the sampling frequency which is greater than twice the max');
fs=8000;
N=1024;
M=2;
n=0:N-1;
f1=500;
f2=2000;
x=3*sin(2*pi*f1*n/fs)+cos(2*pi*f2*n/fs);

%Spectrum of Input
X=2*abs(fft(x,N))/N;
X(1)=X(1)/2;
f=(0:1:N/2-1)*fs/N;

subplot(3,1,1);
plot(f,X(1:N/2));
xlabel('frequency in hz');
ylabel('magnitude');
title(['spectrum of input signal at',num2str(f1), 'and at',num2str(f2)]);

%Specifications of Digital Filter


wp=1500; % passband frequency
ws=1000; % stopband frequency
rp=3; % passband ripple
rs=20; % stopband ripple

%Folding Frequency or Normalized Sampling frequency


fF=fs/2;
%Normalized Analog Butterworth filter frequencies
wpa=wp/fF;
wsa=ws/fF;
[n,wc]=buttord(wpa,wsa,rp,rs); % find butter worth filter order
[b,a]=butter(n,wc,'high'); % design butter worth filter
[H,f_hz]=freqz(b,a,512,fs);
subplot(3,1,2);
plot(f_hz,20*log10(abs(H)));
xlabel('frequency in hz');
15
ylabel('magnitude in db');
title(['butterworth filter of order',num2str(n)]);
grid minor
y=filter(b,a,x); % filter the input signal
y=2*abs(fft(y,N))/N;
y(1)=y(1)/2;
f=(0:N/2-1)*fs/N;
subplot(3,1,3);
plot(f,y(1:N/2));
xlabel('frequency in hz');
ylabel('magnitude');
title([‘Filtered Signal at frequencies above’,num2str(wp)]);

Expected Outputs

spectrum of input signal at500and at2000


magnitude

0
0 500 1000 1500 2000 2500 3000 3500 4000
frequency in hz
butterworth filter of order5
magnitude in db

-100

-200
0 500 1000 1500 2000 2500 3000 3500 4000
frequency in hz
Filtered Signal at frequencies above1500
1
magnitude

0.5

0
0 500 1000 1500 2000 2500 3000 3500 4000
frequency in hz

B.) Implementation of Low Pass IIR filter for a given input sequence
clear all;
close all;
clc;
16
%fs=input('enter the sampling frequency which is greater than twice the max');
fs=8000;
N=1024;
M=2;
n=0:N-1;
f1=500;
f2=2000;
x=3*sin(2*pi*f1*n/fs)+cos(2*pi*f2*n/fs);

%Spectrum of Input
X=2*abs(fft(x,N))/N;
X(1)=X(1)/2;
f=(0:1:N/2-1)*fs/N;

subplot(3,1,1);
plot(f,X(1:N/2));
xlabel('frequency in hz');
ylabel('magnitude');
title(['spectrum of input signal at',num2str(f1), 'and at',num2str(f2)]);

%Specifications of Digital Filter


wp=1500;
ws=1000;
rp=3;
rs=20;

%Folding Frequency or Normalized Sampling frequency


fF=fs/2;

%Normalized Analog Butterworth filter frequencies


wpa=wp/fF;
wsa=ws/fF;
[n,wc]=buttord(wpa,wsa,rp,rs);
[b,a]=butter(n,wc);
[H,f_hz]=freqz(b,a,512,fs);
subplot(3,1,2);
plot(f_hz,20*log10(abs(H)));
xlabel('frequency in hz');
ylabel('magnitude in db');
title(['butterworth filter of order',num2str(n)]);
grid minor
y=filter(b,a,x);
y=2*abs(fft(y,N))/N;
y(1)=y(1)/2;
f=(0:N/2-1)*fs/N;
subplot(3,1,3);
plot(f,y(1:N/2));
xlabel('frequency in hz');
ylabel('magnitude');
17
Expected Outputs

spectrum of input signal at500and at2000


magnitude

0
0 500 1000 1500 2000 2500 3000 3500 4000
frequency in hz
butterworth filter of order5
magnitude in db

-100

-200

0 500 1000 1500 2000 2500 3000 3500 4000


frequency in hz
magnitude

0
0 500 1000 1500 2000 2500 3000 3500 4000
frequency in hz

18
5. Implementation of FIR filter for a given input
sequence
Purpose of Experiment

FIR filter design:

The basis FIR filter is characterized by the following two equations:


N−1
y [ n ] = ∑ h ( k ) x ( n−k ) (1)
k =0

N−1
H [ z ]= ∑ h ( k ) z−k (2)
k=0

Where, h [ k ] , k=0 ,1 , 2 ….. N−1 are the impulse response coefficients of the filter, H ( z ) is
the transfer function of the filter, and N is the filter length.

The output y [ n ] is a function of only past and present values of input x [n]. When FIR filter
are implemented in this form, i.e. by direct evaluation of eq. 1, they are always stable. Eq. 2 is the
transfer function of the filter. It provides a means of analysing the filter, for example evaluating the
frequency response.

Experimental Steps

Steps for FIR filter design:


Digital filter design involves four steps:
1. Determining specifications
-The specifications are: Pass band edge frequency (ω p) , Stop band edge frequency (ω s ),
Pass band ripples (δ ¿¿ p)¿/Pass band attenuation ( A¿¿ p)¿, Stop band ripples (δ s )/Stop
band attenuation ( A¿¿ s)¿.
2. Finding a transfer function.
M −1

∑ b k z−k
k=0
H ( z )= N−1
∑ a k z −k
k=0
This step calculates the coefficients, a k and b k
3. Choosing a realization structure.
- Direct for I, II, Cascade, Parallel, Transpose or Lattice form
4. Implementing the filter-Software implementation (such as MATLAB or C code) or Hardware
implementation (such as a DSP, a microcontroller, or an ASIC)

19
Sample Code

A). Implementation of LP FIR filter for a given input sequence

%program for filtering unwanted low frequency signals using FIR filters
clear all;
close all;
clc;
fs=8000;
n=0:511;
f1=500;f2=1500;f3=2000;
x=sqrt(2)*sin(2*pi*f1*n/fs)+sqrt(3)*sin(2*pi*f2*n/fs)+2*sin(2*pi*f3*n/fs);
subplot(2,1,1);
plot(n,x);
xlabel('time,n');
ylabel('magnitude of input signal');
title('three tone input sinusoidal signal');

%spectrum of input signal

N=length(x);
Mag_x=2*abs(fft(x))/N;
Mag_x(1)=Mag_x(1)/2;
f_Hz=(1:N/2)*fs/N;
subplot(2,1,2);
20
plot(f_Hz,Mag_x(1:N/2));
xlabel('frequency in hz');
ylabel('magnitude of input signal spectrum');
title(['three tone input signal spectrum at frequencies ',num2str(f1),'',num2str(f2),'& at
',num2str(f3)]);

wc_L=2*pi*500/fs;
wc_H=0;
B=firwd(133,1,wc_L,wc_H,4); %Ftype=1 for LPF
filt_x=filter(B,1,x);

figure(2)
subplot(2,1,1);
plot(n,filt_x);
xlabel('time,n');
ylabel('magnitude of filtered signal');
title('magnitude of filtered sinusoidal signal');

Mag_x=2*abs(fft(filt_x))/N;
Mag_x(1)=Mag_x(1)/2;
f_Hz=(1:N/2)*fs/N;

subplot(2,1,2);
plot(f_Hz,Mag_x(1:N/2));
xlabel('frequency in hz');
ylabel('magnitude of filtered signal spectrum');
title('LP signal spectrum');

21
Expected Outputs

three tone input sinusoidal signal


5
magnitude of input signal

-5
0 100 200 300 400 500 600
time,n
magnitude of input signal spectrum

three tone input signal spectrum at frequencies 5001500& at 2000


2

1.5

0.5

0
0 500 1000 1500 2000 2500 3000 3500 4000
frequency in hz

22
magnitude of filtered sinusoidal signal

magnitude of filtered signal spectrum magnitude of filtered signal


1

0.5

-0.5

-1
0 100 200 300 400 500 600
time,n
LP signal spectrum
0.6

0.4

0.2

0
0 500 1000 1500 2000 2500 3000 3500 4000
frequency in hz

B). Implementation of High Pass FIR filter for a given input sequence
%program for filtering unwanted low frequency signals using FIR filters
clear all;
close all;
clc;
fs=8000;
n=0:511;
f1=500;f2=1500;f3=2000;
x=sqrt(2)*sin(2*pi*f1*n/fs)+sqrt(3)*sin(2*pi*f2*n/fs)+2*sin(2*pi*f3*n/fs);
subplot(2,1,1);
plot(n,x);
xlabel('time,n');
ylabel('magnitude of input signal');
title('three tone input sinusoidal signal');

%spectrum of input signal

N=length(x);
Mag_x=2*abs(fft(x))/N;
Mag_x(1)=Mag_x(1)/2;
f_Hz=(1:N/2)*fs/N;
subplot(2,1,2);
plot(f_Hz,Mag_x(1:N/2));
23
xlabel('frequency in hz');
ylabel('magnitude of input signal spectrum');
title(['three tone input signal spectrum at frequencies ',num2str(f1),'',num2str(f2),'& at
',num2str(f3)]);

wc_H=2*pi*1500/fs;
wc_L=0;
B=firwd(133,2,wc_L,wc_H,4); %Ftype=2 for HPF
filt_x=filter(B,1,x);

figure(2)
subplot(2,1,1);
plot(n,filt_x);
xlabel('time,n');
ylabel('magnitude of filtered signal');
title('magnitude of filtered sinusoidal signal');

Mag_x=2*abs(fft(filt_x))/N;
Mag_x(1)=Mag_x(1)/2;
f_Hz=(1:N/2)*fs/N;

subplot(2,1,2);
plot(f_Hz,Mag_x(1:N/2));
xlabel('frequency in hz');
ylabel('magnitude of filtered signal spectrum');
title('HP signal spectrum');

function B=firwd(N, Ftype, WnL,WnH, Wtype)


M=(N-1)/2;
hH=sin(WnH*[-M:1:-1])./([-M:1:-1]*pi);
hH(M+1)=WnH/pi;
hH(M+2:1:N)=hH(M:-1:1);
hL=sin(WnL*[-M:1:-1])./([-M:1:-1]*pi);
hL(M+1)=WnL/pi;
hL(M+2:1:N)=hL(M:-1:1);
if Ftype==1
h(1:N)=hL(1:N);
end
if Ftype==2
h(1:N)=-hH(1:N);
h(M+1)=1+h(M+1);
end
if Ftype==3
h(1:N)=hH(1:N)-hL(1:N);
end
if Ftype==4
h(1:N)=hL(1:N)-hH(1:N);
end
%Window Functions
24
if Wtype==1
w(1:N)=ones(1,N);
end
if Wtype==2
w=1-abs([-M:1:M])/M;
end
if Wtype==3
w=0.5+0.5*cos([-M:1:M]*pi/M);
end
if Wtype==4
w=0.54+0.46*cos([-M:1:M]*pi/M);
end
if Wtype==5
w=0.42+0.5*cos([-M:1:M]*pi/M)+0,08*cos(2*[-M:1:M]*pi/M);
end
B=h.*w;
end

Expected Outputs

three tone input sinusoidal signal


5
magnitude of input signal

-5
0 100 200 300 400 500 600
time,n
magnitude of input signal spectrum

three tone input signal spectrum at frequencies 5001500& at 2000


2

1.5

0.5

0
0 500 1000 1500 2000 2500 3000 3500 4000
frequency in hz

25
magnitude of filtered signal spectrum magnitude of filtered signal magnitude of filtered sinusoidal signal
4

-2

-4
0 100 200 300 400 500 600
time,n
HP signal spectrum
2

1.5

0.5

0
0 500 1000 1500 2000 2500 3000 3500 4000
frequency in hz

26
6. Generation of Sinusoidal signal through filtering

Purpose of Experiment

Let the impulse response of the system is h [n ]

The impulse response of the system must be a sinusoidal signal.

y [ n ] =h [ n ] =sin ω0 n

Algorithm:

Step1:Given
y [ n ] =h [ n ] =sin ω0 n

Step 2: Find Y [ z ]
−1
sin ω 0 z
Y [ z ]= −1 −2
1−2cos ω0 z + z

Step 3: Compare with system function


M −1

∑ b k z−k
k=0
H ( z )= N−1
∑ a k z −k
k=0

Step 4: Find the coefficients: b k and a k

Experimental Steps

27
Sample Code

%Program for Generation of Sinusoidal Signal through Filtering

clear all;
close all;
clc;
%fs=input('enter the sampling frequency of the signal=');
%f_hz=input('enter the signal frequency in Hz= ');

f_hz=1000;
fs=8000;
f0=2*pi*f_hz/fs;

a1=2*cos(f0);
a2=-1;

b1=sin(f0);
%xnm1=zeros(1,128);

xnm1=1;
ynm1=0;
ynm2=0;
%Initializing output to zero
%output=zeros(1,200);
y1=zeros(1,200);
for i=1:200
y1(i)=b1*xnm1+a1*ynm1+a2*ynm2;
ynm2=ynm1;
28
ynm1=y1(i);
xnm1=0;
%output(i)=y1(i);
end
subplot(2,1,1)
plot(1:length(y1),y1);
xlabel('Time in Seconds');
ylabel('Amplitude of the signal');
title(['sinusoidal signal of frequency',num2str(f_hz),'Hz']);

Ak=2*abs(fft(y1))/length(y1);
Ak(1)=Ak(1)/2;
f=(0:1:(length(y1)-1)/2)*fs/length(y1);

subplot(2,1,2)
plot(f, Ak(1:(length(y1)+1)/2));

xlabel('Frequency in Hz');
ylabel('Magnitude of the Spectrum');
title(['Spectrum at',num2str(f_hz),'Hz frequency']);
Expected Outputs

sinusoidal signal of frequency1000Hz


1
Amplitude of the signal

0.5

-0.5

-1
0 20 40 60 80 100 120 140 160 180 200
Time in Seconds
Spectrum at1000Hz frequency
Magnitude of the Spectrum

0.5

0
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency in Hz

29
7. Generation of DTMF Signals
Purpose of Experiment

The DTMF stands for “Dual Tone Multi Frequency”, and is a method of representing digits with tone
frequencies, in order to transmit them over an analog communications network, for example a
telephone line. In telephone networks, DTMF signals are used to encode dial trains and other
information. Dual-tone Multi-Frequency (DTMF) signalling is the basis for voice communications
control and is widely used worldwide in modern telephony to dial numbers and configure
switchboards. It is also used in systems such as in voice mail, electronic mail and telephone banking.
A DTMF signal consists of the sum of two sinusoids - or tones - with frequencies taken from two
mutually exclusive groups. These frequencies were chosen to prevent any harmonics from being
incorrectly detected by the receiver as some other DTMF frequency. Each pair of tones contains one
frequency of the low group (697 Hz, 770 Hz, 852 Hz, 941 Hz) and one frequency of the high group
(1209 Hz, 1336 Hz, 1477Hz) and represents a unique symbol.

Frequency 1209 Hz 1336 Hz 1477 Hz

697 Hz 1 2 3

770 Hz 4 5 6

852 Hz 7 8 9

941 Hz * 0 #

Experimental Steps
STAR
30
INPUTS: Enter row and
column frequencies

Define signals to represent all symbols

Use If statements to generate the symbols

STOP

Sample Code

clear all;
close all;
clc;
%Signal and Sampling frequency
fs=8000;
t=0:1/fs:1;
x=zeros(1,length(t));
x(1)=1;
%Calculation of output of LF signal generation
%fL=input('enter any one low frequency value from [697 770 852 941] %vector');
fL=852;
%Numerator coefficients of HL(z)
bL=[0 sin(2*pi*fL/fs)];

%Denominator coefficients of HL(z)


aL= [1 -2*cos(2*pi*fL/fs) 1];

% Output of HL(z)
yL=filter(bL,aL,x);

%Calculation of output of HF signal generation


%fH=input('enter any one High frequency value from [1209 1336 14777] %vector');
fH=1336;
%Numerator coefficients of HH(z)
bH=[0 sin(2*pi*fH/fs)];

31
%Denominator coefficients of HH(z)
aH=[1 -2*cos(2*pi*fH/fs) 1];
% Output of HH(z)
yH=filter(bH,aH,x);

%generation of fL and fH DTMF tone


y_LH=yL+yH;

%Identifying Key pressed

if (fL==697 && fH==1209)


key=1;
disp('Generated DTMF tone is for key 1');
end

if(fL==697 && fH==1336)


key=2;
disp('Generated DTMF tone is for key 2');
end

if(fL==697 && fH==1477)


key=3;
disp('Generated DTMF tone is for key 3');
end
if(fL==770 && fH==1209)
key=4;
disp('Generated DTMF tone is for key 4');
end
if(fL==770 && fH==1336)
key=5;
disp('Generated DTMF tone is for key 5');
end
if(fL==770 && fH==1477)
key=6;
disp('Generated DTMF tone is for key 6');
end
if(fL==852 && fH==1209)
key=7;
disp('Generated DTMF tone is for key 7');
end
if(fL==852 && fH==1336)
key=8;
disp('Generated DTMF tone is for key 8');
end
if(fL==852 && fH==1477)
key=9;
disp('Generated DTMF tone is for key 9');
end
if(fL==941 && fH==1209)
32
key='*';
disp('Generated DTMF tone is for key *');
end
if(fL==941 && fH==1336)
key='0';
disp('Generated DTMF tone is for key 0');
end
if(fL==941 && fH==1477)
key='#';
disp('Generated DTMF tone is for key #');
end

%Plotting of DTMF Signal and its Spectrum


subplot(2,1,1)
plot(1:200,y_LH(1:200));
xlabel('Time in Seconds');
ylabel('Amplitude of DTMF signal');
title(['DTMF signal for Key',num2str(key)]);

%One Sided Amplitude Spectrum


Mag_Spec=2*abs(fft(y_LH))/length(y_LH);
Mag_Spec(1)=Mag_Spec(1)/2;
f=(0:1:(length(y_LH)-1)/2)*fs/length(y_LH);

subplot(2,1,2)
plot(f,Mag_Spec(1:(length(y_LH)+1)/2));
grid
xlabel('Frequency in Hz');
ylabel('Magnitude of the Spectrum');
title(['Magnitude Spectrum of DTMF Tone for Key',num2str(key),' at '
num2str(fL),'HZ & at',num2str(fH),'Hz']);

Expected Outputs

Generated DTMF tone is for key 8

33
8. Implementation of Decimation and Interpolation
processes, I/D sampling Rate Converters
Purpose of Experiment

Decimation process in Time Domain


Decimation is the process of reducing the sampling frequency of a signal to a lower sampling
frequency that differs from the original frequency by an integer value. Decimation also is known as
down-sampling. The low pass filtering associated with decimation removes high-frequency content
from the signal to accommodate the new sampling frequency.

• Decimation is useful in applications in which the Nyquist frequency of a signal is much


higher than the highest frequency of the signal. Decimation filters help you remove the excess
bandwidth and reduce the sampling frequency of the signal. Decimation filters also help you
reduce the computational resources required for processing and storing the signal. During the
analog-to-digital (A/D) conversion process, decimation filters also can reduce the variance of
34
quantization noise in a signal and maintain the signal power, thus improving the signal-to-
noise ratio (SNR).

• The following figure shows a typical M-fold decimation filter, where M is the integer value
by which you want to decrease the sampling frequency. This filter contains a low pass FIR
filter H(z). This low pass FIR filter is an anti-aliasing filter followed by an M-fold decimator.
The decimator passes every Mth sample and discards the other samples. After this operation,
the decimation filter changes the sampling frequency fs of the input signal x(n) to a new
sampling frequency fs/M. The decimation filter then returns an output signal y(n) with the
new sampling frequency

y ( n )=x ( Mn ) ………………Decimation
x(n)
x(n)
Anti M
aliasing
filter H(z) fs/M
fs Decimator

To prevent aliasing, this system uses the low pass filter H(z) before the M-fold decimator to suppress
the frequency contents above the frequency fs/(2M), which is the Nyquist frequency of the output
signal. This system produces the same results as an analog anti-aliasing filter with a cutoff frequency
offs/(2M) followed by an analog-to-digital (A/D) converter with a sampling frequency offs/M.
Because the system shown in the figure above is in the digital domain, H(z) is a digital anti aliasing
filter.

Experimental Steps

Start

Enter Down sampling and


up sampling factor and
input frequencies

Perform sampling rate


conversion

Plot the input, output


sequences
35
Stop
Sample Code
clear all;
close all;
clc;
N=1024;
f=500;
fs=8000;
n=0:N-1;
x=sin(2*pi*f/fs*n);
subplot(2,1,1)
Hx=stem(n(1:50),x(1:50),'filled');
set(Hx,'markersize',2);
xlabel('time index, n','fontsize',12)
ylabel('Amplitude','fontsize',12)
title('Original Input Signal','fontsize',12)
M=2;
xd=decimate(x,M);
subplot(2,1,2)
Hx=stem(n(1:50),xd(1:50),'filled');
set(Hx,'markersize',2);
xlabel('time index, n','fontsize',12)
ylabel('Amplitude','fontsize',12)
title(['Decimation Signal by a factor',num2str(M)],'fontsize',12)

Expected Outputs

36
Original Input Signal
1

0.5
Amplitude

-0.5

-1
0 5 10 15 20 25 30 35 40 45 50
time index, n
Decimation Signal by a factor2
1

0.5
Amplitude

-0.5

-1
0 5 10 15 20 25 30 35 40 45 50
time index, n

Interpolation process
Up sampling is the process of inserting zero-valued samples between original samples to increase the
sampling rate. (This is called “zero-stuffing”.) “Interpolation”, is the process of up sampling followed
by filtering. The filtering removes the undesired spectral images. The primary reason to interpolate is
simply to increase the sampling rate at the output of one system so that another system operating at a
higher sampling rate can input the signal.

y(n)
x(n) Anti
L imaging
filter H(z)
Up sampler

-π/L ω
π/L
Multirate" means "multiple sampling rates". A multi rate DSP system uses multiple sampling rates
within the system. Whenever a signal at one rate has to be used by a system that expects a different
rate, the rate has to be increased or decreased, and some processing is required to do so. Therefore
"Multirate DSP" refers to the art or science of changing sampling rates.

n
y ( n )=x ( )………………..Interpolation
L

37
"Resampling" means combining interpolation and decimation to change the sampling rate by a
rational factor. Resampling is done to interface two systems with different sampling rates.

clear all;
close all;
clc;
% Generation of Input Signal
N=1024;
L=2;
fs=8000;
n=0:N-1;
x=2*sin(2*pi*1000*n/fs)+sin(2*pi*2000/fs*n);

%Upsampling process
%Upsampling by a factor of L
w=zeros(1,L*N);
for k=0:N-1
w(L*k+1)=x(k+1);
end
L_w=length(w);
W=2*abs(fft(w,L_w))/L_w;
W(1)=W(1)/2;
f=(0:L_w/2-1)*fs*L/L_w;

% Design of Anti-aliasing/ Interpolation filter

%Use FIR LPF with a cut off frequency of 2*pi*fc or 2*pi*3000 and a sampling rate
of L*fs

N=25;
new_fs=L*fs;
wcL=2*pi*2500/new_fs;
Ftype=1;
wcH=0;
wtype=4;
B=firwd(N,1,wcL,wcH,wtype);

% Interpolation operation
y=filter(B,1,w);
Y=2*abs(fft(y,L_w)/L_w);
Y(1)=Y(1)/2;
fsL=(0:L_w/2-1)*fs*L/L_w;

%Plot of Interpolation operation


figure(1)
subplot(2,1,1)
stem(1:length(w(1:200)),w(1:200));
38
xlabel('time index, n','fontsize',12)
ylabel('Amplitude','fontsize',12)
title('Upsampled Signal','fontsize',12)

subplot(2,1,2)
stem(1:length(y(1:200)),y(1:200));
xlabel('time index, n','fontsize',12)
ylabel('Amplitude','fontsize',12)
title(['Interpolated Signal by a factor',num2str(L)],'fontsize',12)

% Plot of Spectrum
figure(2)
subplot(2,1,1)
plot(f,W(1:L_w/2));
xlabel('Frequency in Hz')
ylabel('Amplitude','fontsize',12)
title('Spectrum of Upsampled Signal','fontsize',12)

subplot(2,1,2)
plot(fsL,Y(1:L_w/2));
xlabel('Frequency in Hz')
ylabel('Amplitude','fontsize',12)
title('Spectrum of Interpolated Signal','fontsize',12)

39
Expected Outputs

Upsampled Signal
2
Amplitude

-1

-2
0 20 40 60 80 100 120 140 160 180 200
time index, n
Interpolated Signal by a factor2
1
Amplitude

0.5

-0.5

-1

0 20 40 60 80 100 120 140 160 180 200


time index, n

Spectrum of Upsampled Signal


1
Amplitude

0.5

0
0 1000 2000 3000 4000 5000 6000 7000 8000
Frequency in Hz
Spectrum of Interpolated Signal
1
Amplitude

0.5

0
0 1000 2000 3000 4000 5000 6000 7000 8000
Frequency in Hz

40
Implementation of I/D Sampling Rate Converters

• Multirate means "multiple sampling rates".

• A Multirate DSP system uses multiple sampling rates within the system.

• Whenever a signal at one rate has to be used by a system that expects a different rate, the rate
has to be increased or decreased, and some processing is required to do so.

• Therefore "Multirate DSP" refers to the art or science of changing sampling rates.

• "Resampling" means combining interpolation and decimation to change the sampling rate by
a rational factor.

• Resampling is done to interface two systems with different sampling rates.

w(n)
v(n) y(n)
x(n)
L H(z) M

Fx
LFx LFx/M

clear all;
close all;
clc;
% Generation of Input Signal
N=1024;
L=3;
M=8;
fs=8000;
n=0:N-1;
x=5*sin(2*pi*1000*n/fs)+cos(2*pi*2500/fs*n);

%Upsampling process

%Upsampling by a factor of L
w=zeros(1,L*N);
for k=0:N-1
w(L*k+1)=x(k+1);
end
L_w=length(w);
W=2*abs(fft(w,L_w))/L_w;
W(1)=W(1)/2;
f=(0:L_w/2-1)*fs*L/L_w;

% Design of Anti aliasing/ Interpolation filter

41
%Use FIR LPF with a cut off frequency of 2*pi*fc or 2*pi*3000 and a sampling rate
of L*fs

N=53;
new_fs=L*fs;
wcL=2*pi*1250/new_fs;
Ftype=1;
wcH=0;
wtype=4;
B=firwd(N,1,wcL,wcH,wtype);

% Combined filtering operation


y=filter(B,1,w);
Y=2*abs(fft(y,L_w)/L_w);
Y(1)=Y(1)/2;
fsL=(0:L_w/2-1)*fs*L/L_w;

%Down Sampling
d=y(1:M:L_w);
Ld=length(d);
D=2*abs(fft(d,Ld)/Ld);
D(1)= D(1)/2;
fsd=(0:Ld/2-1)*(fs*L/M)/Ld;

% Plot of Spectrum
subplot(3,1,1)
plot(f,W(1:L_w/2));
xlabel('Frequency in Hz')
ylabel('Amplitude','fontsize',12)
title('Spectrum of Upsampled Signal','fontsize',12)

subplot(3,1,2)
plot(fsL,Y(1:L_w/2));
xlabel('Frequency in Hz')
ylabel('Amplitude','fontsize',12)
title('Spectrum of Combined Signal','fontsize',12)

subplot(3,1,3)
plot(fsd,D(1:Ld/2));
xlabel('Frequency in Hz')
ylabel('Amplitude','fontsize',12)
title('Spectrum of Down sampled Signal','fontsize',12)

42
Expected Outputs

Spectrum of Upsampled Signal


2
Amplitude

0
0 2000 4000 6000 8000 10000 12000
Frequency in Hz
Spectrum of Combined Signal
Amplitude

0.5

0
0 2000 4000 6000 8000 10000 12000
Frequency in Hz
Spectrum of Down sampled Signal
Amplitude

0.5

0
0 500 1000 1500
Frequency in Hz

Additional Experiments

% Noise Removal: Add noise above 3 KHz and then remove


interference

clear all;
close all;
clc;
N=200;
f1=100;
f2=400;
fs=1000;
n=0:N-1;
x=3*sin(2*pi*f1*n/fs)+2*sin(2*pi*f2*n/fs);
L=25;
fc=400;
b=fir1(55,fc/fs);
y=filter(b,1,x);
subplot(3,1,1);

43
plot(n,x,n,y,'r');
xlabel('time,n');
ylabel('magnitude of input signal');
title('two input sinusoidal signal filtered');

%spectrum of input signal

N=length(x);
Mag_x=2*abs(fft(x))/N;
Mag_x(1)=Mag_x(1)/2;
f_Hz=(1:N/2)*fs/N;
subplot(3,1,2);
plot(f_Hz,Mag_x(1:N/2));
xlabel('frequency in hz');
ylabel('magnitude of input signal spectrum');
title('three tone input signal spectrum');

N=length(y);
Mag_y=2*abs(fft(y))/N;
Mag_y(1)=Mag_y(1)/2;
f_Hz=(1:N/2)*fs/N;
subplot(3,1,3);
plot(f_Hz,Mag_y(1:N/2));
xlabel('frequency in hz');
ylabel('magnitude of input signal spectrum');

44
Expected Outputs

magnitude of input signal


two input sinusoidal signal filtered
5

0
spectrumof input signal spectrum

-5
0 20 40 60 80 100 120 140 160 180 200
time,n
three tone input signal spectrum

0
magnitude

0 50 100 150 200 250 300 350 400 450 500


frequency in hz
magnitude of input signal

0
0 50 100 150 200 250 300 350 400 450 500
frequency in hz

Frequency Response of a given system given in Transfer


function /difference Equation Form

%To find frequency response of a given system given in Transfer function /Difference
Equation form

Clear Section
clear all;
close all;
clc;

Coefficients of numerator and denominator coefficients


b=[1 -1 1];
a=[1 -0.9 0.81];
N=200;

Finding frequency response, magnitude and phase response


[H,w]=freqz(b,a,N);
Mag_H=abs(H);
Phase_H=180*unwrap(angle(H))/pi;

45
subplot(2,1,1);
plot(w,Mag_H);
grid;
xlabel('Frequency in radians');
ylabel('Magnitude of frequency response');
title('Frequency response');

subplot(2,1,2);
plot(w,Phase_H);
grid;
xlabel('Frequency in radians');
ylabel('Phase response in degrees');
title('Phase response');

Expected Outputs
Magnitude of frequency response

Frequency response
1.5

0.5

0
0 0.5 1 1.5 2 2.5 3 3.5
Frequency in radians
Phase response in degrees

Phase response
100

50

-50

-100
0 0.5 1 1.5 2 2.5 3 3.5
Frequency in radians

46
TMS320C6713 DSP Starter Kit (DSK)

• This board plugs into the computer using a USB cable.


• There are stereo audio inputs for line (CD player / IPOD etc).
• There are stereo audio outputs for headphones or computer speakers.
• Input switches are provided to allow selection of up to 16 different settings.
• There are 4 LEDs which can be used as a bargraph.

References
• The DSK boards can be ordered from the TI website: www.ti.com
Additional information and software downloads can be found on the Spectrum Digital
website: www.spectrumdigital.com

47
TMS320C6713 DSK KIT

DSP Board
 FLOATING POINT C6713TM 255MHz DSP
 16-bit stereo codec (stereo in & out)
 Four 3.5 millimeter audio jacks
 512K non-volatile Flash memory
 16MB SDRAM
 HPI, McASP & I2C interface header emulation
 On-board standard JTAG interface
 Plug and play JTAG support via USB connectors
 +5-volt universal power supply
 Expansion port for plug-in modules

Typical C6713 DSK Setup

48
TMS320C6713 DSK Overview Block Diagram

CODE COMPOSER STUDIO (CCS)


I. CODE COMPOSER STUDIO (CCS) 5.3 (setup in simulation
Mode)
Following are the steps to be followed for executing a program in CCS 5.3

1. Open code composer studio CCS 5.3.


2. Click on view----Target Configuration
If a .ccxml file already exits under user defined, delete it.
3. In order to define a new Target Configuration file:
Click on file-new- Target Configuration file-C6713.ccxmlfinish
4. Under Basic Settings:
Connection: Texas Instrument Simulator
Board/Device: C6713 Device Cycle Accurate Simulator, Little Endian
After making these changes click on SAVE
5. Under Advance setting:
Select TMS320C6713
GO to CPU properties:Browse
Path: ccstudioV3.1CCgelDSK6713.gel(open)
6. After these settings in user defined window we get C6713.ccxml file.
Right click on this file and select Launch Target/ Selected configuration.

In order to create a new CCS project

7. Click on file newotherCCS:CCS project


49
Project name: abc
Output type: Executable
Family: C6000
Variant: TMS320C6713
Connection: texas instrument simulator
Select empty project with main.c
8. Write the C code in main.c and save it.
9. Go to viewProject Explorer
Click on Project Name(abc)ProjectBuild project
10. Go to project explorer. Right click on C6713.ccxml file and launch selected
configuration.
11. Click on runLoadBrowse
Select abc.out file and click on OK
12. Go to run Resume

IN ORDER TO VIEW A GRAPH/PLOT


13. Go to tools - graph properties single time
Acquisition buffer size and Display data size must be set to maximum size of
output array
DSP data type: 32-bit floating point number
Start Address: Output variable in the code

II. Steps for Real Time Implementation on DSK6713 Processor Kit.


Following are the steps for for Real Time Implementation on DSK6713 Processor Kit.
Part I:
1. Open CCS 5.3 version.
2. Click on view Target configuration.
If a Click on view----Target Configuration
If a .ccxml file already exits under user defined, delete it.
3. In order to define a new Target Configuration file:
Click on file-new- Target Configuration file-C6713.ccxmlfinish
4. Under Basic Settings:
Connection: Texas Instrument Simulator
Board/Device: C6713 Device Cycle Accurate Simulator, Little Endian
After making these changes click on SAVE
5. Under Advance setting:
Select TMS320C6713
GO to CPU properties:Browse
Path: ccstudioV3.1CCgelDSK6713.gel(open)
6. After these settings, in User defined we obtain DSK6713.ccxml
7. Go to run- connect target
On the right corner of the screen, A message appears “USB Enumeration”.

PART-2: PROJECT CREATION


1. Click on filenewCCS project
Name: xyz
Connection: spectrum digital DSK EVM EZ DSP onboard DSP emulator
Output type: Executable
Family: C6000
50
Variant: TMS320C67XX
Connection: AS mentioned above
Select empty project with main.c
2. Select project name right clickAdd files
ccs 3.1C6000dsk6713libDSK6713bsl.lib (Board Support library)
Copy files and click on OK
3. Again right click on project name: Add file
ccs 3.1C6000csllibcsl6713.lib
(chip select library)
4. Right click on project name
Go to propertiesC6000 compilerInclude options
Note: If already exists a path, delete it
Click on Addfile systemccs 3.1C6000cslincludeokok
5. Again right click on project nameProperties
Select C6000 compilerAdvance optionspredefined symbolsadd
CHIP_6713ok

51
9. LINEAR CONVOLUTION
Purpose of Experiment

Description: -Linear Convolution Involves the following operations.


1. Folding
2. Multiplication
3. Addition
4. Shifting

These operations can be represented by a Mathematical Expression as follows:


r
y [ n ] =∑ x [ k ] .h [n−k ]
k=0

x[ ]= Input signal Samples


h[ ]= Impulse response co-efficient.
y[ ]= Convolution output.
n = No. of Input samples
h = No. of Impulse response co-efficient.
Algorithm to implement ‘C’ or Assembly program for Convolution:
Eg: x[n] = {1, 2, 3, 4}
h[k] = {1, 2, 3, 4}
Where: n=4, k=4.; Values of n & k should be a multiple of 4.
If n & k are not multiples of 4, pad with zero’s to make
multiples of 4
r= n+k-1 ; Size of output sequence.
= 4+4-1
= 7.

Output: y[r] = {1, 4, 10, 20, 25, 24, 16}.


NOTE: At the end of input sequences pad ‘n’ and ‘k’ no. of zero’s

Sample Code

C PROGRAM TO IMPLEMENT LINEAR CONVOLUTION

/* prg to implement linear convolution */


#include<stdio.h>
#include<math.h>
int y[20];
main()
{ int m=6; /*Lenght of i/p samples sequence*/
int n=6; /*Lenght of impulse response Co-efficients */
52
int i=0,j;
int x[15]={1,2,3,4,5,6,0,0,0,0,0,0}; /*Input Signal Samples*/
int h[15]={1,2,3,4,5,6,0,0,0,0,0,0}; /*Impulse Response Co-efficients*/
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
}
Expected Outputs

53
10. CIRCULAR CONVOLUTION
Purpose of Experiment

Description:- Steps for Cyclic Convolution

Steps for cyclic convolution are the same as the usual convolution, except all index
calculations
are done "mod N" = "on the wheel"

Step1: “Plot f[m] and h[−m]

Step 2: "Spin" h[−m] n times Anti Clock Wise (counter-clockwise) to get h[n-m]
(i.e. Simply rotate the sequence, h[n], clockwise by n steps)

Step 3: Point wise multiply the f[m] wheel and the h[n−m] wheel. Sum=y[n]
Step 4: Repeat for all 0≤n≤N−1

Example 1: Convolve (n = 4)

Figure 3: Two discrete-time signals to be convolved

h[−m] =

54
Multiply f[m] and sum to yield: y[0] =3

h[1−m]

Figure 5
Multiply f[m] and sum to yield: y[1] =5

h[2−m]

Figure 6
Multiply f[m] and sum to yield: y[2] =3

h[3−m]

Figure 7
Multiply f[m] and sum to yield: y[3] =1

Sample Code

C Program to Implement Circular Convolution

#include<stdio.h>
#include<math.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);
55
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++)
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];
/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
for(k=1;k<n;k++)
{
y[k]=0;
/*circular shift*/
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];
}
}
/*displaying the result*/
printf(" the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);
}

Expected Outputs

INPUT: Eg: x[4]={1, 2, 3,4} h[4]={1, 2, 3,4} OUT PUT y[4]={26, 28,
26,20}
56
11. Finite Impulse Response Filter(FIR)

Sample Code

DESIGNING AN FIR FILTER:

57
Following are the steps to design linear phase FIR filters Using Windowing Method.
I. Clearly specify the filter specifications.
Eg: Order = 30;
Sampling Rate = 8000 samples/sec
Cut off Freq. = 400 Hz.
II. Compute the cut-off frequency Wc
Eg: Wc = 2*pie* fc / Fs
= 2*pie* 400/8000
= 0.1*pie
III. Compute the desired Impulse Response h d (n) using particular Window
Eg: b_rect1=fir1 (order, Wc , 'high',boxcar(31));
IV. Convolve input sequence with truncated Impulse Response x (n)*h (n)

Using FIR1 Function on Matlab

B = FIR1(N,Wn) designs an N'th order lowpass FIR digital filter and returns the filter
oefficients in length N+1 vector B. The cut-off frequency Wn must be between 0 < Wn < 1.0,
with 1.0 corresponding to half the sample rate. The filter B is real and has linear phase, i.e.,
even symmetric coefficients obeying B(k) =B(N+2-k), k = 1,2,...,N+1. If Wn is a two-
element vector, Wn = [W1 W2], FIR1 returns an order N bandpass filter with passband W1 <
W < W2. B = FIR1(N,Wn,'high') designs a highpass filter. B = FIR1(N,Wn,'stop') is a
bandstop filter if Wn = [W1 W2]. If Wn is a multi-element vector, Wn = [W1 W2 W3 W4
W5 ... WN], FIR1 returns an order N multiband filter with bands 0 < W < W1, W1 < W <
W2, ..., WN < W < 1. B = FIR1(N,Wn,'DC-1') makes the first band a passband. B =
FIR1(N,Wn,'DC-0') makes the first band a stopband. For filters with a passband near Fs/2,
e.g., highpass and bandstop filters, N must be even.

By default FIR1 uses a Hamming window. Other available windows, including Boxcar,
Hanning, Bartlett, Blackman, Kaiser and Chebwin can be specified with an optional trailing
argument. For example, B = FIR1(N,Wn,kaiser(N+1,4)) uses a Kaiser window with beta=4.
B = FIR1(N,Wn,'high',chebwin(N+1,R)) uses a Chebyshev window.
By default, the filter is scaled so the center of the first pass band has magnitude exactly one
after windowing. Use a trailing 'noscale' argument to prevent this scaling, e.g. B =
FIR1(N,Wn,'noscale'),
B = FIR1(N,Wn,'high','noscale'), B = FIR1(N,Wn,wind,'noscale').

Matlab Program to generate ‘FIR Filter-Low Pass’ Coefficients using FIR1

% FIR Low pass filters using rectangular, triangular and kaiser windows
% sampling rate – 8000
order = 50;
cf=[500/4000,1000/4000,1500/4000]; cf--> contains set of cut-off frequencies[Wc ]
% cutoff frequency – 500
58
b_rect1=fir1(order,cf(1),boxcar(51)); %Rectangular
b_tri1=fir1(order,cf(1),bartlett(51)); %Triangular
b_kai1=fir1(order,cf(1),kaiser(51,8)); %Kaisar [Where 8-->Beta Co-efficient]
% cutoff frequency - 1000b_rect2=fir1(order,cf(2),boxcar(51));
b_tri2=fir1(order,cf(2),bartlett(51));
b_kai2=fir1(order,cf(2),kaiser(31,8));
% cutoff frequency - 1500
b_rect3=fir1(order,cf(3),boxcar(51));
b_tri3=fir1(order,cf(3),bartlett(51));
b_kai3=fir1(order,cf(3),kaiser(51,8));
fid=fopen('FIR_lowpass_rectangular.txt','wt');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -400Hz');
fprintf(fid,'\nfloat b_rect1[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect1);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -800Hz');
fprintf(fid,'\nfloat b_rect2[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect2);
fseek(fid,-1,0);
fprintf(fid,'};');
fprintf(fid,'\n\n\n\n');
fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -1200Hz');
fprintf(fid,'\nfloat b_rect3[31]={');
fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect3);
fseek(fid,-1,0);
fprintf(fid,'};');
fclose(fid);
winopen('FIR_highpass_rectangular.txt');

T.1 : Matlab generated Coefficients for FIR Low Pass Kaiser filter:

C PROGRAM TO IMPLEMENT FIR FILTER:

fir.c
#include "xyzcfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
float filter_Coeff[] ={0.000000,-0.001591,-0.002423,0.000000,0.005728,
59
0.011139,0.010502,-0.000000,-0.018003,-0.033416,-0.031505,0.000000,
0.063010,0.144802,0.220534,0.262448,0.220534,0.144802,0.063010,0.000000,
-0.031505,-0.033416,-0.018003,-0.000000,0.010502,0.011139,0.005728,
0.000000,-0.002423,-0.001591,0.000000 };
static short in_buffer[100];

DSK6713_AIC23_Config config = {\
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Leftline input channel volume */\
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume*/\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */\
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */\
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */\
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */\
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */\
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */\
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */\
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
/*
* main() - Main code routine, initializes BSL and generates tone
*/
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
/* Initialize the board support library, must be called first */
DSK6713_init();

/* Start the codec */


hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec, 1);
while(1)
{ /* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec, &l_input));
/* Read a sample to the right channel */
while (!DSK6713_AIC23_read(hCodec, &r_input));
l_output=(Int16)FIR_FILTER(&filter_Coeff ,l_input);
r_output=l_output;
/* Send a sample to the left channel */
while (!DSK6713_AIC23_write(hCodec, l_output));
/* Send a sample to the right channel */
while (!DSK6713_AIC23_write(hCodec, r_output));
}
/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}
signed int FIR_FILTER(float * h, signed int x)
{
int i=0;
60
signed long output=0;
in_buffer[0] = x; /* new input at buffer[0] */
for(i=51;i>0;i--)
in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer */
for(i=0;i<51;i++)
output = output + h[i] * in_buffer[i];
return(output);
}

Expected Outputs

12. Infinite Impulse Response Filter(IIR)


Sample Code
#include <stdio.h>
#include "dsk6713.h"
#include "dsk6713_aic23.h"
const signed int filter_Coeff[] =
61
{
12730,-12730,12730,32767,-18324,21137 /*HP 2000 */
//312,312,312,32767,-27943,24367 /*LP 800 */
//1455,1455,1455,32767,-23140,21735 /*LP 2500 */
//9268,-9268,9268,32767,-7395,18367 /*HP 4000*/
//7215,-7215,7215,32767,5039,6171, /*HP 7000*/

};

/* Codec configuration settings */


DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume
*/\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */
\
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume
*/ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};

/*
* main() - Main code routine, initializes BSL and generates tone
*/
void main()
{
DSK6713_AIC23_CodecHandle hCodec;

int l_input, r_input, l_output, r_output;

/* Initialize the board support library, must be called first */


DSK6713_init();

/* Start the codec */


hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 3);

while(1)
{ /* Read a sample to the left channel */
while (!DSK6713_AIC23_read(hCodec, &l_input));

/* Read a sample to the right channel */


while (!DSK6713_AIC23_read(hCodec, &r_input));
62
l_output=IIR_FILTER(&filter_Coeff ,l_input);
r_output=l_output;

/* Send a sample to the left channel */


while (!DSK6713_AIC23_write(hCodec, l_output));

/* Send a sample to the right channel */


while (!DSK6713_AIC23_write(hCodec, r_output));
}

/* Close the codec */


DSK6713_AIC23_closeCodec(hCodec);
}

signed int IIR_FILTER(const signed int * h, signed int x1)


{
static signed int x[6] = { 0, 0, 0, 0, 0, 0 }; /* x(n), x(n-1), x(n-2). Must be
static */
static signed int y[6] = { 0, 0, 0, 0, 0, 0 }; /* y(n), y(n-1), y(n-2). Must be
static */
int temp=0;

temp = (short int)x1; /* Copy input to temp */

x[0] = (signed int) temp; /* Copy input to x[stages][0] */

temp = ( (int)h[0] * x[0]) ; /* B0 * x(n) */

temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */


temp += ( (int)h[1] * x[1]); /* B1/2 * x(n-1) */
temp += ( (int)h[2] * x[2]); /* B2 * x(n-2) */

temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */


temp -= ( (int)h[4] * y[1]); /* A1/2 * y(n-1) */
temp -= ( (int)h[5] * y[2]); /* A2 * y(n-2) */

/* Divide temp by coefficients[A0] */

temp >>= 15;

if ( temp > 32767 )


{
temp = 32767;
}
else if ( temp < -32767)
{
63
temp = -32767;
}
y[0] = temp ;

/* Shuffle values along one place for next time */

y[2] = y[1]; /* y(n-2) = y(n-1) */


y[1] = y[0]; /* y(n-1) = y(n) */

x[2] = x[1]; /* x(n-2) = x(n-1) */


x[1] = x[0]; /* x(n-1) = x(n) */

/* temp is used as input next time through */

return (temp<<2);
}
Expected Outputs

13. FAST FOURIER TRANSFPRM (FFT)


64
Sample Code

#define PTS 256 //# of points for FFT


typedef struct {float real,imag;} COMPLEX;
extern COMPLEX w[PTS]; //twiddle constants stored in w

void FFT(COMPLEX *Y, int N) //input sample array, # of points


{
COMPLEX temp1,temp2; //temporary storage variables
int i,j,k; //loop counter variables
int upper_leg, lower_leg; //index of upper/lower butterfly leg
int leg_diff; //difference between upper/lower leg
int num_stages = 0; //number of FFT stages (iterations)
int index, step; //index/step through twiddle constant
i = 1; //log(base2) of N points= # of stages
do
{
num_stages +=1;
i = i*2;
}while (i!=N);
leg_diff = N/2; //difference between upper&lower legs
step = (PTS*2)/N; //step between values in twiddle.h // 512
for (i = 0;i < num_stages; i++) //for N-point FFT
{
index = 0;
for (j = 0; j < leg_diff; j++)
{
for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff))
{
lower_leg = upper_leg+leg_diff;
temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real;
temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag;
temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real;
temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag;
(Y[lower_leg]).real = temp2.real*(w[index]).real
-temp2.imag*(w[index]).imag;
(Y[lower_leg]).imag = temp2.real*(w[index]).imag
+temp2.imag*(w[index]).real;
(Y[upper_leg]).real = temp1.real;
(Y[upper_leg]).imag = temp1.imag;
}
index += step;
}
leg_diff = leg_diff/2;
step *= 2;
}
j = 0;
for (i = 1; i < (N-1); i++) //bit reversal for resequencing data
{
65
k = N/2;
while (k <= j)
{
j = j - k;
k = k/2;
}
j = j + k;
if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag;
(Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
}

//FFT256c.c FFT implementation calling a C-coded FFT function

#include <math.h>
#define PTS 256 //# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer
float x1[PTS]; //intermediate buffer
short i; //general purpose index variable
short buffercount = 0; //number of new samples in iobuffer
short flag = 0; //set to 1 by ISR when iobuffer full
COMPLEX w[PTS]; //twiddle constants stored in w
COMPLEX samples[PTS]; //primary working buffer

main()
{
for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w
{
w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants
w[i].imag =-sin(2*PI*i/(PTS*2.0)); //Im component of twiddle constants
}

for (i = 0 ; i < PTS ; i++) //swap buffers


{

iobuffer[i] = sin(2*PI*30*i/PTS);/*10- > freq,100 -> sampling freq*/


66
samples[i].real=0.0;
samples[i].imag=0.0;
}

for (i = 0 ; i < PTS ; i++) //swap buffers


{
samples[i].real=iobuffer[i]; //buffer with new data
/* iobuffer[i] = x1[i]; //processed frame to iobuffer*/
}
//for (i = 0 ; i < PTS ; i++)
//samples[i].imag = 0.0; //imag components = 0

FFT(samples,PTS); //call function FFT.c

for (i = 0 ; i < PTS ; i++) //compute magnitude


{
x1[i] = sqrt(samples[i].real*samples[i].real
+ samples[i].imag*samples[i].imag);///32;
}

} //end of main

Expected Outputs

67
68
14. To compute Power Density Spectrum (PDS) of a
sequence and signal
#include <math.h>
#define PTS 128 //# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer
float x1[PTS],x[PTS]; //intermediate buffer
short i; //general purpose index variable
short buffercount = 0; //number of new samples in iobuffer
short flag = 0; //set to 1 by ISR when iobuffer full
float y[128];
COMPLEX w[PTS]; //twiddle constants stored in w
COMPLEX samples[PTS]; //primary working buffer

main()
{

float j,sum=0.0 ;
int n,k,i,a;
for (i = 0 ; i<PTS ; i++) // set up twiddle constants in w
{
w[i].real = cos(2*PI*i/(PTS*2.0)); //Re component of twiddle constants
w[i].imag =-sin(2*PI*i/(PTS*2.0)); /*Im component of twiddle constants*/
}

/****************Input Signal X(n)**********************************/


for(i=0,j=0;i<PTS;i++)
{ x[i] = sin(2*PI*5*i/PTS); // Signal x(Fs)=sin(2*pi*f*i/Fs);
samples[i].real=0.0;
samples[i].imag=0.0;
}

/********************Auto Correlation of X(n)=R(t)*******************/

for(n=0;n<PTS;n++)
{
sum=0;
for(k=0;k<PTS-n;k++)
{
sum=sum+(x[k]*x[n+k]); // Auto Correlation R(t)
}
iobuffer[n] = sum;
}

/********************** FFT of R(t) *****************************/

for (i = 0 ; i < PTS ; i++) //swap buffers


{
samples[i].real=iobuffer[i]; //buffer with new data
}

69
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0

FFT(samples,PTS); //call function FFT.c

/******************** PSD *******************************************/

for (i = 0 ; i < PTS ; i++) //compute magnitude


{
x1[i] = sqrt(samples[i].real*samples[i].real
+ samples[i].imag*samples[i].imag);
}

} //end of main

#define PTS 128 //# of points for FFT


typedef struct {float real,imag;} COMPLEX;
extern COMPLEX w[PTS]; //twiddle constants stored in w

void FFT(COMPLEX *Y, int N) //input sample array, # of points


{
COMPLEX temp1,temp2; //temporary storage variables
int i,j,k; //loop counter variables
int upper_leg, lower_leg; //index of upper/lower butterfly leg
int leg_diff; //difference between upper/lower leg
int num_stages = 0; //number of FFT stages (iterations)
int index, step; //index/step through twiddle constant
i = 1; //log(base2) of N points= # of stages
do
{
num_stages +=1;
i = i*2;
}while (i!=N);
leg_diff = N/2; //difference between upper&lower legs
step = (PTS*2)/N; //step between values in twiddle.h // 512
for (i = 0;i < num_stages; i++) //for N-point FFT
{
index = 0;
for (j = 0; j < leg_diff; j++)
{
for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff))
{
lower_leg = upper_leg+leg_diff;

temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real;


temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag;
temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real;
temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag;
(Y[lower_leg]).real = temp2.real*(w[index]).real
-temp2.imag*(w[index]).imag;
(Y[lower_leg]).imag = temp2.real*(w[index]).imag
70
+temp2.imag*(w[index]).real;
(Y[upper_leg]).real = temp1.real;
(Y[upper_leg]).imag = temp1.imag;
}
index += step;
}
leg_diff = leg_diff/2;
step *= 2;
}
j = 0;
for (i = 1; i < (N-1); i++) //bit reversal for resequencing data
{
k = N/2;
while (k <= j)
{
j = j - k;
k = k/2;
}
j = j + k;
if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag;
(Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
}

Additional Programs

Generation of Sinusoid

#include<math.h>
#define FREQ 1000

float a[128];
main()
{
int i=0;

for(i=0;i<128;i++)
{
a[i]=sin(2*3.14*FREQ*i/24000);
printf("%f",a[i]);
}
}

71
Expected Outputs

DIFFERENCE EQUATION
Purpose of Experiment

Description:-An Nth order linear constant – coefficient difference equation can be


represented as
N M

∑ ak y ( n−k )=∑ b r x( n−r )


k=0 r =0
If we assume that the system is causal a linear difference equation provides an explicit
relationship between the input and output..this can be seen by rewriting above equation.
M
y ( n )=∑ ¿ ¿ ¿ ¿
r=0

Sample Code
C Program to Implement Difference Equation
#include <stdio.h>
#include<math.h>
#define FREQ 400
float y[3]={0,0,0};
float x[3]={0,0,0};
float z[128],m[128],n[128],p[128];
main()

72
{
int i=0,j;
float a[3]={ 0.072231,0.144462,0.072231};
float b[3]={ 1.000000,-1.109229,0.398152};
for(i=0;i<128;i++)
{
m[i]=sin(2*3.14*FREQ*i/24000);
}
for(j=0;j<128;j++)
{
x[0]=m[j];
y[0] = (a[0] *x[0]) +(a[1]* x[1] ) +(x[2]*a[2]) - (y[1]*b[1])-(y[2]*b[2]);
z[j]=y[0];
y[2]=y[1];
y[1]=y[0];
x[2]=x[1];
x[1] = x[0];
}
}

Expected Outputs

73
Note: To verify the Difference Equation, Observe the output for high frequency and low
frequency by changing variable “FREQ” in the program.

Direct Implementation of DFT equation


#include<stdio.h>
#include<math.h>
int N,k,n,i;
float pi=3.1416,sumre=0, sumim=0,out_real[8]={0.0}, out_imag[8]={0.0};
int x[32];
void main(void)
{
printf(" enter the length of the sequence\n");
scanf("%d",&N);
printf(" enter the sequence\n");
for(i=0;i<N;i++)
scanf("%d",&x[i]);
for(k=0;k<N;k++)
{
sumre=0;
sumim=0;
for(n=0;n<N;n++)
{
sumre=sumre+x[n]* cos(2*pi*k*n/N);

sumim=sumim-x[n]* sin(2*pi*k*n/N);
}
out_real[k]=sumre;
out_imag[k]=sumim;
printf("X([%d])=\t%f\t+\t%fi\n",k,out_real[k],out_imag[k]);
}
}
74

You might also like