Ex 1
Ex 1
t = (-1:0.01:1)';
impulse = t==0;
unitstep = t>=0;
plot(t,[impulse])
plot(t,[unitstep])
ramp = t.*unitstep;
quad = t.^2.*unitstep;
plot(t,[ramp])
d) Generate and plot each of the following sequences over the indicated interval.
t = (-5:01:5);
x = 2*unitimpul(-5,5,-2) - unitimpul(-5,5,4);
stem(t,x)
xlabel('time n')
ylabel('x[n]')
x = [5,4,3,2,1];
y = [1,1,1,1];
z = x'*y;
t =(-10:01:9);
a = reshape(z,[1 20]);
stem(t,a)
xlabel('time n')
ylabel('x[n]')
x = [5,4,3,2,1];
y = [1,1,1,1];
z = x'*y;
t =(-10:01:9);
a = reshape(z,[1 20]);
stem(t,a)
xlabel('time n')
ylabel('x[n]')
ye = (1/2)*(yn+yflip);
subplot(3,1,2);
stem(n,ye,'b');
title('plot of even');
xlabel('time');
ylabel('y even');
yo= (1/2)*(yn-yflip);
subplot(3,1,3);
stem(n,yo);
title('plot of odd');
xlabel('time');
ylabel('y odd');
Q2.Given the following difference equation
y(n) − y(n − 1) + 0.9y(n − 2) = x(n); ∀n
a. Calculate and plot the impulse response h(n) at n = −20, . . . , 100.
close all
clear
myImpulse=zeros(-20,100);
myImpulse(1)=1;
myImpulseResponse=filter(bb,aa,myImpulse);
t=0:49;
figure(1);
% next with direct calculation of h(n), as per ex. 2.25 in DTSP Oppenheim
% h[n] = (a^n)u[n] - (a^(n))*u[n-N]
a1 = power(a,t);
a2 = power(a,t);
a2(1:N)=0;
calculatedImpulseResponse = a1-a2;
subplot(2,1,1)
stem(t,calculatedImpulseResponse)
title('calculated as per DTSP Oppenheim')
b. Calculate and plot the unit step response s(n) at n = −20, . . . , 100.
t = (-1:0.01:1)';
% solve the following:
% y[n] = ay[n − 1] + x[n] − (a^N)x[n − N]
% first with the fitler() function
% next with direct calculation of h(n), as per ex. 2.25 in the textbook
impulse = t==-20;
unitstep = t>=-20;
ramp = t.*unitstep;
quad = t.^2.*unitstep;
plot(t,[impulse unitstep])
Aim 2: To find the frequency response of a given system given in (Transfer Function/
Differential equation form).
Q3. Find and plot the frequency response (amplitude and phase) of a given system given in (Transfer
Function/ Differential equation form).
The difference equation is given as y[n]-0.25y[n-1] +0.45y[n-2] =1.55x[n]+1.95x[n-1] + 2.15x[n].
You can use the inbuilt functions of the MATLAB.
close all
clear
myImpulse=zeros(-20,100);
myImpulse(1)=1;
myImpulseResponse=filter(bb,aa,myImpulse);
t=0:49;
% next with direct calculation of h(n), as per ex. 2.25 in DTSP Oppenheim
% h[n] = (a^n)u[n] - (a^(n))*u[n-N]
a1 = power(a,t);
a2 = power(a,t);
a2(1:N)=0;
calculatedImpulseResponse = a1-a2;
subplot(2,1,2)
stem(t,calculatedImpulseResponse)
title('calculated as per DTSP Oppenheim')
Aim 3: To write a MATLAB program to evaluate the impulse response of the system
Q. Write a MATLAB program to evaluate the impulse response of the system given as:
y(n) = x(n)+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2).
close all
clear
myImpulse=zeros(-20,100);
myImpulse(1)=1;
myImpulseResponse=filter(bb,aa,myImpulse);
t=0:49;
% next with direct calculation of h(n), as per ex. 2.25 in DTSP Oppenheim
% h[n] = (a^n)u[n] - (a^(n))*u[n-N]
a1 = power(a,t);
a2 = power(a,t);
a2(1:N)=0;
calculatedImpulseResponse = a1-a2;
subplot(2,1,2)
stem(t,calculatedImpulseResponse)
title('calculated as per DTSP Oppenheim')
Aim 4: To write a "C" program to generate various wave forms (Sine wave, Square wave) graphically
with using Code Composer Studio (CCS-7.4) IDE and the DSP TMS 320C6713 DSK Kit.
#include <conio.h>
#include <math.h>
#include <graphics.h>
#include <dos.h>
int main() {
int gd = DETECT, gm;
int angle = 0;
double x, y;
initgraph(&gd, &gm, "C:\\TC\\BGI");
line(0, getmaxy() / 2, getmaxx(), getmaxy() / 2);
/* generate a sine wave */
for(x = 0; x < getmaxx(); x+=3) {
/* calculate y value given x */
y = 50*sin(angle*3.141/180);
y = getmaxy()/2 - y;
/* color a pixel at the given position */
putpixel(x, y, 15);
delay(100);
/* increment angle */
angle+=5;
}
getch();
/* deallocate memory allocated for graphics screen */
closegraph();
return 0;
}#include<reg51.h>
void delay(void);
sbit p=P1^5;
while (1)
p=~p;
delay();
void delay()