Upload
pavan-kumar-p-n
View
231
Download
0
Embed Size (px)
Citation preview
7/30/2019 Digital Signal Processor - Codes
1/5
M. S. Ramaiah Institute of Technology, India Pavan Kumar P N
Processor: TMS320 Family
Software: TI CCS Studio
1.Program for Circular Convolution#include
void main(){
float h[20],x[20],y[20],sum;
int N,n,k,m;
/* Length of the sequences */
N = 4;
/* First Sequence */
x[0] = 1.0;
x[1] = 1.0;x[2] = 1.0;
x[3] = 1.0;
/* Second Sequence */h[0] = 1.0;
h[1] = 1.0;
h[2] = 1.0;h[3] = 1.0;
/* calculates circular convolution */
for(m = 0; m < N; m++)
{sum = 0.0;
/* computation of one value in circular convolution */
for(k = 0; k < N; k++)
{/* Modulo index */
if((m-k) >= 0) n = m-k;
else n = m-k+N;
sum += x[k] * h[n];}
y[m] = sum;
}}
7/30/2019 Digital Signal Processor - Codes
2/5
M. S. Ramaiah Institute of Technology, India Pavan Kumar P N
2.Program for Linear Convolution#include
void main()
{
float x1[100], x2[100], y[100];
int L = 4, M = 4, n, m, a, b;
x1[0] = 1;
x1[1] = -1;
x1[2] = 1;x1[3] = 0;
x2[0] = 1;x2[1] = 2;
x2[2] = 3;
x2[3] = 3;
for (n = 0; n < L+M; n++)
{
if(n-L+1 < 0) a = 0;else a = n-L+1;
if(n > M) b = M;else b = n;
for (y[n] = 0, m = a; m
7/30/2019 Digital Signal Processor - Codes
3/5
M. S. Ramaiah Institute of Technology, India Pavan Kumar P N
3. Solving of differential equation with zero initial conditionsGiven the difference equation y(n) 0.9y(n-1) plot the impulse response and theoutput of the system for the input x(n) = u(n) u(n-10): DiffEq.c
/* Solving a general difference equation
This program implements the difference equation of a LTI system which is givenas,y(n) = -[a1*y(n-1)+a2*y(n-2)+a3*y(n-3)+........]+b0*x(n)+b1*x(n-1)+b2*x(n-2)+.......
Inputs: 1. Number of denominator coefficients ak, denoted as NValues of a1,a2,a3,....aN
2. Number of numerator coefficients bk, denoted as MValues of b0,b1,b2,.....bM-1
3. Number of samples of x(n), denoted as L.Values of x(0),x(1),x(2),....x(L)
Outputs: The computed output sequence y(n)Assumptions: 1.The number of samples of y(n) are same as number ofinput samples.
2. All initial conditions are assumed zero.---------------------------------------------------------------------------------------------------#include#include
void main()
{
float a[10],b[10],x[100],y[100],h[100],sumXn_k,sumYn_k;int N,M,k,L,n;
/* Number of denominator coefficients and ak */N = 1;a[1] = -0.9;
/* Number of numerator coefficients and bk */M = 1;b[0] = 1;
/* Number of input samples & the input sequence */L = 51;
/* Impulse sequence from n = 0 to n = 50 */x[0] = 1.0;for(k = 1; k < L ; k++)
x[k] = 0.0;/* Computation of y(n) that is the impulse response */for(n = 0; n < L; n++){
sumYn_k = 0;sumXn_k = 0;
7/30/2019 Digital Signal Processor - Codes
4/5
M. S. Ramaiah Institute of Technology, India Pavan Kumar P N
/* computation of a1*y(n-1)+a2*y(n-2)+a3*y(n-3)+......*/for(k = 1; (k
7/30/2019 Digital Signal Processor - Codes
5/5
M. S. Ramaiah Institute of Technology, India Pavan Kumar P N
4.Impulse Response of a Given systemGiven the difference equation y(n) y(n-1) + 0.9y(n-2) = x(n) plot theimpulse response h(n) and the unit step response s(n): ImpulseResponse.c
/* Impulse Response of a given system */
/* Solve the given difference equation y(n)-y(n-1)+0.9y(n-2)=x(n) *//* Calculate the impulse response h(n) at n = 0,1,...,100 *//* Calculate the unit step response s(n) at n = 0,1,...,100 *//* b=[1] and a=[1 -1 0.9] */
#include#includevoid main(){
float a[10],b[10],x[125],h[125],sumXn_k,sumYn_k;int N,M,k,L,n;
/* Number of denominator coefficients and ak */N = 2;a[1] = -1.0;a[2] = 0.9;
/* Number of numerator coefficients and bk */M = 1;b[0] = 1;
/* Number of input samples & the input sequence */L = 101;
/* Impulse sequence from n = 0 to n = 50 */x[0] = 1.0;for(k = 1; k < L ; k++)
x[k] = 0.0;/* Computation of y(n) that is the impulse response */for(n = 0; n < L; n++){
sumYn_k = 0;sumXn_k = 0;
/* computation of a1*y(n-1)+a2*y(n-2)+a3*y(n-3)+......*/for(k = 1; (k