Professional Documents
Culture Documents
DEPARTMENT OF ECE
OBSERVATION BOOK
NAME: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ROLL NO: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
BRANCH: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
AIM: - To write a “MATLAB” Program to generate of discrete time signals like unit impulse,
unit step, unit ramp, exponential signal and sinusoidal signals.
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
% GENERATION OF BASIC DISCRETE TIME SIGNALS
n5=-3:1:3;
y5=[zeros(1,3),ones(1,1),zeros(1,3)];
subplot(3,2,6);
stem(n5,y5,'k');
xlabel('Time');
ylabel('Amplitude');
title('Unit Impulse');
Amplitude 10
0.5
5
0 0
0 5 10 15 0 5 10 15
Time Time
Sinosoidal Sequence Cosine Sequence
1 1
Amplitude
Amplitude
0 0
-1 -1
0 5 10 15 0 5 10 15
Time Time
Exponential Sequence Unit Impulse
20 1
Amplitude
Amplitude
10 0.5
0 0
0 5 10 15 -4 -2 0 2 4
Time Time
PROCEDURE:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
PROGRAM:-
Program 2(A):
Program 2(B):
c=fliplr(x);
y=fliplr(-n);
subplot(3,2,4);
stem(y,c);
title('Reversed Signal x(-n)') ;
OUTPUT:
Program:
% Program for DFT & IDFT
Theory:
Fast Fourier Transform (FFT) is used for performing frequency analysis of discrete
time signals. FFT gives a discrete frequency domain representation whereas the
other transforms are continuous in frequency domain.
The N point FFT of discrete time signal x[n] is given by the equation
N -1 j 2kn
X (k ) x[n]e N
; k 0,1,2,....N - 1
n 0
Where N is chosen such that N L , where L=length of x[n].
FFT is calculated using two algorithms: 1. DIT-FFT, 2. DIF-FFT
Algorithm:
MATLAB Program:
Theory:
The output y[n] of a LTI (linear time invariant) system can be obtained by convolving
the input x[n] with the system’s impulse response h[n].
The convolution sum is y[n] x[n] h[n] x[k ]h[n k ] x[n k ]h[k ]
k k
Algorithm:
MATLAB Program:
%impulse sequence
h=input('Enter the impulse sequence h(n)= ');
N2=length(h);
n1=0:1:N2-1;
subplot(3,1,2);
stem(n1,h,'k');
xlabel('n--->');
ylabel('Amplitude');
title('impulse sequence h(n)');
% Output conv.
y = 1 4 10 17 19 15 4
Theory: The circular convolution sum is y[n] x(n) h[n] x[k ]h[ n k
k
N
] where the
index n k N
implies circular shifting operation and k N
implies folding the
sequence circularly.
Steps for circular convolution are the same as the usual convolution, except all index
calculations are done "mod N" = "on the wheel".
o Plot f [m] and h [−m] as shown in Fig. 4.1. (use f(m) instead of x(k))
o Multiply the two sequences
o Add to get y[m]
o "Spin" h[−m] n times Anti Clock Wise (counter-clockwise) to get h[n-m].
x[n] and h[n] can be both finite or infinite duration sequences. If infinite sequences,
they should be periodic, and the N is chosen to be at least equal to the period. If
they are finite sequences N is chosen as >= to max (xlength, hlength). Whereas in
linear convolution N>= xlength+hlength-1.
Say x[n] {2,3, 1,1} and N = 5, then the x[-1] and x[-2] samples are plotted at x[N-1]
= x[-4] and x[N-2] =x[-3] places. Now x[n] is entered as x[n] {1,1,0,2,3} .
Algorithm:
PROCEDURE:-
PROGRAM:-
% SAMPLING THEOREM
clc; close all; clear all;
fs=2*fm/3;
n=0:1/fs:0.1;
xn=sin(2*pi*fm*n);
figure(2)
subplot(2,1,1);
stem(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Undersampled fs<<2fm signal');
subplot(2,1,2);
plot(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Reconstructed undersampled fs<<2fm signal');
fs=2*fm;
n=0:1/fs:0.1;
xn=sin(2*pi*fm*n);
figure(3)
subplot(2,1,1);
stem(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Sampled at Nyquist rate fs=2fm signal');
subplot(2,1,2);
plot(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Reconstructed Nyquist rate fs=2fm signal');
fs=40*fm;
n=0:1/fs:0.1;
xn=sin(2*pi*fm*n);
figure(4)
subplot(2,1,1);
stem(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Oversampled fs>>2fm signal');
subplot(2,1,2);
plot(n,xn);
xlabel('Time');
ylabel('Amplitude');
title('Reconstructed oversampled fs>>2fm signal');
OUTPUT:
Theory:
There are two methods of stating the specifications as illustrated in previous program. In
the first program, the given specifications are directly converted to digital form and the
designed filter is also implemented. In the last two programs the butter worth and
chebyshev filters are designed using bilinear transformation (for theory verification).
Given the pass band (Wp in radians) and Stop band edge (Ws in radians) frequencies,
Pass band ripple Rp and stopband attenuation As.
1. Once the coefficients of the IIR filter [b,a] are obtained, the next step is to simulate
an input sequence x[n], say input of 100, 200 & 400 Hz (with sampling frequency of
fs), each of 20/30 points. Choose the frequencies such that they are >, < and = to fc.
2. Filter the input sequence x[n] with Impulse Response, to obtain the output of the
filter y[n] using the ‘filter’ command.
3. Infer the working of the filter (low pass/ high pass, etc).
OUTPUT:
pass ripple freqency=5
stop ripple frequency=40
pass band frequency=2000
stop band frequency=3000
sampling frequency=10000
OUTPUT:
pass ripple freqency=5
stop ripple frequency=40
pass band frequency=2000
stop band frequency=3000
sampling frequency=10000
OUTPUT:
Enter the pass band ripple in db=3
Enter the stop band ripple in db=70
Enter the pass band edge frequency in rad/sec=.4
Enter the stop band edge frequency in rad/sec=.7
OUTPUT:
Enter the pass band ripple in db=3
Enter the stop band ripple in db=70
Enter the pass band edge frequency in rad/sec=.4
Enter the stop band edge frequency in rad/sec=.7
Aim: To design Low pass FIR filter using Rectangular, Hamming and Kaiser Windows for
given specifications.
Theory:
There are two types of systems – Digital filters (perform signal filtering in time domain) and
spectrum analyzers (provide signal representation in the frequency domain). The design of a
digital filter is carried out in 3 steps- specifications, approximations and implementation.
Method I: Given the order N, cutoff frequency fc, sampling frequency fs and the window.
Step 1: Compute the digital cut-off frequency Wc (in the range -π < Wc < π, with π
corresponding to fs/2) for fc and fs in Hz. For example let fc=400Hz, fs=8000Hz
Wc = 2*π* fc / fs = 2* π * 400/8000 = 0.1* π radians
For MATLAB the Normalized cut-off frequency is in the range 0 and 1, where 1
corresponds to fs/2 (i.e., fmax)). Hence to use the MATLAB commands
wc = fc / (fs/2) = 400/(8000/2) = 0.1
Note: if the cut off frequency is in radians then the normalized frequency is
computed as wc = Wc / π
Step 2: Compute the Impulse Response h(n) of the required FIR filter using the given
Window type and the response type (lowpass, bandpass, etc). For example given a
rectangular window, order N=20, and a high pass response, the coefficients (i.e., h[n]
samples) of the filter are computed using the MATLAB inbuilt command ‘fir1’ as
h =fir1(N, wc , 'high', boxcar(N+1));
Note: In theory we would have calculated h[n]=hd[n]×w[n], where hd[n] is the
desired impulse response (low pass/ high pass,etc given by the sinc function) and
w[n] is the window coefficients. We can also plot the window shape as
stem(boxcar(N)).
Plot the frequency response of the designed filter h(n) using the freqz function and
observe the type of response (lowpass / highpass /bandpass).
OUTPUT:
PROGRAM (2)
OUTPUT:
DSP LAB EEE VI SEM DEPT OF ECE
PROGRAM (3)
Result:
1. In the main screen go to project - - > new.. the following screen will appear .
Give a appropriate project name, project type as executable (.out) file.
Select target as TMS320C67xx (depends on the target processor we are using, in our case
it‟s 67xx), and click finish in dialog box finally.
2. Now a new project will be created(e.g. linear.pjt) and a tree will be displayed on left hand
side.
3. Now we need to write C source code . Go to File - - > New - - > Source file.
4. Now a blank screen will appear in which we have to write our C source
code. Type the source code and click save.
5. We have to save the source code file as .c file .When we press save icon in main screen,
following dialog box will open. Save the file as C\C++ source file (e.g. „lin.c‟).
7. After the addition of all three files ,the expanded project tree on left hand side will
resemble this format.(observe the LHS project tree which contains a library file, a source
code and linker command file.)
10. Now we can assembly equivalent of C source code which the simulator has generated.
11. To see the output of the program we have to run the program.
Go to Debug - - > Run.
Input:
x[n] = {1,2,3,4}
h[n] = {2,4,6,8}
Output:
y[n] = {2,8,20,40,50,48,32}
input:
x(n)={1,2,3,4}
h(n)={5,6,7,8}
output:
y(n)={66,68,66,60}
Result:
Aim: compute the DFT of the given sequence x(n)={1,3,2,4,1,6,4,7} using code composer.
//DFT_logic: DFT of N-point from look up table ,output is viewed from watch window
#include<stdio.h>
#include<math.h>
void main(void) // DFT main function
{
short N=8;
short x[8]={1,3,2,4,1,6,4,7}; //Test data
float pi=3.1416;
float sumre=0,sumim=0;
float cosine=0,sine=0;
int i=0,k=0,n=0;
for(k=0;k<N,k++)
{
sumre=0;
sumim=0;
for(n=0;n<N;n++)
{
cosine=cos(2*pi*k*n/N); //Real
sine=sin(2*pi*k*n/N); //imaginary
sumre=sumre+x[n]*cosine;
sumim=sumim-x[n]*sine;
}
out_real[k]=sumre;
out_img[k]=sumim;
Printf(“[%d] %7.3f %7.3f\n”,k,out_real[k],out_img[k]);
}
}
RESULT:
Aim: To generate wave signals step ,ramp,impulse, exponential, using DSP trainer kit.
Program:
#include<studio.h>
#include<math.h>
float unit impulse[5];
float unit step[50];
float exponential [20];
int Ramp[50];
float sine[200]
void main()
{
Int i,n;
Printf(“\ n enter length of unit step response signal (<50\n”));
Scanf(“%d”,&n);
For(i=0;i<n;i++)
Unit impulse[i]=0;
Unit impulse[i]=1;
for(i=0;i<50;i++)
unit step[i]=0;
for(i=0;i<n;i++)
unit step[i]=1;
for(i=0;i<50;i++)
ramp[i]=0;
for(i=0;i<5;i++)
ramp[i]=1;
for(i=0;i<20;i++)
exponential[i]=exp[2’i];
for(i=0;i<200;i++)
sine[i]=sine(2”3.k”;1000/3000)
printf(“in program com\n”);
RESULT:
Aim: Compute the response of the system whose co-efficients are a0=0.1311,a1=0.2622,
a2=0.1311 and b0=1, b1= -0.7478, b2=0.2722, when the input is a unit impulse signal.
Program:
#include <stdio.h>
float y[3]={0,0,0};
float x[3]={0,0,0};
float z[10];
float impulse[10]={1,0,0,0,0,0,0,0,0,0};
main()
{
int j;
float a[3]={0.1311, 0.2622, 0.1311};
float b[3]={1, -0.7478, 0.2722};
for(j=0;j<10;j++)
{
x[0]=impulse[j];
y[0] = (a[0] *x[0]) +(a[1]* x[1] ) +(x[2]*a[2]) - (y[1]*b[1])-(y[2]*b[2]);
printf("%f\n",y[0]);
z[j]=y[0];
y[2]=y[1];
y[1]=y[0];
x[2]=x[1];
x[1] = x[0];
}
}
RESULT:
INPUT:
Coefficient of x(n)={0.1311,0.2622,0.1311}
Coefficient of y(n)={1,-0.7478,0.2722}
OUTPUT:
0.131100
0.360237
0.364799
0.174741
0.031373
-0.024104
-0.026565
-0.013304
-0.002718
0.001589
-------******----------