Access over 20 million homework & study documents

Matlab Codes Project 1

Content type
User Generated
Subject
Engineering
Type
Homework
Rating
Showing Page:
1/9
Answer of Exercise (1)
Part (a)
Matlab script code:
clc;
clear;
% Dirac
N = 10; % number of samples
n = -N/2:N/2; % vector
d = [zeros(1,N/2) 1 zeros(1,N/2)];
figure(1); % display
stem(n,d);
xlabel('n');
ylabel('\delta(n)');
title('Dirac function');
axis([-N/2 N/2 0 1.1]);
% Unit step function
N = 10; % number of samples
n = -N/2:N/2; % vector
u = [zeros(1,N/2) 1 ones(1,N/2)]; %logic to give unit step
figure(2); % display
stem(n,u);
xlabel('n');
ylabel('u(n)');
title('Unit step function'); %title
axis([-N/2 N/2 0 1.1]);
% Sign function
N = 10; % number of samples
n = -N/2:N/2; % vector
u = [zeros(1,N/2) 1 ones(1,N/2)]; %logic for sign function
x = 2.*u-1;
figure(3); % display
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('Sign function');
axis([-N/2 N/2 -1 1]);
% Rect function
M = 3;
N = 10; % number of samples
n = -N/2:N/2; % vector
Rect = [zeros(1,N/2-M) ones(1,2*M+1) zeros(1,N/2-M)];
%logic for rect
figure(4); % display
stem(n,Rect);
xlabel('n');
ylabel('rect');
title('Rect function');
axis([-N/2 N/2 0 1.1]);

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/9
% Sine function
L = 20;
n = 0:L-1;
f0 = 100; %initial frequency
fs = 1000; %sampling frequency
x0 = 1;
x = x0*sin(2*pi*f0/fs*n); %sine function description
figure(5); % display
stem(n,x);
xlabel('n');
ylabel('sin');
title('Sine');
axis([-1 L -1.1 1.1]);
% Sine cordinate function
L = 50;
n = [-L:L];
Ts = 0.1;
x = zeros(1,length(n));
x(n~=0) = sin(pi*n(n~=0)*Ts)./(pi*n(n~=0)*Ts); %logic for sinc
x(n==0) = 1;
figure(6); % display
stem(n,x);
xlabel('n');
ylabel('sin');
title('Sinc function');

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/9

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 9 pages?
Access Now
Unformatted Attachment Preview
Answer of Exercise (1) Part (a) Matlab script code: clc; clear; % Dirac N = 10; % number of samples n = -N/2:N/2; % vector d = [zeros(1,N/2) 1 zeros(1,N/2)]; figure(1); % display stem(n,d); xlabel('n'); ylabel('\delta(n)'); title('Dirac function'); axis([-N/2 N/2 0 1.1]); % Unit step function N = 10; % number of samples n = -N/2:N/2; % vector u = [zeros(1,N/2) 1 ones(1,N/2)]; %logic to give unit step figure(2); % display stem(n,u); xlabel('n'); ylabel('u(n)'); title('Unit step function'); %title axis([-N/2 N/2 0 1.1]); % Sign function N = 10; % number of samples n = -N/2:N/2; % vector u = [zeros(1,N/2) 1 ones(1,N/2)]; %logic for sign function x = 2.*u-1; figure(3); % display stem(n,x); xlabel('n'); ylabel('x(n)'); title('Sign function'); axis([-N/2 N/2 -1 1]); % Rect function M = 3; N = 10; % number of samples n = -N/2:N/2; % vector Rect = [zeros(1,N/2-M) ones(1,2*M+1) zeros(1,N/2-M)]; %logic for rect figure(4); % display stem(n,Rect); xlabel('n'); ylabel('rect'); title('Rect function'); axis([-N/2 N/2 0 1.1]); % Sine function L = 20; n = 0:L-1; f0 = 100; %initial frequency fs = 1000; %sampling frequency x0 = 1; x = x0*sin(2*pi*f0/fs*n); %sine function description figure(5); % display stem(n,x); xlabel('n'); ylabel('sin'); title('Sine'); axis([-1 L -1.1 1.1]); % Sine cordinate function L = 50; n = [-L:L]; Ts = 0.1; x = zeros(1,length(n)); x(n~=0) = sin(pi*n(n~=0)*Ts)./(pi*n(n~=0)*Ts); %logic for sinc x(n==0) = 1; figure(6); % display stem(n,x); xlabel('n'); ylabel('sin'); t ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Just what I needed. Studypool is a lifesaver!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Similar Documents