0% found this document useful (0 votes)
67 views13 pages

Ex 1

The document contains MATLAB code to generate and plot various signals including unit step, ramp, exponential, complex-valued, and decomposed even and odd signals. It also includes code to calculate and plot the impulse and step responses of a given difference equation system and find the frequency response using the system's transfer function. Finally, it outlines a C program that can generate sine and square waves graphically using a DSP kit and Code Composer Studio IDE.

Uploaded by

Maan Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views13 pages

Ex 1

The document contains MATLAB code to generate and plot various signals including unit step, ramp, exponential, complex-valued, and decomposed even and odd signals. It also includes code to calculate and plot the impulse and step responses of a given difference equation system and find the frequency response using the system's transfer function. Finally, it outlines a C program that can generate sine and square waves graphically using a DSP kit and Code Composer Studio IDE.

Uploaded by

Maan Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Q1.

WAP to generate the following signals using MATLAB:


Unit step sequence b) Ramp sequence c) Exponential sequence

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]')

e) Generate the complex-valued signal

clc; % Clear the command window.


close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;

t = linspace(0, 2*pi, 90);


j = sqrt(-1);
arg=-0.1+j*0.3;
complexSignal = exp(t*arg);
% Get the real component and plot it on the x axis
x = real(complexSignal);
y = imag(complexSignal);
plot(x, y, 'bo-', 'LineWidth', 2);
grid on;
title('Plot of cos(t) + j*sin (t)', 'Fontsize', fontSize);
xlabel('Real Component', 'Fontsize', fontSize);
ylabel('Imaginary Component', 'Fontsize', fontSize);
axis square;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
f) Let x(n) = u(n) − u(n − 10). Decompose x(n) into even and odd components.
n=-5:5;
yn= 0*(n<-10)+1*(n==0)+1*(n>-10)+0*(n<0)+1*(n==0)+1*(n>0);
yflip=fliplr(yn);
subplot(3,1,1);
stem(n,yn,'r');
title('plot of yn');
xlabel('time');
ylabel('yn');

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

% 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

% using the filter() function


a=0.8;
N=5;
aa=zeros(-20,100);
aa(1:2)=[1 -a];
bb=zeros(1,50);
bb(1)=1;
bb(N+1)=power(a,N);

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

% using the filter() function


a=0.8;
N=5;
aa=zeros(-20,100);
aa(1:2)=[1 -a];
bb=zeros(1,50);
bb(1)=1;
bb(N+1)=power(a,N);

impulse = t==-20;
unitstep = t>=-20;
ramp = t.*unitstep;
quad = t.^2.*unitstep;
plot(t,[impulse unitstep])

c. Is the system specified by h(n) stable?


Yes

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

% 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

% using the filter() function


a=0.8;
N=5;
aa=zeros(1,2);
aa(1:2)=[1 -a];
bb=zeros(0,2);
bb(1)=1;
bb(N+1)=power(a,N);

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

% 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

% using the filter() function


a=0.8;
N=5;
aa=zeros(1,2);
aa(1:2)=[1 -a];
bb=zeros(0,2);
bb(1)=1;
bb(N+1)=power(a,N);

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;

void main (void)

while (1)

p=~p;

delay();

void delay()

TMOD=0X01; //set timer 0 in mode 1 i.e. 16 bit number

TL0=0X1AH; //load TL register with LSB of count

TH0=0XFFH ; //Load TH register with MSB of count

TR0 =1 //Start timer 0

While(TF0==0) //wait until timer rolls over

TR0=0; //Stop timer 0

TF0=0; //Clear timer flag 0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy