Professional Documents
Culture Documents
(3/4) I Semester
EC 667-1
Page No.
Generation of Sequences
*2
Operations on Sequences
Linear Convolution
14
Circular Convolution.
16
18
Generation of Windows
23
25
8.
IIR filters
a. IIR Butterworth filter
b. IIR Chebyshev filter (type-I)
30
43
Sampling Theorem
45
47
9.
*10.
11
37
S.No.
Page No.
Linear Convolution
49
13.
Circular Convolution
55
14.
63
15.
74
16.
Difference Equation
85
17.
Impulse Response
86
INTRODUCTION
MATLAB: MATLAB is a software package for high performance numerical computation
and visualization provides an interactive environment with hundreds of built in functions for
technical computation, graphics and animation. The MATLAB name stands for MATrix
Laboratory
MATLAB Windows:
MATLAB works with through three basic windows
Command Window : This is the main window .it is characterized by MATLAB command
prompt >> when you launch the application program MATLAB puts you in this window all
commands including those for user-written programs ,are typed in this window at the
MATLAB prompt
Graphics window: the output of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background
color the user can create as many windows as the system memory will allow
Edit window: This is where you write edit, create and save your own programs in files called
M files.
Input-output:MATLAB supports interactive computation taking the input from the screen
and flushing, the output to the screen. In addition it can read input files and write output files
Data Type: the fundamental data type in MATLAB is the array. It encompasses several
distinct data objects- integers, real numbers, matrices, charcter strings, structures and
cells.There is no need to declare variables as real or complex, MATLAB automatically sets
the variable to be real.
Dimensioning: Dimensioning is automatic in MATLAB. No dimension statements are
required for vectors or arrays .we can find the dimensions of an existing matrix or a vector
with the size and length commands.
Where to work in MATLAB?
All programs and commands can be entered either in
the a) Command window
b) As an M file using MATLAB editor
Note: Save all M files in the folder 'work' in the current directory. Otherwise you
have to locate the file during compiling. Typing quit in the command prompt>> quit,
will close MATLAB.
For any clarification regarding plot etc, which are built in functions type help
topic i.e. help plot
Basic Instructions in Mat lab
1. T = 0: 1:10
This instruction indicates a vector T which as initial value 0 and final value 10 with an
increment of 1
Therefore T = [0 1 2 3 4 5 6 7 8 9 10]
2. F= 20: 1: 100
Therefore F = [20 21 22 23 24 100]
3. T= 0:1/pi: 1
Therefore T= [0, 0.3183, 0.6366, 0.9549]
4. zeros (1, 3)
The above instruction creates a vector of one row and three columns whose values are zero
Output= [0 0 0]
5. zeros ( 2,4)
Output =
0000
0000
6. ones (5,2)
Output =
11
11
11
11
11
8. A=[1 2 3] B=[4 5 6] , then A.*B = [4 10 18]
9. If C=[2 2 2]
B.*C results in [8 10 12]
9. Plot (t,x)
If x= [6 7 8 9] t= [1 2 3 4]
This instruction will display a figure window which indicates the plot of x versus t
10. stem (t,x) :-This instruction will display a figure window as shown
11. Subplot: This function divides the figure window into rows and columns.
Subplot (2 2 1) divides the figure window into 2 rows and 2 columns 1 represent
number of the figure
Subplot (3 1 2) divides the figure window into 3 rows and 1 column 2 represent
number of the figure
12. Conv
Syntax: w = conv(u,v)
Description: w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same
operation as multiplying the polynomials whose coefficients are the elements of u and v.
13.Disp
Syntax: disp(X)
Description: disp(X) displays an array, without printing the array name. If X contains a text
string, the string is displayed. Another way to display an array on the screen is to type its
name, but this prints a leading "X=," which is not always desirable. Note that disp does not
display empty arrays.
14.xlabel
Syntax: xlabel('string')
Description: xlabel('string') labels the x-axis of the current axes.
15. ylabel
Syntax : ylabel('string')
Description: ylabel('string') labels the y-axis of the current axes.
16.Title
Syntax : title('string')
Description: title('string') outputs the string at the top and in the center of the current axes.
17.grid on
Syntax : grid on
Description: grid on adds major grid lines to the current axes.
18.FFT Discrete Fourier transform.
FFT(X) is the discrete Fourier transform (DFT) of vector X. For matrices, the FFT operation
is applied to each column. For N-D arrays, the FFT operation operates on the first nonsingleton dimension.
FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points and truncated if
it has more.
1. Generation of Sequences
AIM: Generate different types of Sequences (Waveforms)
Apparatus Required: - System with MATLAB
Algorithm: - 1. Get the number of samples.
2. Generate the unit step, unit impulse, unit ramp using for and if else using C
syntax.
3. Generate ramp, sine, cosine and exponential signals using corresponding
general formula.
4. Plot the graph.
Procedure:-1) Open MATLAB
2) Open new M-file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window\ Figure window
1. Unit step.
r=6;
for n=-r:r
if(n>=0)
x=1
else
x=0
end
stem(n,x)
hold on
end
Fig.1
2. Unit Impulse.
r=6;
for n=-r:r
if(n==0)
x=1;
else
x=0;
end
stem(n,x);
hold on
end
Fig.2
3. Unit Ramp.
r=9;
for n=r
if(n>=0)
x=n;
else
x=0;
end
stem(n,x);
hold on
end
Fig.3
4. Sinusoidal sequence.
n=-0:(2*pi)/50:4*pi
x=sin(n)
stem(n,x)
Fig.4
5. Exponential Sequence.
n=0:.1:10
x=exp(n)
stem(n,x)
Fig.5
6. Complex Exponential.
clear all;
a=4
b=3
c=input('enter value of n=' )
d=100
for n=-c:0.1:c;
x=a*exp(b*n)*cos(d*n);
stem(n,x);
hold on
end
stem(n,x)
Fig .6
Fig .7
2. High pass Filter.
N=input('enter order of filter');
Fp=input('enter pass band edge freq.');
Fs=input('enter sampling frequency');
Wp=2*pi*Fp/Fs;
b1=fir1(N,Wp,'high',boxcar(N+1));
b2=fir1(N,Wp,'high',blackman(N+1));
[h,w]=freqz(b1,1);
plot(w/pi,20*log10(abs(h)));
hold on
[h,w]=freqz(b2,1);
plot(w/pi,20*log10(abs(h)),'-g');
xlabel('normalized frequency');
ylabel('Magnitude in Db');
title('Low pass frequency response');
hold off
INPUTS:
enter order of filter=20
N = 20
enter pass band edge freq.500
Fp = 500
enter sampling frequency5000
Fs = 5000
OUTPUT:
Fig .8
3. Band Stop filter
N=input('enter order of filter');
fl=input('enter lower cutoff freq.');
fh=input('enter higher cutoff freq.');
Fs=input('enter sampling frequency');
Wp1=2*pi*fl/Fs;
Wp2=2*pi*fh/Fs;
Wp=[Wp1,Wp2];
b1=fir1(N,Wp,'stop',hamming(N+1));
b2=fir1(N,Wp,'stop',Blackman(N+1));
[h,w]=freqz(b1,1);
plot(w/pi,20*log10(abs(h)));
hold on
[h,w]=freqz(b2,1);
plot(w/pi,20*log10(abs(h)),'-.g');
hold off
INPUT:
Enter order of filter20
Enter lower cutoff freq.200
Enter higher cutoff freq.800
Enter sampling frequency10000
Fig .9
4. Band Pass filter
N=input('enter order of filter');
fl=input('enter lower cutoff freq.');
fh=input('enter higher cutoff freq.');
Fs=input('enter sampling frequency');
Wp1=2*pi*fl/Fs;
Wp2=2*pi*fh/Fs;
Wp=[Wp1,Wp2];
b1=fir1(N,Wp,bartlett(N+1));
b2=fir1(N,Wp,Blackman(N+1));
[h,w]=freqz(b1,1);
plot(w/pi,20*log10(abs(h)));
hold on
[h,w]=freqz(b2,1);
plot(w/pi,20*log10(abs(h)),'-.g');
hold off
INPUT:
enter order of filter20
Fig .10
Fig .11
2. High Pass Filter
fp=input('Enter pass band freq :')
fs=input('Enter stop band freq :')
Fs=input('enter Sampling frequency');
rp=input('Enter pass band ripple:');
rs=input('Enter stop band ripple:');
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=buttord(wp,ws,rp,rs)
[b,a]=butter(N,wc,'high');
[h,w1]=freqz(b,a);
plot(w1/pi,20*log10(abs(h)));
xlabel('normalized frequency');
ylabel('Magnitude in dB');
title('Frequency response of High pass filter');
INPUTS:
Enter pass band freq: 200
fp = 200
Enter stop band freq: 100
fs = 100
enter Sampling frequency2000
Enter pass band ripple: 1
Enter stop band ripple: 20
OUTPUT:
N=3
wc = 0.5462
Fig .12
OUTPUTS:
Order of the filter N = 3
3dB cutoff frequencies wc = 0.2346
0.3997
Fig .13
4. Band stop filter
fp1=input('Enter pass band freq1:');
fp2=input('Enter pass band freq2:');
fs1=input('Enter stop band freq1 :');
fs2=input('Enter stop band freq2 :');
Fs=input('Enter sampling Frequency');
rp=input('Enter pass band ripple:');
rs=input('Enter stop band ripple:');
fp=[fp1,fp2];
fs=[fs1,fs2];
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=buttord(wp,ws,rp,rs)
[b,a]=butter(N,wc,'stop');
[h,w1]=freqz(b,a);
plot(w1/pi,20*log10(h));
xlabel('normalized frequency');
ylabel('Magnitude in Db');
title('Frequency response of Band stop filter');
INPUTS:
Enter pass band freq1:200
Enter pass band freq2:800
Enter stop band freq1 :400
Enter stop band freq2 :600
Enter sampling Frequency10000
Enter pass band ripple:1
Enter stop band ripple:20
OUTPUTS:
Order N = 3
3dB cutoff frequency wc = 0.1979
Fig .14
0.4566
OUTPUTS:
Order N = 3
3dB cutoff frequency wc = 0.2513
Fig .15
2. High Pass Filter
fp=input('Enter pass band freq :')
fs=input('Enter stop band freq :')
Fs=input('enter Sampling frequency');
rp=input('Enter pass band ripple:');
rs=input('Enter stop band ripple:');
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=cheb1ord(wp,ws,rp,rs)
[b,a]=cheby1(N,rp,wc,'high');
[h,w1]=freqz(b,a);
plot(w1/pi,20*log10(abs(h)));
xlabel('normalized frequency');
ylabel('Magnitude in dB');
title('Frequency response of High pass filter');
axis([0,1,-5,0]);
INPUTS:
Enter pass band freq: 400
Enter stop band freq: 800
Enter Sampling frequency: 10000
Enter pass band ripple: 1
Enter stop band ripple: 20
OUTPUTS:
N=3
wc = 0.2513
Fig .16
INPUTS:
Enter pass band freq1:400
Enter pass band freq2:600
Enter stop band freq1:200
Enter stop band freq2:800
Enter sampling Frequency: 10000
Enter pass band ripple: 1
Enter stop band ripple: 20
OUTPUTS:
Order of the filter N = 3
3dB cutoff frequency wc = 0.2513
0.3770
Fig .17
4. Band stop filter
rs=input('Enter stop band ripple:');
fp=[fp1,fp2];
fs=[fs1,fs2];
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
[N,wc]=cheb1ord(wp,ws,rp,rs)
[b,a]=cheby1(N,rp,wc,'stop');
[h,w1]=freqz(b,a);
plot(w1/pi,20*log10(abs(h)));
xlabel('normalized frequency');
ylabel('Magnitude in Db');
title('Frequency response of Band stop filter');
axis([0,1,-20,0]);
INPUTS:
Enter pass band freq1:200
Enter pass band freq2:800
Enter stop band freq1:400
Enter stop band freq2: 600
Enter sampling Frequency: 10000
OUTPUTS:
N=3
wc = 0.1257
0.5027
Fig .18
PROGRAM:
Definition of the function "note"
function tone = note(freq,dur,fs)
t=0:1/fs:dur;
x=t/dur;
envelope=x.*(1-x).*(exp(-8*x)+0.5*x.*(1-x));
beat=0.08;
harmonic0=sin(2*pi*freq*t*(1-beat))+sin(2*pi*freq*t*(1+beat));
harmonic1=sin(2*pi*2*freq*t*(1-beat))+sin(2*pi*2*freq*t*(1+beat));
harmonic2=sin(2*pi*3*freq*t*(1-beat))+sin(2*pi*3*freq*t*(1+beat));
tone=envelope.*(harmonic0+0.2*harmonic1+0.05*harmonic2);
tone=tone/max(tone);
Filtering
f_c=fir1(64,1/dsr); %fir1 call will apply filter to the music
music_f=filter(f_c,1,music); %filter call will apply filter to the music
subplot(3,1,3);
plot(music_f);
title('filtered music');
soundsc(music);
Fig.19
Observations: Here we considered an oversampled data (music) and then down sampled it
without filtering in the first stage and then after filtering. We again down sampled thus the
quality improvement can be observed by listening to it using soundsc(); We can also observe
that for higher values of down sampling factor the spectrum is distorted. Hence an optimum
value is to be choosen.
Conclusion: We are able to generate an aliasing-free concatenated music tone by a three step
procedure by oversampling, then passing it through a filter and finally down sampling it.
The Simulink Library Browser window should now appear on the screen. Most of the blocks
needed for modeling basic systems can be found in the subfolders of the main "Simulink"
folder (opened by clicking on the "+" in front of "Simulink"). Once the "Simulink" folder
has been opened, the Library Browser window should look like:
Basic Elements
There are two major classes of elements in Simulink: blocks and lines. Blocks are used to
generate, modify, combine, output, and display signals. Lines are used to transfer signals
from one block to another.
Blocks
The subfolders underneath the "Simulink" folder indicate the general classes of blocks
available for us to use:
Continuous: Linear, continuous-time system elements (integrators, transfer
functions, state-space models, etc.)
Discrete: Linear, discrete-time system elements (integrators, transfer functions,
state- space models, etc.)
Functions & Tables: User-defined functions and tables for interpolating function
values
Math: Mathematical operators (sum, gain, dot product, etc.)
Nonlinear: Nonlinear operators (coulomb/viscous friction, switches, relays,
etc.) Signals & Systems: Blocks for controlling/monitoring signal(s) and for
creatingsubsystems
Sinks: Used to output or display signals (displays, scopes, graphs,
Lines
Lines transmit signals in the direction indicated by the arrow. Lines must always transmit
signals from the output terminal of one block to the input terminal of another block. One
exception to this is that a line can tap off of another line. This sends the original signal to
each of two (or more) destination blocks, as shown below:
Lines can never inject a signal into another line; lines must be combined through the use
of a block such as a summing junction.
A signal can be either a scalar signal or a vector signal. For Single-Input, Single-Output
systems, scalar signals are generally used. For Multi-Input, Multi-Output systems, vector
signals are often used, consisting of two or more scalar signals. The lines used to transmit
scalar and vector
signals are identical. The type of signal carried by a line is determined by the blocks on
either end of the line.
Building a System
To demonstrate how a system is represented using Simulink, we will build the block
diagram for a simple model consisting of a sinusoidal input multiplied by a constant gain,
which is shown below:
This model will consist of three blocks: Sine Wave, Gain, and Scope. The Sine Wave is a
Source Block from which a sinusoidal input signal originates. This signal is transferred
through a line in the direction indicated by the arrow to the Gain Math Block. The Gain
block modifies its input signal (multiplies it by a constant value) and outputs a new signal
through a line to the Scope block. The Scope is a Sink Block used to display a signal
(much like an oscilloscope).
We begin building our system by bringing up a new model window in which to create the
block diagram. This is done by clicking on the "New Model" button in the toolbar of the
Simulink Library Browser (looks like a blank page).
Building the system model is then accomplished through a series of steps:
1. The necessary blocks are gathered from the Library Browser and placed in the model
window.
2. The parameters of the blocks are then modified to correspond with the system we
are modelling.
3. Finally, the blocks are connected with lines to complete the model.
Each of these steps will be explained in detail using our example system. Once a system is
built, simulations are run to analyze its behavior.
Gathering Blocks
Each of the blocks we will use in our example model will be taken from the Simulink
Library
Browser. To place the Sine Wave block into the model window, follow these steps:
1. Click on the "+" in front of "Sources" (this is a subfolder beneath the "Simulink"
folder)
to display the various source blocks available for us to use.
2. Scroll down until you see the "Sine Wave" block. Clicking on this will display a
short explanation of what that block does in the space below the folder list:
3. To insert a Sine Wave block into your model window, click on it in the Library
Browser and drag the block into your workspace. The same method can be used to place
the Gain and Scope blocks in the model window. The "Gain" block can be found in the
"Math" subfolder and the "Scope" block is located in the "Sink" subfolder. Arrange the
three blocks in the workspace (done by selecting and dragging an individual block to a
new location) so that they look similar to the following:
This window allows us to adjust the amplitude, frequency, and phase shift of the
sinusoidal input. The "Sample time" value indicates the time interval between successive
readings of the signal. Setting this value to 0 indicates the signal is sampled
continuously.
Let us assume that our system's sinusoidal input
has: Amplitude = 2
Frequency = pi
Phase =
pi/2
Enter these values into the appropriate fields (leave the "Sample time" set to 0) and click
"OK" to accept them and exit the window. Note that the frequency and phase for our
system contain 'pi' (3.1415...). These values can be entered into Simulink just as they have
been shown.
Next, we modify the Gain block by double-clicking on it in the model window. The
following window will then appear:
Note that Simulink gives a brief explanation of the block's function in the top portion
of this window. In the case of the Gain block, the signal input to the block (u) is
multiplied by a constant (k) to create the block's output signal (y). Changing the
"Gain" parameter in this window changes the value of k.
For our system, we will let k = 5. Enter this value in the "Gain" field, and click "OK" to
close the window.
The Scope block simply plots its input signal as a function of time, and thus there are no
system parameters that we can change for it. We will look at the Scope block in more
detail after we have run our simulation.
Connecting the Blocks
For a block diagram to accurately reflect the system we are modeling, the Simulink blocks
must be properly connected. In our example system, the signal output by the Sine Wave
block is transmitted to the Gain block. The Gain block amplifies this signal and outputs its
new value to the Scope block, which graphs the signal as a function of time. Thus, we need
to draw lines from the output of the Sine Wave block to the input of the Gain block, and
from the output of the Gain block to the input of the Scope block.
Lines are drawn by dragging the mouse from where a signal starts (output terminal of
a block) to where it ends (input terminal of another block). When drawing lines, it is
important to make sure that the signal reaches each of its intended terminals. Simulink will
turn the mouse pointer into a crosshair when it is close enough to an output terminal to begin
drawing a line, and the pointer will change into a double crosshair when it is close enough to
snap to an input terminal. A signal is properly connected if its arrowhead is filled in. If the
arrowhead is open, it means the signal is not connected to both blocks. To fix an open
signal, you can treat the open arrowhead as an output terminal and continue drawing the line
to an input terminal in the same manner as explained before.
Open Signal
When drawing lines, you do not need to worry about the path you follow. The lines will
route themselves automatically. Once blocks are connected, they can be repositioned for a
neater appearance. This is done by clicking on and dragging each block to its desired
location (signals will stay properly connected and will re-route themselves).After drawing
in the lines and repositioning the blocks, the example system model should look like:
The routing of lines and the location of branches can be changed by dragging them to their
desired new position. To delete an incorrectly drawn line, simply click on it to select it,
and hit the DELETE key.
Running Simulations
Now that our model has been constructed, we are ready to simulate the system. To do this,
go to the Simulation menu and click on Start, or just click on the "Start/Pause Simulation"
button in the model window toolbar (looks like the "Play" button on a VCR). Because our
example is a relatively simple model, its simulation runs almost instantaneously. With more
complicated systems, however, you will be able to see the progress of the simulation by
observing its running time in the the lower box of the model window. Double-click the
Scope block to view the output of the Gain block for the simulation as a function of time.
Once the Scope window appears,
click the "Autoscale" button in its toolbar (looks like a pair of binoculars) to scale the
graph to better fit the window. Having done this, you should see the following:
Note that the output of our system appears as a cosine curve with a period of 2 seconds and
amplitude equal to 10. Does this result agree with the system parameters we set? Its
amplitude makes sense when we consider that the amplitude of the input signal was 2 and
the constant gain of the system was 5 (2 x 5 = 10). The output's period should be the same
as that of the input signal, and this value is a function of the frequency we entered for the
Sine Wave block (which was set equal to pi). Finally, the output's shape as a cosine curve
is due to the phase value of pi/2 we set for the input (sine and cosine graphs differ by a
phase shift of pi/2).
The Scope graph should now look like the following:
Note that the only difference between this output and the one from our original system is the
amplitude of the cosine curve. In the second case, the amplitude is equal to 1, or 1/10th of
10, which is a result of the gain value being 1/10th as large as it originally was.
Fig.20
Fig.21
Amplitude Modulation
Fig.22
Output:
Fig.23
b)
Frequency Modulation
Fig.24
Output:
Fig.25
c) Phase Modulation
Fig.26
Output:
Fig.27
Fig.28
ASK output:
Fig.29
DSBSC output
Fig.30
d) SSB Moulation
Fig.31
SSB output:
Fig.32
Program: Decimation
clc
clear all
close all
t=[0:0.01:1]
m=sinc(2*pi*t)
subplot(211)
hold on
plot(m,'*black')
title('sinc pulse')
xlabel('time')
ylabel('amplitude')
d=2*pi/100
for n=1:1:100
if n==1
e(n)=m(n)
eq(n)=d*sign(e(n))
mq(n)=eq(n)
else
e(n)=m(n)-mq(n-1)
eq(n)=d*sign(e(n))
mq(n)=mq(n-1)+eq(n)
end
end
stairs(mq,'black')
hleg=legend('original signal','stair case approximated signal')
hold off
subplot(212)
hold on
m1=sin(2*pi*t)
plot(m1,'black')
title('sin wave')
xlabel('time')
ylabel('amplitude')
d=2*pi/100
for n=1:1:100
if n==1
e1(n)=m1(n)
eq1(n)=d*sign(e1(n))
mq1(n)=eq1(n)
else
e1(n)=m1(n)-mq1(n-1)
eq1(n)=d*sign(e1(n))
mq1(n)=mq1(n-1)+eq1(n)
end
end
stairs(mq1,'black')
hleg=legend('original signal','stair case approximated signal')
hold off
OUTPUT:
Fig.33
DSK6711 Contents
The TMS320C6711 (C6711) is based on the very-long-instruction-word (VLIW) architecture,
which is very well suited for numerically intensive algorithms. The internal program memory
is structured so that a total of eight instructions can be fetched every cycle.
Hardware
150 MHz C6711 DSP
TI 16-bit A/D Converter (AD535)
A 4-MHz clock onboard the DSK connects to this codec to provide a fixed sampling
rate of 8 kHz.
16MB (megabytes) of synchronous dynamic RAM (SDRAM) and 128kB (kilobytes) of
flash ROM
Daughter card expansion
Two connectors on the board provide input IN (J7) and output OUT (J6)
150 MHz onboard clock. Also onboard the DSK are voltage regulators that provide
1.8V for the
C6711 core and 3.3 V for its memory and peripherals.
Power Supply & Parallel Port Cable
Software
Code Generation Tools (C Compiler, Assembler & Linker)
Code Composer Debugger (256K program limitation)
Example Programs & S/W Utilities
Power-on Self Test
Flash Utility Program
Board Confidence Test
Host access via DLL
Sample Program(s)
Once we open the CCS the main window will be look like this
sum.c
rts6700.lib
Libraryfiles: rts6700.lib
(path:c:\ti\c6000\cgtools\lib\rts6700.lib) Note: select
object&library in (*.o,*.1) in type of files
Project
hello.cmd
Compile:
To Compile: Project
compile
To rebuild: Project
rebuild
Which will create the final.outexecutablefile (eg.vectors.out)
Procedure to load and run program:
Load the program to DSK: file
To execute project: Debug
load program
run
vectors. Out
1. LINEAR CONVOLUTION
AIM: Write a C program for linear convolution of two discrete sequences and
compute using code composer studio V2 (using simulators 64xx, 67xx, 6711)
software and TMS 320C 6711 DSK.
Program:
#include<stdio.h>
#include<math.h>
main ()
{
int x[20],h[20],y[20],N1,N2,n,m;
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N1);
printf ("enter the length of the sequence h (n) :");
scanf ("%d", &N2);
printf ("enter the sequence x (n) :");
for (n=0; n<N1; n++)
scanf ("%d", &x[n]);
printf ("enter the sequence h (n) :");
for (n=0; n<N2; n++)
scanf ("%d", &h[n]);
for (n=0; n<N1+N2-1; n++)
{
if (n>N1-1)
{
y[n]=0;
for(m=n-(N1-1);m<=(N1-1);m++)
y[n] =y[n] +x[m]*h [n-m];
}
else
{
y[n] =0;
for (m=0; m<=n; m++)
y[n] =y[n] +x[m]*h [n-m];
}
}
16
34
52
45
28
2. CIRCULAR CONVOLUTION
AIM: Write a C program for circular convolution of two discrete sequences and
compute using code composer studio V2 (using simulators 64xx, 67xx, 6711)
software and TMS 320C 6711 DSK.
Program:
#include<math.h>
#define pi 3.14
main ()
{
int x[20],h[20],y[20],N1,N2,N,n,m,k;
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N1);
printf ("enter the length of the sequence h (n) :");
scanf ("%d", &N2);
printf ("enter the %d samples of sequence x (n): N1);
for (n=0; n<N1; n++)
scanf ("%d", &x[n]);
printf ("enter the %d samples of sequence h (n): N2);
for (n=0; n<N2; n++)
scanf ("%d", &h[n]);
if (N1>N2)
{
N=N1;
for (n=N2; n<N; n++)
h[n]=0;
}
else
{
N=N2;
for(n=N1;n<N1;n++)
y[n]=0;
}
for(k=0;k<N;k++)
{
y[k]=0;
for (m=N-1; m>=0; m--)
{
if ((N+k-m)>=N)
{
y[k] =y[k] +x[m]*h [k-m];
}
else
y[k] =y[k] +x[m]*h [N+k-m];
}
}
printf ("\response is y (n) :");
for (n=0; n<N; n++)
printf ("\t%d", y[n]);
}
Input:
Enter the length of the sequence x (n):4
Enter the length of the sequence h (n):4
Enter the 4 samples of sequence x (n):2 1 2 1
Enter the 4 samples of sequence h (n):1 2 3 4
Output:
Response is y (n):
14
16
14
16
3. DFT OF A SEQUENCE
AIM: Write a C program for DFT of a sequence and compute using code composer studio
V2 (using simulators 64xx, 67xx, 6711) software and TMS 320C 6711 DSK.
Program:
%DISCRETE FOURIER TRANSFORM OF THE GIVEN SEQUENCE
#include<stdio.h>
#include<math.h>
#define pi 3.14
main ()
{
int x [20], N, n, k;
float Xre[20],Xim[20],Msx[20],Psx[20];
printf ("enter the length of the sequence x (n) :");
scanf ("%d", &N);
printf ("enter the %d samples of discrete sequence x (n): N);
for (n=0; n<N; n++)
scanf ("%d", &x[n]);
for(k=0;k<N;k++)
{
Xre[k]=0;
Xim[k]=0;
for(n=0;n<N;n++)
{
Xre[k]=Xre[k]+x[n]*cos(2*pi*n*k/N);
Xim[k]=Xim[k]+x[n]*sin(2*pi*n*k/N);
}
Msx[k]=sqrt(Xre[k]*Xre[k]+Xim[k]*Xim[k]);
Xim[k]=-Xim[k];
Psx[k]=atan(Xim[k]/Xre[k]);
}
printf ("discrete sequence is");
for (n=0; n<N; n++)
printf ("\nx(%d) =%d", n,x[n]);
printf ("\nDFT sequence is :");
for(k=0;k<N;k++)
printf("\nx(%d)=%f+i%f",k,Xre[k],Xim[k]);
printf("\nmagnitude is:");
for (k=0; k<N; k++)
printf ("\n%f",Msx[k]);
printf ("\nphase spectrum is");
for(k=0;k<n;k++)
printf("\n%f",Psx[k]);
}
Input:
Enter the length of the sequence x (n):4
Enter the 4 samples of discrete sequence x (n):1 2 3 4
Output:
Discrete sequence is:
x (0) =1
x (1) =2
x (2) =3
x (3) =4
DFT sequence is:
x (0) =10.000000+i0.000000
x (1) =-2.007959+i1.995211
x (2) =-1.999967+i-0.012741
x (3) =-1.976076+i-2.014237
Magnitude is:
0.000000
10.000000
-0.782214
2.830683
0.006371
2.000007
0.794961
2.821707
4. IDFT OF A SEQUENCE
Aim: Write a C program for IDFT of a sequence and compute using code composer studio V2
(using simulators 64xx, 67xx, 6711) software and TMS 320C 6711 DSK.
Program:
% Inverse Discrete Foureir Transform
#include<stdio.h>
#include<math.h>
#define pi 3.1428
main()
{
int j, k, N, n;
float XKr[10],XKi[10],xni[10],xnr[10],t;
printf (" enter seq length: \n");
scanf ("%d", &N);
printf ("enter the real & imaginary terms of the sequence: \n");
for (j=0; j<N; j++)
{
scanf ("%f%f", &XKr[j], &XKi[j]);
}
for (n=0; n<N; n++)
{
xnr[n] =0; xni[n] =0; for(k=0;k<N;k++)
{
t=2*pi*k*n/N;
xnr[n]=( xnr[n]+XKr[k]*cos(t) - XKi[k]*sin(t)) ;
xni[n]=( xni[n]+XKr[k]*sin(t) + XKi[k]*cos(t)) ;
}
xnr[n]=xnr[n]/N;
xni[n]=xni[n]/N;
}
printf("IDFT seq:");
for(j=0;j<N;j++)
{
printf("%f + (%f) i\n",xnr[j],xni[j]);
}
}
Input:
Enter seq length: 4
Enter the real & imaginary terms of the sequence:
3
0
0
1
1
0
0
1
Output:
IDFT seq: 1.000000 + (0.000000) i
1.000000 + (0.000302) i
1.000603 + (0.000605) i
0.000006 + (-0.002717) i
Program:
% N - Point Discrete Foureir Transform
#include<stdio.h>
#include<math.h>
#define pi 3.142857
main ()
{
int j, k, n, N, l;
float XKr[10],XKi[10],xni[10],xnr[10],t;
printf (" enter seq length: \n");
scanf ("%d", &l);
printf ("enter the real & imaginary terms of the sequence: \n");
for (j=0; j<l; j++)
{
scanf ("%f%f", &xnr[j], &xni[j]);
}
printf (" enter required length: \n");
scanf ("%d", &N);
if (l<N)
{
for(j=l;j<N;j++)
xnr[j]=xni[j]=0;
}
for(k=0;k<N;k++)
{
XKr[k]=0; XKi[k]=0;
for(n=0;n<N;n++)
{
t=2*pi*k*n/N;
XKr[k]=( XKr[k]+xnr[n]*cos(t) + xni[n]*sin(t)) ;
XKi[k]=( XKi[k]+ xni[n]*cos(t) - xnr[n]*sin(t)) ;
}
}
printf (" The %d Point DFT seq: N);
for(j=0;j<N;j++)
{
printf("%3.3f + (%3.3f) i\n",XKr[j],XKi[j]);
}
}
Input:
Enter seq length:
3
Enter the real & imaginary terms of the sequence:
1
0
1
0
1
0
Enter required length:
4
Out put:
The 4 Point DFT seq:3.000 + (0.000) i
-0.001 + (-0.999) i
1.000 + (-0.001) i
0.002 + (1.004) i
Result: 4 - Point Discrete Foureir Transform of a sequence is computed.
6. FIR FILTERS
AIM: Implement FIR low pass and high pass filters
// FIR Low pass Filter program in C language using CC Studio
#include<stdio.h>
#include<math.h>
main()
{
int k,N,n,x,y;
static float h[10],hd[10],w[10]; printf("enter the no of samples N");
scanf("%d",&N);
y=(N-1)/2; x=-y;
for(n=x;n<=y;n++) {
if(n!=0) {
hd[n]=(sin(n*1.57)/3.14*n);
}
else hd[n]=0.5;
}
printf("select the window: 1.rectangular 2.triangular 3.hanning 4.hamming 5.blackmann");
scanf("%d",&k);
switch(k)
{
case 1: for(n=x;n<=y;n++) w[n]=1;
break;
case 2:
for(n=x;n<=y;n++)
w[n]=1-((abs(n)*2)/(N-1));
break;
case 3:
for(n=x;n<=y;n++)
w[n]=0.5+(0.5*cos((6.28*n)/(N-1)));
break;
case 4:
for(n=x;n<=y;n++)
w[n]=0.54+(0.46*cos((6.28*n)/(N-1)));
break;
case 5:
for(n=x;n<=y;n++)
w[n]=0.42+(0.5*cos((6.28*n)/(N-1)))+(0.08*cos((12.56*n)/(N-1)));
break;
default:
printf("wrong choice is entered"); }
for(n=x;n<=y;n++) {
h[n]=hd[n]*w[n]; printf("output is %f\t",h[n]);
}
}
Result:
ent er t he no of samples N
output is 0.001014 output is 0.318471 output is 0.500000 output is 0.318471 output is 0.001014
Result:
ent er t he no of samples N
Result:
ent er t he no of samples N
output is 0.000000 output is 0.159362 output is 0.500000 output is 0.159362 output is 0.000000
Result:
ent er t he no of samples N
Result:
ent er t he no of samples N
74
Result:
Enter the number of samples
75
Result:
Enter the number of samples
76
Result:
Enter the number of samples
77
Result:
Enter the number of samples
78
Result:
Enter the number of samples
79
7.IIR FILTERS
AIM: Implement IIR low pass and high pass filters
PROGRAM:
// IIR Filter C Program
#include<stdio.h>
#include<math.h>
int i,w,wc,c,N;
float H[100];
float mul(float,int);
void main()
{
printf("\n Enter order of filter");
scanf("%d",&N);
printf("\n Enter the cut off frequency"); scanf("%d",&wc);
printf("\n Enter the choice for IIR Filter 1.LPF 2.HPF");
scanf("%d",&c);
switch(c)
{
case 1: for(w=0;w<100;w++)
{
H[w]=1/sqrt(1+mul((w/(float)wc),2*N));
printf("H[%d]=%f\n",w,H[w]);
} break; case 2:
for(w=0;w<=100;w++) {
H[w]=1/sqrt(1+mul((float)wc/w,2*N));
printf("H[%d]=%f\n",w,H[w]);
} break;
}
}
float mul(float a,int x)
{
for(i=0;i<x-1;i++) a*=a;
return(a);
}
Result:
Enter order of filter 2
Enter the cut off frequency 50
Enter the choice for IIR Filter 1.LPF 2.HPF
80
H[0]=1.000000
H[1]=1.000000 H[2]=1.000000 H[3]=1.000000 H[4]=1.000000 H[5]=1.000000 . .
H[95]=0.076509 H[96]=0.073388 H[97]=0.070423 H[98]=0.067605 H[99]=0.064926
IIR Low Pass Filter Graph:
Result:
Enter order of filter 2
Enter the cut off frequency 50
Enter the choice for IIR Filter 1.LPF 2.HPF 2
H[0]=0.000000 H[1]=0.000000 H[2]=0.000003 H[3]=0.000013 H[4]=0.000041
H[5]=0.000100 . . .
H[95]=0.997069 H[96]=0.997304 H[97]=0.997517 H[98]=0.997712 H[99]=0.997890
H[100]=0.998053
IIR High Pass Filter Graph:
81
Program:
%SUM OF TWO SINUSOIDALS
#include<stdio.h>
#include<math.h>
main ()
{
int w1, w2, t;
float a, b, c;
printf ("enter the w1 value:");
scanf ("%d", &w1);
printf ("enter the w2 value:");
scanf ("%d", &w2);
printf ("sum of two sinusoidal :");
for(t=-5;t<5;t++)
{
b=sin(w1*t);
c=sin (w2*t);
a=b+c;
printf ("\n%f", a);
}
}
Input:
Enter the w1 value: 5
Enter the w2 value: 5
82
Output:
Sum of two sinusoidal:
0.264704
-1.825891
-1.300576
1.088042
1.917849
0.000000
-1.917849
-1.088042
1.300576
1.825891