Télécharger au format docx, pdf ou txt
Télécharger au format docx, pdf ou txt
Vous êtes sur la page 1sur 5

Lab2para:

%task1
f=300;
SR=2.2;
N=500;
%task3
nlow=-4;
nupp=5;



lab2main:
clc
clear all
close all
lab2_param;
y=task1_function(f,SR,N);
[e,p]=task2_function(y);
[step,impulse]=task3_function(nlow,nupp);


Task 1:
function x=task1_function(fm,sr,N)
n=1:N;
fs=fm*sr;
x=sin(2*pi*(fm/fs)*n);
plot(x)
figure
end



Task 2:
function [ene,pow]=task1_function(a);
%energy
b=zeros(length(a));
for i=1:length(a);
b(i)=a(i)*a(i);
end
ene=0
for i=i:length(b)
ene=ene+b(i);
end

%power

pow=ene/length(a);

ene
pow
end


Task 3:
function [step,impulse]=task3_function(nlow,nupp);
n=nlow:nupp

%for unit step:
step=zeros(1,length(n));
for i=1:length(n)
if(n(i)<0) step(i)=0
else step(i)=1
end
end
stem(step)
figure


%for unit impulse:
impulse=zeros(1,length(n));
for i=1:length(n)
if(n(i)<0) impulse(i)=0
elseif (n(i)==0) impulse(i)=1
else impulse(i)=0
end
end
stem(impulse)
end

Vous aimerez peut-être aussi