DSP Lab Manual 2023

Download as pdf or txt
Download as pdf or txt
You are on page 1of 85

DIGITAL SIGNAL PROCESSING LAB MANUAL

Subject Code: ECE 3141

V Semester B. Tech. ECE

DEPARTMENT OF
ELECTRONICS & COMMUNICATION ENGINNEERING

1
List of Experiments:

Sl. Name of the Experiment Page


No Number

1 Introduction to MATLAB and CCS 4

2 Time domain Analysis of Signals 16

3 Time domain Analysis of Systems 22

4 Frequency domain Analysis of Signals and Systems 31

5 Analysis in Z- domain 39

6 IIR Filter Design – I 48

7 IIR filter design – II 55

8 FIR filter design 66

9 Image Processing Applications 74

10 Audio and Communication applications 78

2
Instructions to the Students:

1. All the students are required to come prepared for the experiments to be done
in the lab.

2. Students should try to analyze and understand the solved problems and then
try to solve the unsolved problems of the experiment in the lab.

3. Maintaining an observation copy is compulsory for all, where the programs


(codes) and results of the unsolved-problems (exercise) are to be noted down.

4. Students have to get their results verified and observation copies checked by
the instructor before leaving the lab.

5. Maintain a separate folder in the computer you use, where you save all the
programs you do in the lab.

6. Use of external storage media during lab is not allowed.

7. Maintain the timings and the discipline of the lab.

8. Students will be evaluated in every lab based on individual performance,


observation copy and involvement in the lab.

Evaluation plan

• In-semester Assessment Marks : 60% (60 Marks)


✓ Continuous evaluation component (lab sessions 1 to 8): 10

marks each. This will be converted into 60 marks.


✓ Assessment is based on conduction of each experiment,

exercise problems, answering the questions related to the


experiment.

• End semester assessment: 40 % (40 marks)


✓ write up (coding, analysis): 20 marks
✓ Concept/Theory: 10 marks
✓ Viva-Voce: 10 marks

3
Experiment No. 1: Introduction to MATLAB and CCS

MATLAB (MATrix LABoratory) is an interactive program for scientific and engineering


numeric calculation, which has application in almost all the areas. MATLAB is one of the few
languages in which each variable is a matrix. Moreover, the fundamental operators (e.g.
addition, multiplication) are programmed to deal with matrices when required. In the MATLAB
environment, a matrix is a rectangular array of numbers. Special meaning is sometimes
attached to 1-by-1 matrices, which are scalars, and to matrices with only one row or column,
which are vectors. Unlike languages such as C and C++, there is no much syntax in the
MATLAB. Anyone having knowledge of simple programming language can work with the
MATLAB. So learning MATLAB programming is made easier using certain applications.
MATLAB is very rich with toolboxes, which consist of various functions depending on the
applications. These functions can be used as a command to perform particular operation. Let
us begin with starting MATLAB from the desktop. You can find a MATLAB icon on the desktop
or from the start menu. By double clicking the icon you can invoke the MATLAB command
window, which is shown in the figure 1.1

Figure 1.2: MATLAB Command Window

4
Command window consists of prompt for entering the command for the execution of the
particular function. Suppose we want to create a variable with a vector we can enter the
following at the command prompt and press ENTER key.

>> a = [1 2 3 4 5]

a=

1 2 3 4 5

This will create a vector with variable name ‘a’. If the command which is entered at prompt is
terminated by the semicolon, then the values corresponding to the variable is not shown in
the command window when you press the ENTER key. Similarly, the command, which does the
particular function, can be entered at the prompt, which is shown as follows.

>> a=ones (2, 2)

a=

1 1

1 1

The above shown command will create a matrix of size 2x2 with all ones. There are many
commands like this are available in the MATLAB, which are given in various tool boxes. In this
lab students will get acquainted with the usage of these commands using some examples. The
function rand will generate uniformly distributed random elements and randn will generate
normally distributed random elements.

R = randn(4,4)

R=

0.6353 0.0860 -0.3210 -1.2316

-0.6014 -2.0046 1.2366 1.0556

0.5512 -0.4931 -0.6313 -0.1132

-1.0998 0.4620 -2.3252 0.3792

The data set can be saved in a file such with an extension of .mat, .dat and .txt using save
command and same can be retrieved using load function. The load function reads binary files
containing matrices generated by earlier MATLAB sessions, or reads text files containing
numeric data. The text file should be organized as a rectangular table of numbers, separated
by blanks, with one row per line, and an equal number of elements in each row. For example,
outside of MATLAB, create a text file containing these four lines:

16.0 3.0 2.0 13.0

5.0 10.0 11.0 8.0

9.0 6.0 7.0 12.0

5
4.0 15.0 14.0 1.0

Save the file as myfile.dat in the current directory. The statement load myfile.dat reads the file
and creates a variable, containing the example matrix.

M-Files

You can create your own matrices using M-files, which are text files containing MATLAB code.
Use the MATLAB Editor to create a file containing the same statements you would type at the
MATLAB command line. Save the file under a name that ends in .m.

Let us learn this by writing a simple program for generating a sine wave and plotting it using
plot command. In File menu select the New option in and then select M-file.

Matlab editor window will open. Then enter the following program.

clc; % CLEARS THE COMMAND WINDOW

clear all; % CLEARS ALL VARIABLE

close all; % ALL THE EXISTING FIGURE WINDOWS WILL BE CLOSED

Fs = 1000; % SAMPLING FREQUENCY

f = 200; % SIGNAL FREQUENCY

t = 0:1/Fs:(2/f); % GENERATION OF THE TIME SEQUENCE FOR SINEWAVE

x = 5*sin(2*pi*f*t); % SINE WAVE GENERATION USING SINE FUNCTION

plot(t,x); % THE SINE WAVE IS DISPLAYED IN A SEPERATE PLOT WINDOW

The above program and editor window is shown in figure 1.1

6
Figure 1. 1 Matlab editor window with a program

Save the program from save menu with any meaningful file name. Strictly don’t use file
name, which is already a MATLAB command. This will overwrite the existing command file
which is a built in function. The program can be executed by selecting the Run option from
the Debug menu. The output is plotted in separate window which is shown in figure 1.3

Figure 1.2 Plot of the execution (sine wave)

Always use commands such as clc, close all and clear all, before starting any program in the
MATLAB editor.

Help for the MATLAB commands are available from the help menu or by typing help followed
by the command name in the command window.

Activity Questions

Students must complete the execution of activity questions in the lab and write down the
programs or answers in the observation book.

7
1. Study the following command function through the help menu and check it in the
command window with suitable illustrations:
i) fliplr vii) plot xiii) disp xix) angle
ii) zeros viii) title xiv) eye xx) abs
iii) linspace ix) subplot xv) num2str xxi) log
iv) sin x) who xvi) floor xxii) double
v) cos xi) whos xvii) sqrt xxiii) save
vi) figure xii) input xviii) exp xxiv) load
2. Assume array c is defined as shown, and determine the contents of the following sub-
arrays.
1.1 −3.2 3.4 0.6
𝑐 = [0.6 1.2 −0.6 3.1]
1.3 0.6 5.5 0.0
i) c(2,3) iv) c(1:2,2:end) vii) c(1:2,2:4)
ii) c(2,:) v) c(6) viii) c([1 3],2)
iii) c(:,end) vi) c(4:end) ix) c([2 2],[3 3])
3. Assume a, b, c and d are defined as follows
1 0 −1 2 3
𝑎= [ ],𝑏 = [ ],𝑐 = [ ],𝑑 = 5
2 1 0 1 2
What is the result of the following expressions?
i) a+b
ii) a+c
iii) a+d

iv) a .* b
v) a * b

8
Introduction to CCS: Code composer is the DSP industry’s first fully integrated
development environment (IDE) with DSP-specific functionality. With a familiar
environment liked MS-based C++, Code Composer lets you edit, build, debug, profile
and manage project from a single unified environment. Other unique features include
graphical signal analysis, injection/extraction of data signals via I/O, multi-processor
debugging, automated testing and customization via a C-interpretive scripting
language and much more.

Code Composer Studio (CCS) Features:

1. IDE
2. Debug IDE
3. Advanced watch windows
4. Integrated editor
5. File I/O, Probe points, and graphical algorithm scope probes.
6. Advanced graphical signal analysis
7. Interactive profiling
8. Automated testing and customization via scripting
9. Visual project management system
10. Compile in the background while editing and debugging
11. Multi-processor debugging
12. Help on the target DSP

General Procedure to work on Code Composer Studio V6 for non-


real time projects Using target:

1. Launch CCS: Launch the CCS v6 icon from the Desktop or go to All Programs -> Texas

Instruments -> CCSv6

2. Choose the location for the workspace, where your project will be saved.

3. Creating a New Project:

→Go to File →New →CCS Project.

→Specify the name of the project in the space provided e g., Project Name: test

4. Specify the “Device” properties as shown in the figure below.

9
Note: For newly arrived kits use “connection”: Texas Instruments XDS100V3 USB
Debug pro

Press “verify” button to check the proper connection of the kit with the system.

5. Choose the Linker command file: as “linker_dsp.cmd” (Browse from Supporting


files folder given at the time of installation)

6. Click Finish

7. Type your C Code and save.

10
8. BUILD
Build the program to check your code.
Go to
Project → Build project.

Window will display errors or warnings, if any.

9. DEBUG
After successful Build, connect the kit with the system using the JTAG
emulator and power the kit.
Click the Debug as shown in the below figure.

It will redirect to the Debug perspective automatically. It an error


message pops out, press the reset button of the kit and retry.

10. RUN
Wait until the program loaded to the hardware automatically.
Now you can run the code, by selecting Run-> Resume.

11
Once you run the program the output will be printed in the Console Window.

SINE WAVE GENERATION


Procedure to create a simple non-real time project - Sine wave Generation:

Repeat the steps 1 to 6.


In step 7, write the following C code:

Once you run the program, 128 no’s of sine samples has been printed in the Console
Window.

To view the values in graph


Go to Tools → Graph →Single Time

12
Set the Graph Properties as shown in the Picture

Buffer size: 128 (No. of samples)

DSP Data Type: 32-Bit floating point

Start Address: m

Display Data Size: 128

Click: Ok
Graph will be plotted as shown below:

13
GENERAL PROCEDURE FOR WORKING WITH THE REAL TIME
PROJECTS USING C6748LCDK:
Repeat the steps 1 to 6 of previous method and Create the source file (C-code) and
save it.

1. Now add the following library files and supporting files of codec to your project. To
add files, go to Project-> Add files.

Follow the path given below to add the required files:

2. Right click on the project name and choose “Show Build Settings..”
➔ Build-> C6000 Compiler-> Include Options -> Click “Add” as shown in the figure.

• Now Click File system -> supporting files->bsl->inc->OK.

Now, Build Project, Load and Resume the project.

14
According to your requirement you can use the following connections:

Expt. 1 – Non real time

Expt. 2 – CRO to Line out

Expt. 3 – Non real time

Expt. 4 - Non real time

Expt. 7 and 8: AFO to Line in and CRO to Line out

Expt. 8 – Non real time

Experiment 10: Audio input to Line in or Speaker to line out.

OR

MIC input to MIC in and Speaker to Line out.

15
Experiment No. 2: Analysis of signals in time domain

Objective:
To study signals in time-domain and understand the concepts of generation
of signals and sampling,

Signal generation and sampling

The signals we use in the real world (such as voice signal) are "analog"
signals. To process these signals in computing devices, we need to convert
them in to "digital" form. While an analog signal is continuous in both time
and amplitude, a digital signal is discrete in both time and amplitude. To
convert a signal from continuous time to discrete time, sampling is used. The
value of the signal is taken at certain intervals in time to get discrete samples
of the signal.

The Sampling Theorem states that a signal can be exactly reproduced if it is


sampled at a frequency Fs, where Fs is equal or greater than twice the
maximum frequency in the signal (Nyquist rate). The sampling frequency or
sampling rate, Fs, is the average number of samples obtained in one second
(samples per second), thus Fs = 1/T. As the sampling frequency decreases,
the signal separation also decreases. When the sampling frequency drops
below the Nyquist rate, the frequencies will crossover and cause aliasing. In
MATLAB signals can be simulated using functions where the duration and
the sampling time can be specified.

16
Example-1: Generate and plot the following signals
a) Unit-step function
b) Delayed step function with a delay of n0 = 5.
c) Step function with amplitude m= 5
d) Rectangular window of length 5;
e) Ramp signal

Solution:

clc; % clears the command window


clear all; % clear all variables
close all; % all the existing figure windows will be closed
n = 0:15; % time index for the discrete signal from 0 to 15 with
unity sampling
% time
u = [(n)>=0]; % Unit Step
u5 = [(n-5)>=0]; % Delayed step
a5 = 5* u; % Scaled unit step
xn = u-u5; % rectangular window x[n]= u[n]- u[n-5]
xr = n.*u; % Ramp signal

% v(1:16) = ones(1,16) also defines the unit step vector v of length 16 or a


rectangular
%window of size 16.

subplot(321), stem(n,u), title('Unit-step Function'); ylabel('Amplitude ');


subplot(322), stem(n,u5), title('Delayed Unit-step Function');
subplot(323), stem(n,a5), title('Amplitude scaled step function
');ylabel('Amplitude');
subplot(324), stem(n,xn), title('Window function ');ylabel('x[n]');xlabel('n --
--->')
subplot(325), stem(n,xr), title('Ramp
Function');ylabel('Amplitude');xlabel('n ---- >');

17
Output:

Unit-step Function Delayed Unit-step Function


1 1
Amplitude

0.5 0.5

0 0
0 5 10 15 0 5 10 15

Amplitude scaled step function Window function


5 1
Amplitude

x[n]
0.5

0 0
0 5 10 15 0 5 10 15
n ----->

18
Ramp Function
20

Amplitude
10

0
0 5 10 15
n ----- >

Figure 2.1 Results of example-1

Example-2: MATLAB code to generate sine wave at different


sampling frequencies.

clc;
clea
r
all;
clos
e
all;
Fs = 1000; % sampling frequency
f = 200; % signal frequency
T = 0:1/Fs:(1/f); % generation of the time sequence at sampling
% frequency fs for 1 period duration.
x = 5*sin(2*pi*f*t); %sine wave of freq. Of f hz and
amplitude 5; sampled at fs
subplot(3,1,1); stem(t,x);
title('Sine wave sampled at 1000 Hz 1 period duration'); ylabel('Amplitude')
Fs1 =10000; % Different sampling
frequency f = 200;
t = 0:1/Fs1:(1/f);
x=
5*sin(2*pi*f*t);
subplot(3,1,2);stem
(t,x);
title('Sine wave sampled at 10000 Hz for 1 period
duration '); ylabel('Amplitude')

Fs1 =10000; % another sampling frequency


T = 0:1/Fs1:(2/f); % generation of the time sequence at
sampling frequency fs
%for 2 cycle duration
x=
5*sin(2*pi*f*t)
;
subplot(3,1,3);
stem(t,x);
title('Sine wave sampled at 10000 Hz for 2 cycle
duration'); ylabel('Amplitude')
xlabel('n ----- >');

19
Output:
Sine wave sampled at 1000 Hz 1 period duration
5
Amplitude
0

-5
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
-3
x 10
Sine wave sampled at 10000 Hz for 1 period duration
5
Amplitude

-5
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
-3
x 10
Sine wave sampled at 10000 Hz for 2 cycle duration
5
Amplitude

-5
0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01
n ---- >

Figure 2.2 Results of example 2

Example-3: C-program to generate triangular waveform

#include<stdio.h>
int res[32];
main()
{ int j ,k=0,l,m,n;
for(j=0;j<4;j++)
{ m =0 ;
n= 3;
for(l=0;l<8;l++)
{
if(l<5)
{ res[k]=m++;
printf("%d\n",res [k]);
k++;
}
else
{ res[k]=n--;
printf("%d\n",res[k]);
k++;
}
}//for l
}//for j
k++;
}

20
Figure 2.3 Results of example 3

Example 4: Generation of real time Sine Signal

#include "L138_LCDK_aic3106_init.h"
#include "math.h"
#define SAMPLING_FREQ 48000
#define PI 3.14159265358979
float frequency = 1000.0;
float amplitude = 20000.0;
float theta_increment;
float theta = 0.0;
interrupt void interrupt4(void) // interrupt service routine
{
theta_increment = 2*PI*frequency/SAMPLING_FREQ;
theta += theta_increment;
if (theta > 2*PI) theta -= 2*PI;
output_left_sample((int16_t)(amplitude*sin(theta)));
return;
}
int main(void)
{
L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT
);
while(1);
}

Exercise: 1. Generate the following signals


a) (-1/2)k, (2)k and (-2)k, assuming k = 0 to 15
b) Square wave with duty cycle 25%, 50% and 75%. (Use square
function)
c) Triangular wave. (Use sawtooth function)
d) A multi-tone signal having the frequencies 10Hz,
30Hz and 60Hz.
2. Write a MATLAB program to sketch the following discrete-time
signals in the time range of -10 n 10. If the sequence is complex,
plot the magnitude and angle separately. Note: Study the difference
between plot and stem functions of MATLAB
a) x[𝑛] = u[𝑛] − 𝑢[𝑛 − 3]
𝑛𝜋
b) x[𝑛] = 0.5𝑛𝑒𝑗𝜋𝑛/2 c) x[n] =sin( )u[n]
3

21
Experiment No. 3: Time domain analysis of systems.

Objective:
To study systems in time-domain and understand the concepts of
convolution, correlation and impulse response.

Example-1: Write a MATLAB program to find and plot the convolution


between the two signals x = u - u5 and y = [1 2 3 4 5] where u is unit
step function in the range 0:15.
Solution:

Use conv(x, y) MATLAB function to perform the convolution and


plot the signals

Example-2: Given a discrete-time sequence x[𝑛] =


{3, 11, 7, 0, −1, 4, 2} and y[𝑛] = x[𝑛 − 2] + 𝑤[𝑛], where 𝑤[𝑛] is a Gaussian
sequence with zero mean and unit variance. Compute the cross- correlation
between x[𝑛] and y[𝑛].

Solution:

clc;
close all;
clear all;
x = [3,11,7,0,-1,4,2]; % Given sequence x[n]

nx = -3:3;
ny = nx + 2; % Shifted x[n] ; delay of 2
units
y1 = x;
w = randn(1, length(y1)); % Random sequence

22
generation
y = y1 + w;
nyb = ny(1)+nx(1); % Starting point
nye = ny(length(y1))+nx(length(x)); % Ending point
ny = nyb:nye;
xcr = xcorr(x,y); % cross-correlation
plot(ny,xcr);
title('Cross-correlation example');
xlabel('Time, n');

Output:

Cross-correlation example
200

180

160

140

120

100

80

60

40

20

0
-4 -2 0 2 4 6 8
Time, n

Figure 1: Cross correlation

Note: The signal x and its delayed signal y have maximum correlation at time
n = 2. Hence, the correlation plot shows a maximum peak at n = 2. Such
signal processing is used in Radar applications.

Example-3: Determine the UNIT impulse response h[n] of a system


described by the difference equation [𝑛] − 0.6𝑦[𝑛 – 1] − 0.16𝑦[𝑛
– 2] = 5𝑥[𝑛]

23
Solution:

clc;
close all;
clear all;
N = 20;
b = [5 0 0];
a = [1 -0.6 -0.16];
f = [1, zeros(1,N-1)]; % generation of unit impulse δ[n]
h = filter(b, a, f); % input to the system is δ[n]; output is impulse
response h[n]
n = 0: 1: N-1;
stem(n, h);
title('Unit Impulse Response, h[n]'), xlabel('n'), ylabel('Amplitude');

Output:

Unit Impulse Response, h[n]


5

4.5

3.5

3
Amplitude

2.5

1.5

0.5

0
0 2 4 6 8 10 12 14 16 18 20
n

Figure 2: Response of system

Note: Refer MATLAB help for details of filter function

24
Exercise:
1. Find the system output y[n]; 0 n 10 of an LTI system with impulse
response
h[n] = (0.5)𝑛{𝑢[𝑛] – 𝑢[𝑛 – 10]) when the inputs are
a) 𝑥[𝑛] = (0.8)𝑛(𝑢[𝑛]– 𝑢[𝑛 − 5])
b) x[n] = δ[n] + 3δ[n – 1] + 4δ[n – 3]

2. A simple digital differentiator is given by [𝑛] = [𝑛] − 𝑥[𝑛 − 1].


Implement this differentiator and test with the following sequences. Plot
the results and comment on the appropriateness of this differentiator.
a) [𝑛] = 5([𝑛] − 𝑢[𝑛 − 20])
b) [𝑛] = (𝑢[𝑛] − 𝑢[𝑛 − 10]) + (20 − 𝑛)(𝑢[𝑛 − 10] −
[𝑛 − 20])

𝜋𝑛
c) 𝑥 [𝑛] = sin ( 25 )(𝑢[𝑛] − 𝑢 [𝑛 − 100]))

25
3. Write a MATLAB program to generate a pure sine wave of frequency
80Hz and add additive white Gaussian noise with SNR of 10dB. (Use the
function awgn.) Find and plot the autocorrelation of the resulting
sequence.

Code Composer studio

Experiment 1: To perform circular convolution.

/* prg to implement circular convolution */


#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) /*Iflenght 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;
}

26
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]);

27
Experiment 2: To perform linear convolution.

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

Experiment 3: To perform autocorrelation .

#include<stdio.h>
#include<math.h>
#define PI 3.14
#define PTS 512

float x[PTS]; //INPUT ARRAY


float y[PTS];
float z[PTS]; //OUTPUT ARRAY

void main()
{
int i,j;
for (i = 0 ; i < PTS ; i++)
28
{
x[i] = sin(2 * PI * 100 * i / 8000.0);
y[i]=0.0;
}

for(i=0 ; i< PTS ; i++)


{
for(j = 1 ; j < (PTS-i+1) ;j++)
{
y[i]=y[i]+x[j]*x[j+i-1];
}
z[i]=y[i]/(PTS);

Experiment 4: To perform cross correlation.

#include<stdio.h>
#include<math.h>
#define PI 3.14
#define PTS 512

float x[PTS]; //INPUT ARRAY


float y[PTS];
float z[PTS]; //OUTPUT ARRAY#include<stdio.h>
#include<math.h>
#define PI 3.14
#define PTS 128
float x[PTS];
float y[PTS];
float z[PTS];
float n[PTS];

void main()

29
{
int i,j;
for (i = 0 ; i < PTS ; i++)
{
x[i] = sin(2*PI*i*20/128.0);
y[i]=0.0;
n[i]=x[i] + rand() * 10 ;
}

for(i=0;i< PTS ;i++)


{
for(j = 1 ; j < (PTS-i+1) ;j++)
{
y[i]=y[i]+x[j]*n[j+i-1];
}
z[i]=y[i]/(PTS);
}
}

void main()
{
int i,j;
for (i = 0 ; i < PTS ; i++)
{
x[i] = sin(2 * PI * 100 * i / 8000.0);
y[i]=0.0;
}

for(i=0 ; i< PTS ; i++)


{
for(j = 1 ; j < (PTS-i+1) ;j++)
{
y[i]=y[i]+x[j]*x[j+i-1];
}
z[i]=y[i]/(PTS);
}}
30
Experiment 4

Frequency domain Analysis of Signals and Systems

Objectives:
To study the frequency-domain representation of signals and systems.

Theory: The Discrete Time Fourier Transform (𝑒𝑗𝜔) of the impulse


response is called the frequency response.

For infinite-duration impulse response (IIR) system

𝐵(𝑒𝑗𝜔) 𝑏0 + 𝑏1𝑒−𝑗𝜔 + 𝑏2𝑒−𝑗𝜔 …


𝐻(𝑒𝑗𝜔) = =
𝐴(𝑒𝑗𝜔) 1 + 𝑎0 + 𝑎1𝑒−𝑗𝜔 + 𝑎2𝑒−𝑗𝜔 …

For finite-duration impulse response (FIR) systems

(𝑒𝑗𝜔) = 𝑏0 + 𝑏1𝑒−𝑗𝜔 + 𝑏2𝑒−𝑗𝜔 …

Example-1: Find Discrete-time Fourier transform (DTFT) of the given


signal and plot the magnitude and the phase.

31
Solution:
clc;
clear all;
close all;
w = [0:1:500]*pi/500; % defining 501 values of radian frequency ω
in the range 0 to π
x = exp(j*w)./(exp(j*w)-0.5);
subplot(121)
plot(w, abs(x)), title('Magnitude response'), xlabel('w'), ylabel('Amplitude');
subplot(122), plot(w,angle(x));
title('Phase Response'), xlabel('w(radians)'), ylabel('Angle');

Output:

Figure 4.1 Results of example-1

32
Example-2: Verify the symmetry property of DTFT for the impulse
response given below:
ℎ[𝑛] = 𝑎𝑛𝑢[𝑛], |𝑎| < 1

Solution:
clc;
clear all;
close all;

b = [1 0 0];
a = [1 -0.5 0]; % assuming a = 0.5
N = 512;
[h w] = freqz(b,a,N,'whole');
w = w-pi;
subplot(121), plot(w,abs(h));
title('Magnitude Response'), xlabel('w(radians)'), ylabel('Amplitude');
subplot(122), plot(w,angle(h));
title('Phase Response'), xlabel('w(radians)'), ylabel('Angle');
Output:

33
Figure 4.2 Results of example-2
Discrete Fourier Transform

The DTFT spectrum is continuous and hence it is difficult to evaluate on a


computer. So to make the evaluation of the DTFT possible on a computer,

we choose a finite number of frequency points. This is equivalent to sampling


the DTFT at a certain number of points. This is called the Discrete Fourier
Transform (DFT). ‘fft’ function in MATLAB is used to compute DFT of
finite duration signal. DFT length should be at least equal to the length of the
signal or more. By default function fft has length equal to the length of the
signal.

Example-3: Find the Discrete Fourier Transform (DFT) of a windowed sine


wave of frequency 30Hz and plot the magnitude and phase. (Use fft function)
Solution:
clc; clear all; close all;
frq = 30;
Fs = 1000;
34
t = 0:1/Fs:1; %window length is 0 to 1
x = sin(2*pi*frq*t);
X = fft(x); % fft(x, M) can be used to control the DFT length
l = length(X)/2;
f = (0:(l-1))*Fs/(2*l);
subplot(311), plot(t, x);
title('Sine wave of frequency 30Hz');
xlabel('Time in sec');ylabel('Amplitude');
subplot(312), plot(f,abs(X(1:l)));zoom on;
title('Magnitude Response'); ylabel('Amplitude');
ang=(angle(X(1:l)) * (180/pi));
subplot(313), plot(f, ang);
title('Phase Response');xlabel('Frequency in Hz'); ylabel('Angle in
Degrees');

35
Output:

Sine wave of frequency 30Hz


1
Amplitude

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time in sec
Magnitude
Response
500
Amplitude

0
0 50 100 150 200 250 300 350 400 450 500

Phase Response
Angle in Degrees

200

-200
0 50 100 150 200 250 300 350 400 450 500
Frequency in Hz

Figure 4.3 Results of example-3

NOTE: Refer MATLAB help for fft function

DFT Implementation using CCS toolkit:


Example-4: Find the 8-point DFT of the sequence x(n)=[1, 2, 1, 2, 1,
4] using CCS toolkit.
Solution:
#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;

36
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]);
}
}
Output:

Figure 4.4- Output console window of example-4

37
Exercise:

1.Let Determine and verify its


periodicity property.

2.Determine the frequency response of the filters, which are represented by


the difference equations given below. Also, state what type of filter each
defines by observing the response (like HPF, LPF etc..).

3.Find and plot the frequency response of a causal 3-point moving averager.
Generate first 100 samples of 0.9n u[𝑛] and corrupt it using a random signal.
Pass the corrupted signal through the moving point averager and plot the
output.

4.Find the DFT of multitone sine wave with 30Hz, 80Hz, 120Hz frequency
components and plot the magnitude vs. frequency in Hz.

5.Write a MATLAB program to compute the circular convolution of two N-


length sequences using DFT/IDFT computations. Use it to determine the
circular convolution of the following pair of sequences. Also demonstrate how
linear convolution is achieved through circular convolution.

38
Experiment No. 5: Analysis in Z-domain
Objective:

To study the Z-domain analysis of signals and systems.

Introduction:

Z-transform maps a signal in the time domain to a power series in the


complex (frequency) domain. There are many advantageous to working with
z-transformed signals. The algebra of system analysis becomes greatly
simplified in the z- domain. The response y[n] of an LTI system with impulse
response h[n] to input x[n] is given by the convolution x[n] *h[n], which
becomes product in Z-domain. The ratio H(z) = Y(z)/X(z) is called system
function. In MATLAB residuez function is used to convert from rational z-
transform to partial fraction form and vice-versa. In using residuez function,
the z- transfer function is expressed as a rational function with ascending
powers of z-1.

Example-1: Consider a causal LTI system described by the difference


equation given by y(n) – 1.81y(n - 1) + 0.81y(n − 2) = x(n) + 0.5 x(n − 1).
Write MATLAB program to obtain the following

a) System function H(z) in the partial fraction form


b) Pole – zero plot
c) Frequency response of the system
d) Unit impulse response of the system
n
e) Output of the system for the given input x[n] = 3cos( )u[n]
3

39
Solution:
clc;
clear all;
close all;

b = [1 0.5]; % Coefficients of numerator polynomials


a = [1 -1.8 0.81]; % Coefficients of denominator
polynomials

% To obtain system function in the partial fraction form

[r p k]=residuez(b,a); % finds the residues, poles and direct


terms of the partial-%fraction expansion of the system function.
disp(['r = ' num2str(r')]);
disp(['p = ' num2str(p')]);
disp(['k = ' num2str(k')]);

% To obtain The pole – zero plot

[z p k] = tf2zp(b,a); % To obtain zeros , ploes and gain constant


of the system.
disp('Zeros are at'); disp(z);
disp('poles are at'); disp(p);
disp('Gain Constant is'); disp(k);
zplane(b,a); % Gives the pole – zero plot

% To obtain frequency response of the system

N = 512; % Frequency resolution assumed.


[h w] = freqz(b,a,N);% returns the N-point complex frequency
response
%vector h and the N-point frequency vector w in radians.
figure;
subplot(211), plot(w,abs(h)), title('Magnitude Response');
40
xlabel('Frequency in radians'), ylabel('Amplitude');
subplot(212), plot(w, angle(h)), title('Phase Response');
xlabel('Frequency in radians'), ylabel('Phase in radians');

% To Obtain the unit impulse response of the system

L = 30; % First 15 values of the impulse response


[y n] = impz(b,a,L);
figure;
stem(y), title('Impulse Response, h[n]');
grid on;
xlabel('Sample Number'), ylabel('Amplitude');

% To find the output of the system for the given input

n = 0:100;
u = [n>=0];
x = 3*cos(n*pi/3).*u; % input signal
y = filter(b, a, x); % o/p signal
figure;
subplot(211), plot(n,x);
subplot(212), plot(n,y);

Output:

r = -0.55556 1.5556

p = 0.9 0.9

k=0

41
Figure 4.1 Pole zero plot

Zeros are at -0.5000. Poles are at 0.9000 and 0.9000. Gain


Constant is 1

Magnitude Response
150

100
Amplitude

50

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

-1

-2

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

Figure 4.2 Frequency response


42
Impulse Response, h[n]
6

4
Amplitude

0
0 5 10 15 20 25 30
Sample Number

Figure 4.3 Impulse response

-2

-4
0 10 20 30 40 50 60 70 80 90 100

15

10

-5
0 10 20 30 40 50 60 70 80 90 100

Figure 4.4 Input and output of the system


43
Example-2: Consider a causal LTI system described by the difference
1
equation y(n) = [x(n) + x(n −1) + x(n − 2)] + 0.95y(n −1) − 0.9025y(n − 2)
3
with initial conditions y(−1) = −2, y(−2) = −3; x(−1) = 1, x(−2) = 1. Write
a MATLAB program to determine the response of the system for the input

x(n) = cos( n) u(n) .
3

Note: Analytical Solution has the following steps.

Step1: Compute one sided z-transform of the difference equation

1
Y + (z) = [ X + (z) + x(−1) + z −1 X + (z) + x(−2) + z −1 x(−1) + z −2 X + (z)]
3
+ 0.95[ y(−1) + z −1Y + (z)] − 0.9025[ y(−2) + z −1 y(−1) + z −2Y + (z)

Step2: Substitute the initial condition.

1 1 −1 1 −2
+ z z
Y (z) = 3 3 3
+
X + (z) + 1.4742+ 2.1383z −1

1− 0.95z −1 + 0.9025z −2 1− 0.95z −1 + 0.9025z −2

1− 0.5z −1
Step3: Compute X +(z) =
1− z −1 + z −2

+
and simplifying, we will obtain Y (z) as a rational function.

Step4:
0.0584+ j3.9468 0.0584- j3.9468 0.8453+ j2.0311 0.8453- j2.0311
Y+ (z) = − j
+ j
+ j
+ − j

1−e 3 z−1 1 − e 3 z−1 1 − 0.95e z


3 −1
1- 0.95e 3 z−1

44
Step5: By applying the inverse z- transform
− jn jn
y(n) = (0.0584 + j3.9486)e 3
+ (0.0584 − j3.9486)e 3
+

jn − jn
(0.8453+ j2.031)(0.9 5) e n 3
+ (0.8453. j2.031)(0.95) e n 3

MATLAB solution:

clc;
clear all;
close all;
a = [1 -0.95 0.9025]; % Denominator coefficient as in step 2
b = [1 1 1]/3; % Numerator coefficient as in step 2
y = [-2 -3]; % Initial conditions array
x = [1 1]; % Initial conditions array
xic = filtic(b,a,y,x); % converts past input x and output y into
initial %conditions which is required for the
computation of %Y(z). Refer Step 2
ax = [1 -1 1]; bx = [1 -0.5]; % X(z) transform coeffs
ay = conv(a, ax) % Gives denominator polynomial coefficients
of Y(z)
by = conv(b, bx) + conv(xic,ax)% Gives numerator polynomial
coefficients of Y(z)
[R, p, C] = residuez(by, ay);
disp('Residues '), disp( R), disp('Ploes '), disp( p), disp('Direct Term

'), disp(C);

Output:

Denominator and numerator coefficients of respectively are

ay = 1.0000 -1.9500 2.8525 -1.8525 0. Y+(z) 9025

by = 1.8075 0.8308 -0.4975 1.9717

45
The Y+(z) in the partial fraction form has residues, pole values as shown
below.

Residues

0.0584 - 3.9468i

0.0584 + 3.9468i

0.8453 + 2.0311i

0.8453 - 2.0311i

Ploes

0.5000 + 0.8660i

0.5000 - 0.8660i

0.4750 + 0.8227i

0.4750 - 0.8227i

From the above we can write the Y+(z) as

0.0584+ j3.9468 0.0584- j3.9468 0.8453+ j2.0311 0.8453- j2.0311


Y+ (z) = − j
+ j
+ j
+ − j

1−e 3 z−1 1 − e 3 z−1 1 − 0.95e z


3 −1 1- 0.95e 3 z−1

And by taking the inverse z- transform we get


− jn jn
y(n) = (0.0584 + j3.9486)e 3
+ (0.0584 − j3.9486)e 3
+

jn − jn
(0.8453+ j2.031)(0.9 5)n e 3
+ (0.8453. j2.031)(0.95)n e 3
,

46
n ≥ 0.
Exercise:
1. An anti-causal LTI system is described by the system function
(z 2 −1)
H (z) = . Determine the following analytically and using
(z − 3)2
MATLAB
a) impulse response
b) difference equation representation
c) pole-zero plot

d) output y[n] if the input is x(n) = 3sin( n) u(n)
3

2. Write a MATLAB program to determine the system function of a


system for which the location of zeros and poles, and the value of the
gain factor are specified. Test this program for various specifications.

3. Consider a causal LTI system described by the difference equation


y]n] = x[n] − x[n −1] + 0.81y[n − 2] with initial conditions y(−1) =

y(−3) = 2 Write a MATLAB program to determine the response of


the system for the input x(n) = 0.7n u[n +1] .

47
Experiment No. 6: IIR Filter Design – 1

Objective: To design and study analog infinite-duration impulse response


(IIR) filters.

Theory: Digital IIR filters are mainly designed from analog filters (classical
techniques). The widely used IIR filters are Butterworth, Chebyshev l (Type
I and II), and Elliptic.

Butterworth filters:

The magnitude response low pass Butterworth filter is |(𝑗Ω)| =


1
Ω
√1+(Ω )2𝑁
𝑐

Here N is the order of the filter and Ωc = 3dB cut-off frequency (rad/sec).

A typical magnitude response plot is shown below

Figure 5.1 Magnitude response of Butterworth LPF

In the above figure, Rp and Rs represent the pass band and stop band
attenuations, respectively, and Ω𝑝 and Ω𝑠 are the corresponding edge
frequencies in rad/sec.
48
Chebyshev: A Chebyshev filter with ripples in pass-band is categorized as
type-1, whereas, the one with ripples in the stop-band comes under type-2.
The figures shown below are examples of type-I filters.

Figure 5.2 Magnitude response of type-1 Chebyshev filter with N odd

Figure 5.3 Magnitude response of type-1 Chebyshev filter with N even

49
Elliptic: They have ripples in both pass band and stop-band.

Figure 5.4 Magnitude response of elliptic filter

Implementation in MATLAB:

The following functions are available in MATLAB to design an analog low


pass filters.

1. [N,Wc] = buttord(wp,ws,Rp,Rs,'s') finds the minimum order N and


cutoff frequency Wc for an analog low pass Butterworth filter where
wp and ws are the edge frequencies in radians per second.
2. [b,a] = butter(N,Wc,'s') returns the transfer function coefficients of
an Nth order analog lowpass Butterworth filter with cutoff angular
frequency Wc.
3. buttap(N) designs a unity cutoff LPF (these are referred to as
prototype filters)
4. Similarly, cheb1ord/cheby1, cheb2ord/cheby2, ellipord/ellip
50
functions can be used to design Chebyshev lowpass (Type 1 and 2),
and Elliptic lowpass respectively.

Note: Refer to MATLAB documentation for more information.

Example-1: Design an analog Butterworth low-pass prototype filter of order


5. Use it to get an unnormalized Butterworth filter with cutoff frequency of
0.2π rad/sec.
Solution:
clc; clear all; close all;
N = 5; % given order of the filter
omegac = 0.2*pi; % Given cutoff frequency
[z, p, k ] = buttap(N); % Getting the prototype
p1 = p* omegac;
k1 = k* omegac ^N;
B = real(poly(z));
b0 = k1;
b = k1*B;
a = real(poly(p1));

Solution:
b= 0.0979
a= 1.0000 2.033 2.0671 1.2988 0.5044 0.0979

51
Example-2: Design an analog Butterworth low-pass filter, given the
following specifications and also plot the frequency response.
Rp = 1dB, Rs = 40dB, fp = 100Hz and fs = 500Hz

Solution:

clc;
clear all;
close all;
rp = 1; %Pass-band attenuation
rs = 40; %Stop-band attenuation
wp = 2*pi*100; %Frequency should be in rad/sec
ws = 2*pi*500;
[N, wc] = buttord(wp,ws,rp,rs,'s'); %Getting the order N and the
3dB cut-off freq
[b, a] = butter(N,wc,'s'); %Getting the numerator &
denominator polynomial coeffs
[H, W] = freqs(b,a); %Complex freq.response of analog
filter
plot(W/(2*pi),20*log10(abs(H))), grid on;
title('Frequency Response');
xlabel(' Frequency in Hz '),ylabel(' Magnitude in dB ');
disp(' the order and cut off frequency in Hz are '),disp( N),disp(
wc/(2*pi));

52
Solution:
Order: 4
Cut-off frequency(Hz): 158.119
Frequency Response
0

-10

-20

-30
Magnitude in dB

-40

-50

-60

-70

-80

-90
0 200 400 600 800 1000 1200 1400 1600
Frequency in Hz

Figure 5.5 Frequency response

53
Exercise
1. Given the following filter specifications: Passband edge: 200Hz;
Rp= 1dB; Stopband edge: 700Hz; Rs= 50 dB.
a. Design an analog lowpass Butterworth filter
b. Design an analog lowpass Chebyshev Type 1 filter
c. Design an analog lowpass Chebyshev Type 2 filter
d. Design an analog lowpass Elliptic filter

Plot the frequency response for each case and compare them.

2. Given the following filter specifications: Passband edge: 1kHz; Rp=


1dB; Stopband edge: 200Hz; Rs= 50 dB.
a. Design an analog high pass Butterworth filter
b. Design an analog high pass Chebyshev Type 1 filter

Note: Refer “butter” function to design high pass and other filters.

54
Experiment No. 7: IIR Filter Design – 2

Theory: The analog filters designed in the previous experiment can be


transformed into digital filter using impulse invariance or bilinear
transformation (BLT) methods.

Implementation details: The following functions are available in


MATLAB:

1. [bz, az] = impinvar(b, a, Fs) creates a digital filter with numerator


and denominator coefficients bz and az, respectively, whose impulse
response is equal to the impulse response of the analog filter with
coefficients b and a, scaled by 1/Fs (Fs = sampling frequency).
2. [numd, dend] = bilinear(num, den, Fs) convert an s-domain transfer
function given by num and den to a discrete equivalent using BLT
method.

Refer to MATLAB documentation for more information.

Note: The functions buttord and butter can also be used to design a digital
filter directly. For example, the following function returns the order N and
the cutoff frequency of digital filter with specifications, wp, ws, rp, rs.

[N, wc] = buttord(wp, ws, rp, rs);

Here rp and rs must be in dB & wp and ws must be normalized to π or half


the sampling frequency. (e.g. If fp is 100Hz, then wp = 2*fp/Fs). Therefore,
the range for wp and ws is always 0 to 1.

3. [b, a]=butter(N, wc) - By default the function butter(N, wc) uses


bilinear transformation with frequency prewarping.

4. Similarly, cheb1ord/cheby1, cheb2ord/cheby2, ellipord/ellip

55
functions can be used to design Chebyshev lowpass (Type 1 and 2), and Elliptic
digital IIR filters respectively.

Refer to MATLAB documentation for more information.

Example-1: Design a low-pass digital filter using an analog Butterworth


filter to satisfy 𝜔𝑝 = 0.2𝜋 𝑟𝑎, 𝜔𝑠 = 0.3𝜋 𝑟𝑎𝑑, 𝑅𝑝 = 1 𝑑𝐵, 𝐴 = 15 𝑑𝐵. Use the
impulse invariance technique to digitize (use impinvar function).

Solution:

clc, clear all , close all;


% Digital Filter specification
wp = 0.2*pi;
ws = 0.3*pi;
rp = 1;
rs = 15;

% Analog design
T = 1; % assumed
wa_p = wp/T;
wa_s = ws/T;

% Butterworth filter design


[Nb, wcb] = buttord(wa_p,wa_s, rp, rs, 's');
[bb_s,ab_s] = butter(Nb, wcb, 's');
disp('For Butterworth, the order and cut off frequency are '),
disp( Nb),disp(wcb);
[Hb,wb] = freqs(bb_s,ab_s); % Analog freq. response

% Transformation from analog to digital


[bb_z, ab_z] = impinvar(bb_s,ab_s,1/T);
[Hbd, wbd] = freqz(bb_z,ab_z); % Digital freq. response
figure(1); plot(wbd/pi,20*log10(abs(Hbd))),grid on;
ylabel('Magnitude in dB' ) ;
xlabel('Frequency in pi units’) ;

56
Figure 7.1 Frequency response

Example-2: Simulate a signal with 50Hz and 200 Hz frequency. Filter the
signal through a 3rd order digital Butterworth LPF with 3-dB cutoff frequency
100 Hz. Plot the spectrum of the input and the filtered signal.
Solution:

clear all; clc ; close all


Fs = 1000; % Sampling rate
t = 0:1/(Fs):0.5;
wc = 2*100/Fs %Normalized 3 dB cutoff freq. for the
filter
x = sin(2*pi*t*50) + sin(2*pi*t*200);
[b,a] = butter(3,wc); %Getting the numerator &
denominator polynomial coeffs
[H,W] = freqz(b,a,Fs); %Complex freq. response of analog
filter
figure(1);

57
k=W*Fs/(2*pi); % defining frequency vector for
plotting
plot(k,20*log10(abs(H))), grid on;
title('Frequency Response');
xlabel(' Frequency in Hz '),ylabel(' Magnitude in dB ');
% Filter testing
yb = filter(b,a,x) ;
% Getting spectrum and plot
N = 512;
w = [0:N/2 - 1]* (Fs/N) ; %defining frequency vector for
plotting
X = fft(x,N);
Yb = fft(yb,N);
figure(2);
subplot(211), plot(w,abs(X(1:N/2)));
title('Spect rum of input signal ' ) ;
subplot(212), plot(w,abs(Yb(1:N/2)));
title('Spectrum of filtered signal ' ) ;

Figure 7.2 Frequency response

58
Figure 7.3 Input and output for example-2

Exercise:
1. Transform
𝑠+1
𝐻𝑎(𝑠) =
𝑠2 + 5𝑠 + 6

59
into a digital filter H(z) using the impulse invariance technique in which T = 0.1s.
First find the solution analytically and then verify your result with the help of a
MATLAB program. Also plot the magnitude responses of the analog and the
resulting digital filter and comment on the result.

2. Design a low-pass digital filter using a


i) Chebyshev-I analog filter
ii) Chebyshev-II analog filter
iii) Elliptic analog filter
to satisfy 𝜔𝑝 = 0.2𝜋 𝑟𝑎𝑑, 𝜔𝑠 = 0.3𝜋 𝑟𝑎𝑑, 𝑅𝑝 = 1 𝑑𝐵, 𝐴𝑠 = 15 𝑑𝐵. Use
the impulse invariance technique.

3. Transform the system function given in Question 1 above using the


bilinear transformation assuming T = 1s.

4. Repeat Question 2 using bilinear transformation.

5. Certain digital low-pass filter has the following specifications:


Pass-band frequency = 0.2π rad, Pass-band ripple = 1dB

Stop-band frequency = 0.3π rad, Stop-band attenuation = 20db.

Write a MATLAB program to design this filter using Butterworth,


Chebyshev and elliptic methods. Plot the frequency response in each
case and compare the performance (Use functions like butter,
cheby1…etc).

6. Design using MATLAB, an analog Butterworth low-pass filter that


has maximum of 1dB attenuation at 30rad/sec and at least 30dB
attenuation at 40rad/sec. Digitize this using bilinear and impulse
invariant transformation. Use suitable sampling rate. Plot the
frequency response in each case.

Note: Refer MATLAB functions to design high pass and other filters.

60
Generating IIR coefficient Using MATLAB for CCS project:

1. Start MATLAB

2. Select Workspace where you need to store Co-efficient

3. Enter "filterDesigner" in command window of MATLAB

4. Design Filter with respect to your requirement

5. Click on Design Filter to see the filter output

6. Click on file and select Export

61
7. Export SOS and Gain

62
8. Come back to Matlab Command prompt select New Script type the Script for IIR filter (Given
below) save it in same workspace with L138_iirsos_coeffs.m, run the script to check error
% L138_IIRSOS_COEFFS.M
% MATLAB function to write SOS IIR filter coefficients
% assumes that coefficients have been exported from
% filterDesigner as two matrices
% first matrix has format
% [ b10 b11 b12 a10 a11 a12
% b20 b21 b22 a20 a21 a22
% ...
% ]
% where bij is the bj coefficient in the ith stage
% second matrix contains gains for each stage
%
function L138_iirsos_coeffs(coeff,gain)
%
num_sections=length(gain)-1;
fname = input('enter filename for coefficients ','s');
fid = fopen(fname,'wt');
fprintf(fid,'// %s\n',fname);
fprintf(fid,'// this file was generated using');
fprintf(fid,'\n// function L138_iirsos_coeffs.m\n',fname);
fprintf(fid,'\n#define NUM_SECTIONS %d\n',num_sections);
% first write the numerator coefficients b
% i is used to count through sections
fprintf(fid,'\nfloat b[NUM_SECTIONS][3] = { \n');
for i=1:num_sections
if i==num_sections
fprintf(fid,'{%2.8E, %2.8E, %2.8E} };\n',...
coeff(i,1)*gain(i),coeff(i,2)*gain(i),coeff(i,3)*gain(i));
else
fprintf(fid,'{%2.8E, %2.8E, %2.8E},\n',...
coeff(i,1)*gain(i),coeff(i,2)*gain(i),coeff(i,3)*gain(i));
end
end
% then write the denominator coefficients a
% i is used to count through sections
fprintf(fid,'\nfloat a[NUM_SECTIONS][3] = { \n');
for i=1:num_sections
if i==num_sections
fprintf(fid,'{%2.8E, %2.8E, %2.8E} };\n',...
63
coeff(i,4),coeff(i,5),coeff(i,6));
else
fprintf(fid,'{%2.8E, %2.8E, %2.8E},\n',...
coeff(i,4),coeff(i,5),coeff(i,6));
end
end
fclose(fid);

9. Once done type L138_iirsos_coeffs(SOS,G) on command prompt


10. It will ask the name for coefficients once you type name and enter it will generate coefficient
in same workspace you can copy value of generated coefficient to “elliptic.cof” and add it to
“main.c”

// main.c
//
// IIR filter implemented using second order sections
// floating point coefficients read from file
//

#include "L138_LCDK_aic3106_init.h"

#define NUM_SECTIONS 2

float b[NUM_SECTIONS][3] = {
{3.70298373E-03, 7.40596747E-03, 3.70298373E-03},
{2.36088362E-02, 2.36088362E-02, 0.00000000E+00} };

float a[NUM_SECTIONS][3] = {
{1.00000000E+00, -1.93814524E+00, 9.52957174E-01},
{1.00000000E+00, -9.52782328E-01, 0.00000000E+00} }; //Chebyshev 1 LPF Fc = 1KHz
Fs=48000KHz */
// Coefficients copied from
“elliptic.cof”

float w[NUM_SECTIONS][2] = {0};

interrupt void interrupt4(void) // associated in intvecs.asm with INT4


{
int section; // index for section number
float input; // input to each section
float yn, wn; // intermediate and output values in each stage

input = (float)input_left_sample();

64
for (section=0 ; section< NUM_SECTIONS ; section++)
{
yn = b[section][0]*input + w[section][0];
w[section][0] = b[section][1]*input + w[section][1] - a[section][1]*yn;
w[section][1] = b[section][2]*input - a[section][2]*yn;
input = yn; // output of current section will be input to next */

output_left_sample((int16_t)(yn)); // before writing to codec

return;
}
int main(void)
{

L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_INPUT);

while(1);

} // end of main()

11. Follow the instruction in Expt. No. 1 for real time implementation.

65
Experiment No. 8: FIR Filter Design

Objective: To design and study finite-duration impulse response (FIR) filters.

Theory: A typical FIR (low-pass) filter response is as shown below Pass

band ripple in dB is 𝑅𝑝 = −20 log10[(1 − 𝛿𝑝)/(1 + 𝛿𝑝)]

Stop band attenuation in dB is 𝐴𝑠 = −20 log10 𝛿𝑠

Pass band deviation in dB = −20 log10(1 + 𝛿𝑝)

For an Nth order filter, there are N+1 coefficients or filter length is N+1.

Important design methods are window based design and frequency sampling design.

Window based Design: The commonly used windows are hamming window and
Kaiser Window.
2𝜋𝑛
0.54 − 0.46 cos(𝑁−1 ) ,0≤𝑛≤𝑁−1
Hamming window, [𝑛] = {
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

The normalized transition width is δw, (transition width divided by sampling frequency
or (ws-wp) divided by 2π) and filter length 𝑁 are related by δw=3.3/ 𝑁, and the designed
filter will have a stop band attenuation of 53 dB.
2𝑛 2
𝐼0[𝛽√1−(1− 𝑁−1
) ]
Kaiser window, [𝑛] =
𝐼0(𝛽)

Where I0[.] is modified zero order Bessel function and β is a parameter that depends on
N.
𝑠 𝐴 −7.95
The filter length M is given by 𝑀 = [14.36𝛿 𝑤
]+1

0.1102(𝐴𝑠 − 8.7), 𝐴𝑠 ≥ 50
where 𝛽 = {
0.5842(𝐴𝑠 − 21)0.4 + 0.07886(𝐴𝑠 − 21), 21 < 𝐴𝑠 < 50

66
The other windows are rectangular, hanning, Bartlett, Blackman and raised cosine.

Frequency Sampling Design: The desired frequency response is sampled at discrete


frequency points 2πk/N to get frequency domain points from which filter taps are
obtained.

For linear phase filter, [𝑘] = 𝐻[𝑘]𝑒𝑗∠𝐻[𝑘]

where, 𝐻𝑟[𝑘] = sampled magnitude value


2𝜋𝑘
−𝛼 ( ) , 𝑘 = 0,1, … 𝑁−1
and ∠𝐻[𝑘] = { 𝑁 2

𝛼 { 2(𝑁−𝑘)
} , 𝑘 = 𝑁−1 + 1, … , 𝑁 + 1
𝑁 2

𝑁−1
where, 𝛼 = , and if N is even, lower integer of 𝑁−1 is taken for k.
2 2

To get filter coefficients, N-point inverse FFT is taken.

Figure 8.1 Frequency Sampling Design example

67
Note: The length M can be estimated as follows
For LPF/HPF:

𝐷 = [𝑎1(log10 𝛿𝑝)2 + 𝑎2 log10 𝛿𝑝 + 𝑎3] log10 𝛿𝑠 + [𝑎4(log10 𝛿𝑝)2 + 𝑎5 log10 𝛿𝑝 + 𝑎6]

𝐹 = 11.01217 + 0.51244 (log10 𝛿𝑝 − log10 𝛿𝑠)

𝑎1 = 5.309 × 10−3, 𝑎2 = 7.114 × 10−2, 𝑎3 = −4.761 × 10−1,

𝑎4 = −2.66 × 10−3, 𝑎5 = −0.5941, 𝑎6 = −0.4278.

and 𝛿𝑓 is the normalized transition width.

For BPF:

𝐶 = [𝑏1(log10 𝛿𝑝)2 + 𝑏2 log10 𝛿𝑝 + 𝑏3] log10 𝛿𝑠 + [𝑏4(log10 𝛿𝑝)2

+𝑏5 log10 𝛿𝑝 + 𝑏6]

𝐺 = −14.61 log10(𝛿𝑝/𝛿𝑠) − 16.9

𝑏1 = 0.01201, 𝑏2 = 0.09664, 𝑏3 = −0.51325, 𝑏4 = 0.00203, 𝑏5 = −0.5705, 𝑏6 =


−0.44314.

Example-1: Design, using window based approach, a low-pass digital FIR filter whose
desired specifications are: wp = 0.2π rad, ws = 0.3π rad, Rp = 0.2dB, As = 50dB.

a) Hamming window

Solution:
clc, clear all, close all;
wp = 0.2*pi;
ws = 0.3*pi;
N = ceil(6.6*pi/(ws-wp)); % estimates order of the filter
b = fir1(N, 0.2);
[H,W] = freqz(b,1,512);
68
plot(W/pi,20*log10(abs(H))), grid on, title('FIR filter using Hamming window');
xlabel('Normalized Frequency'), ylabel('Gain in dB');

% this filter provides about 53dB attenuation in stop band


% and pass band ripples are less than 0.25dB as expected.
Solution:

FIR filter using Hamming window


20

-20

-40
Gain in dB

-60

-80

-100

-120

-140
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency

Figure 8.2 FIR filter frequency response

Example-2: Design the filter specified in problem no.1 using frequency sampling
design technique assuming linear phase.

Solution:

clc, clear all, close all;


M = 20; % assumed
alpha = (M-1)/2;
Hrs = [1,1,1,zeros(1,15),1,1];

69
k1 = 0: floor((M-1)/2);
k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)*k1/M, alpha*(2*pi)*(M-k2)/M];
H = Hrs.*exp(j*angH);
h = real(ifft(H,M));
[H,W]=freqz([h],1,1024);
plot(W/pi,20*log10(abs(H))), zoom on, grid on;
title('FIR LPF using frequency sampling design');
xlabel('Normalized Frequency'), ylabel('Gain in dB');

% Note that stop band attenuation is not very good, is about 15dB only
Solution:

FIR LPF using frequency sampling design


10

-10

-20
Gain in dB

-30

-40

-50

-60

-70
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency

Figure 8.3 FIR filter frequency response

Exercise:
1. Design, using Kaiser window based approach, a low-pass digital FIR filter whose
desired specifications are: wp = 0.2π rad, ws = 0.3π rad, Rp = 0.2dB, As = 50dB.

2. Design and plot the frequency response of a linear phase band-pass filter whose
70
specifications are as follows: Lower pass band edge = 400Hz, upper pass-band
edge = 500Hz, lower stop- band edge = 300Hz and upper stop-band edge = 600Hz,
Rp = 0.5dB and As = 40dB. The sampling frequency is 2 kHz.
a. using hamming window
b. using Kaiser window

3. Design the same filter in sample problem 2 with M = 25 and compare them.

4. The attenuation in stop band was observed to be not adequate in the above
problem. To improve, a few non-zero points are considered in the transition
band. These values are normally estimated by optimization techniques. In the
above problem, use Hrs(k) = [ 1, 1, 1, 0.5, 0.1 , zeros(1,11), 0.1,0.5,1,1]
Compare the results and find out whether there is any improvement. If there is,
then at what cost?
5. Design the filter specified in problem 2 using frequency sampling designing
technique.
6. Certain signal has 10Hz, 30Hz and 50Hz components. Simulate this signal.
Design suitable FIR filter using the following methods to select only 30Hz
component. Filter the signal using the filters, and plot the spectrum of the input
and the filtered signal. Hence compare the performance of the filters.
a) Window method
b) Frequency sampling designing

Code Composer Studio:


Problem: Design and implement low pass FIR filter using window based approach for the
following specifications: Passband edge frequency fp = 1kHZ,, Stopband edge frequency fs =
5kHz. Assume Fs = 48000 Hz. Use Hamming Window.

71
MATLAB program for obtaining the FIR coefficients:

clc, clear all, close all;


Fs=48000;
fp=1000, fs=10000;
wp = fp*2*pi/Fs; ws = fs*2*pi/Fs; %Edge frequencies in
radians
N = ceil(6.6*pi/(ws-wp)); % estimates order of the
filter
b = fir1(N, 2*fp/Fs) % Low pass FIR using Hamming
window, normalized cut-off frequency
[H,W] = freqz(b,1,512,Fs); % Frquency response
subplot(211), plot(W,20*log10(abs(H))), grid on; % Plot
magnitude response
title('a) FIR lowpass filter using Hamming window');
xlabel('Frequency in Hz'), ylabel('Gain in dB');
FIR Coefficients obtained:

0.00665241844915033, 0.00944800191495295, 0.0172251675376609,


0.0295945800356777, 0.0453802313441362,
0.0627672476626719, 0.0795656961393253,
0.0935476786398745, 0.102800730412649, 0.106036495727802,
0.102800730412649,
0.0935476786398745, 0.0795656961393253,
0.0627672476626719, 0.0453802313441362, 0.0295945800356777,
0.0172251675376609,
0.00944800191495295, 0.00665241844915033

CCS program after copying the coefficients:

// L138_fir_intr.c
#include "L138_LCDK_aic3106_init.h"
#define N 19
float h[N] = {0.00665241844915033, 0.00944800191495295,
0.0172251675376609, 0.0295945800356777, 0.0453802313441362,
0.0627672476626719, 0.0795656961393253,
0.0935476786398745, 0.102800730412649, 0.106036495727802,
72
0.102800730412649,
0.0935476786398745, 0.0795656961393253,
0.0627672476626719, 0.0453802313441362, 0.0295945800356777,
0.0172251675376609,
0.00944800191495295, 0.00665241844915033};
float x[N]; // filter delay line
interrupt void interrupt4(void)
{
short i;
float yn = 0.0;
x[0] = (float)(input_left_sample()); // input from ADC
for (i=0 ; i<N ; i++) // compute filter output
yn += h[i]*x[i];
for (i=(N-1) ; i>0 ; i--) // shift delay line
x[i] = x[i-1];
output_left_sample((uint16_t)(yn)); // output to DAC
return;
}
int main(void)
{
L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LINE_I
NPUT);
while(1);
}

Note: Follow the instructions given in Expt. No. 1 for real time implementation.

73
Experiment No. 9
Image Processing Applications
Objective:
1. To study the processing of digital images using MATLAB.
2. To study the processing of digital images using CCS simulation.

MATLAB Programs:

1. For any image file available on your disk, perform the following tasks:
(a) Read and display the image.
(b) Get the negative of the image.
(c) Rotate and display the image.

Solution:
clc;
close all;
clear all;
% a)
a = imread('image.bmp','bmp');
subplot(221),imshow(a), title('a) Image');
% b)
b = double(a);
b = 256-b;
b =uint8(b);
subplot(222), imshow(b), title('b) Negative of the image');
% c)
c = a';
subplot(223), imshow(c), title('c) Image rotated anti-clockwise');

2. Write a MATLAB program to compress an image using 2D-DCT and then try
reconstructing the image by using only 50% of the DCT coefficients.
Solution:
clc;
close all;
clear all;
a = imread('image.bmp','bmp');
subplot(221), imshow(a);
title('Given image');
a1 = dct2(a);
a2 = log(abs(a1));
a3 = mat2gray(a2);
subplot(222),imshow(a3);
title('DCT of the image');
a4 = triu(a1);% Taking only upper triangle of the DCT matrix
a5 = idct2(a4);
a6 = mat2gray(abs(a5));
subplot(223), imshow(a6);
title('Reconstructed image after compression');

74
Exercise Programs:

3. Write a MATLAB program to improve the contrast of an image by using histogram


equalization. Also display the images and their respective histograms before and after
equalization. (Use histeq and imhist functions.)

4. Convolve the two matrices given below:

1 2 3 0 1
𝐴 = [0 8 6] and 𝐵 = [1 0]
5 3 1 3 5

5. Compute the DFT of an image and plot the response with centered low frequencies.
(Use fft2 and fftshift functions.)

6. Write a MATLAB program to detect the sharp edges in an image in the horizontal
direction.

7. Write a MATLAB program to add ‘salt and pepper’ type of noise to an image, and
then filter it. Show all the three images on the same plot.

8. Write a program to read an image and highlight only specified region. (Use iroipoly
function.)

9. Re-size an image to twice its size. Add salt and pepper noise with a density of 0.25.
Filter the noisy image with median filtering using window sizes 3x3, 5x5 and 7x7.
More than one repetition may be done. Display and compare the resulting images.
Which one is most suitable for further processing? (Use imresize, imnoise and
medflt2functions.)

10. Compute the Fourier Transform of an image .Rotate the original image by 45 degrees
and compute the FT of the rotated image. Move the origin to the center of the FT.
Display the logarithm of magnitude of the FT before and after rotation. What happens
to the FT after rotation? (Use fft2, imrotate, fftshift, abs, log and imagesc functions.)

CCS Program:

IMAGE PROCESSING WITH LIBRARY FUNCTIONS:

PREREQUISITES:
1. CCSv5/6 should be installed
2. C64XPLUS-IMGLIB should be installed from http://www.ti.com/tool/sprc264.

1. Create a project:
Goto File ->new->CCS project and enter the details as below.In “Advanced Settings” choose the
Linker command file: as “linker_dsp.cmd” (Browse from ‘IMGLibcall_with logo\src’ folder given at
the time of installation)

75
2. Adding the files:
➢ Right click on project name-> Add files..-> Add ‘IMAGEMAIN.c’ and
‘STARCOMLOGO.c’ from ‘src’ folder.
➢ Add all the files from ‘src\lib files’.
➢ Add ‘wolf.c’ from ‘bitmaps’ folder.

3. Build and debug the project.


4. Before running, create breakpoints after each line starting from 78th line.
5. Every time you change the breakpoint, restart the program and Resume it.
6. Also refresh the image to see the change.
7. Plot image by Tools-> Image Analyzer and follow the below details:

Plot for input image:

76
Plot for output image:

(a) (b) (c)

(d) (e)

Figure 1: (a) Input image (b) Sharpened image (c) Smoothened image (d) Threshold image
(e) Filtered image

77
Expt. No. 10: Audio and Communication applications
Please go through experiment-1 for instructions on how to run a real-time experiment in
LCDKC6748 kit. All the following are real-time experiments.

1. Creating ECO Effect on audio file


Here, we give the input using Mic (connected to MIC_IN). Output is observed using loud
speaker connected to LINE_OUT

// L138_echo_intr.c

#include "L138_LCDK_aic3106_init.h"

#define GAIN 0.6

#define BUF_SIZE 16000

int16_t input,output,delayed;

int16_t buffer[BUF_SIZE];

int i = 0;

interrupt void interrupt4(void) // interrupt service routine

input = input_left_sample();

delayed = buffer[i];

output = delayed + input;

buffer[i] = input + delayed*GAIN;

i = (i+1)%BUF_SIZE;

output_left_sample(output);

return;

int main(void)

int i;

for (i=0 ; i<BUF_SIZE ; i++)

buffer[i] = 0;

L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_MIC_INPUT);

78
while(1);

2. Creating DELAY
This program takes the Mic input and plays it after a delay. Output is observed using loud
speaker connected to LINE_OUT.
// L138_delay_intr.c
//

#include "L138_LCDK_aic3106_init.h"
#define BUF_SIZE 24000

uint16_t input,output,delayed;
uint16_t buffer[BUF_SIZE];
int i = 0;

interrupt void interrupt4(void) // interrupt service routine


{
input = input_left_sample();
delayed = buffer[i];
output = delayed + input;
buffer[i] = input;
i = (i+1)%BUF_SIZE;
output_left_sample(output);
return;
}

int main(void)
{
int i;

for (i=0 ; i<BUF_SIZE ; i++)


{
buffer[i] = 0;
}
L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_MIC_INPUT);
while(1);
}

3. AUDIO PLAYBACK
In this experiment, an audio input is given to the kit using LINE_IN port (you may use an
auxiliary cable to connect a mobile phone and play an audio file). Same audio will be played
in the loud speaker connected to LINE_OUT.

#include "L138_LCDK_aic3106_init.h"
interrupt void interrupt4(void) // interrupt service routine
{
uint32_t sample;

79
sample = input_sample(); // read L + R samples from ADC
output_sample(sample); // write L + R samples to DAC
return;
}
int main(void)
{
L138_initialise_intr(FS_48000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCDK_LIN
E_INPUT)
;
while(1);
}

4. Obtaining the BASS and TREBLE components of an audio file.

Low frequency components of an audio sample are called bass (played using speakers called
woofers), and high frequency components are called treble (played using tweeters).
In this experiment, we will design a low-pass filter (to get bass components) and a high-pass
filter (to get treble) components of the audio file.

Step-1: Obtain the filter coefficients using filterDesigner app in MATLAB.


Type “filterDesigner” in command window to open this app, which is shown below.

Give the specification by entering following options

80
a) Response type – Low pass
b) Design method – FIR (select Window method)
c) Specify order: 10
d) Window: Hamming
e) Units – Hz
f) Sampling frequency: (Fs) – 48000
g) Cutoff frequency (Fc): 3000

Then click on “Design Filter”.

To get the filter coefficients, goto Targets → Generate C header

Select Export as: Double precision float.

Click on Generate and save the coefficients in “fdacoefs.h” .

Now, in CC studio, use the following program to implement the filter.

// L138_fir_intr.c
#include "L138_LCDK_aic3106_init.h"
//(Change N according to the number of coefficients)
#define N 11

// Copy the coefficients from “fdacoefs.h” and paste below.


float h[N] = {
0.007652311531776, 0.02172322572993, 0.06342685093243,
0.1248506518124,
0.1807016830102, 0.2032905539665, 0.1807016830102,
0.1248506518124,
0.06342685093243, 0.02172322572993, 0.007652311531776
};
float x[N]; // filter delay line
interrupt void interrupt4(void)
{
short i;
float yn = 0.0;
x[0] = (float)(input_left_sample()); // input from ADC
for (i=0 ; i<N ; i++) // compute filter output
yn += h[i]*x[i];
for (i=(N-1) ; i>0 ; i--) // shift delay line
x[i] = x[i-1];
output_left_sample((uint16_t)(yn)); // output to DAC
return;
}
int main(void)
{

81
L138_initialise_intr(FS_8000_HZ,ADC_GAIN_0DB,DAC_ATTEN_0DB,LCD
K_LINE_INPUT);
while(1);
}

Save→ Build –> Debug –> Resume


Give an audio input to LINE_IN (using auxiliary cable) and
play the audio using loud speaker. Observe the change in audio
quality due to filtering.
Repeat the same using a high pass filter, and observe the
difference.

5. Perform FSK based digital modulation and observe the waveform using CC studio

#include<stdio.h>
#include<math.h>
#define TIME 336 //length of FSK signal
#define PI 3.14
float fh[TIME],fl[TIME],FSK[TIME];
int input_string[8],scale_data[TIME];
void main()
{
int i,j,k,l;
printf("\nEnter your digital data string in the form of 1 & 0s\n");
for(i=0;i<8;i++) //data in binary format
scanf("%d",&input_string[i]);
k=0;
for(k=0;k<TIME;k++)
{
for(j=0;j<8;j++)
{
for(i=0;i<21;i++)
{
scale_data[k]=input_string[j]; // Scaling input data
k++;
}
}
}
for(i=0;i<TIME;i++)
{
fh[i]=sin(2*PI*2000*i/10000);//high frequency
fl[i]=sin(2*PI*1000*i/10000);//low frequency
}
//assigning high frequency to bit 1
k=0;
for(l=0;k<TIME;l++)
{
for(i=0;i<8;i++)
{
if(input_string[i]==1)
{
for(j=0;j<21;j++)
{
FSK[k]=fh[j];
k++;

82
}
}
else
//assigning low frequency to bit 0
{
if(input_string[i]==0)
{
for(j=0;j<21;j++)
{
FSK[k]=fl[j];
k++;
}}}}}}

After executing the code in the console window, we need to enter the input sequence

For Example: we had entered 11100110

Step 1: Go to the Tools Click on Graph select Dual Time

Fill the details as shown and click OK. You will see two address blocks.

START ADDRESS _A1

83
and

START ADDRESS _B1

Observed output waveforms are as given below.

Input and output FSK waveforms: 11100110:

START ADDRESS _A1

START ADDRESS _B1

Repeat the same experiment for different values of input combinations and record the FSK
output waveform.

84
Reference
1. Sanjit K. Mitra ,“Digital Signal Processing Laboratory Using
Matlab”, Mcgraw-Hill College, 2005.
2. D.G. Manolakis and Vinay K. Ingle, “Applied Digital Signal
Processing”, Cambridge University Press, 2012.
3. MATLAB help
4. CCStudio manual

85

You might also like