close all; clear all;
%%%Primera parte%%%%
fs=50;
fm=500;
t=40/1000; %40ms

n=1/fm:1/fm:t;
x=cos(2*pi*fs*n);
%plot(n,x);

%n tiene 21muestras, la potecia de 2 superior es 2^5=32
L=length(n);
N=2^(fix(log2(L)/log2(2))+1);

figure(1);
F=fft(x,N);
tm=0:fm/N:fm-(1/fm);
plot(tm,abs(F));
axis([0 fm/2 0 max(abs(F))])

figure(2);
W=triang(length(n));
x2=conv(x,W');
F=fft(x,length(n));
tm=0:fm/length(n):fm-(1/fm);
plot(tm,abs(F));
axis([0 fm/2 0 max(abs(F))])

figure(3);
x3=x+0.5*randn(1,length(x));
%N=input('N=?');
N=4;
num=[1 zeros(1,N-1) -1];
den=[N -N];
y=filter(num,den,x3);
plot(y);
hold on;
plot(x3,'r');
hold off;

%%%segunda parte%%%
num=[1 0 -1 -3];
den=[1 0 0 0 -1];
figure(4); stem(impz(num,den));

figure(5); freqz(num,den);

figure(6); grpdelay(num,den);

figure(7); zplane(num,den);

figure(8);
n=0:9;
x=cos(pi*n/5);
y=filter(num,den,x);
plot(x,'r'); hold on; plot(y); hold off;