% En cas de question : antoine.roueff@inpg.fr
%
% Introduction
%==============
%
% 
% Les questions de TD figurent sur ce listing lisez le bien.
%
% L'evalutation sera base sur un compte rendu simple et precis du pour la
% semaine suivante.
% Il y aura un controle continue sur ces TD. Profitez de la presence d'un
% encadrant pour poser des questions PERTINANTES et ainsi avoir une bonne
% note de controle continue.
%
%
%
%=========
% partie 1
%=========
% 
clear            % Nettoie l'espace de travail. Taper "help clear"
close all        % Ferme toutes les figures. Taper "help close" 
%============================
% FIR y[n]=x[n-2]+2*x[n-1]+x[n]
%============================
%
Np=64;
n=linspace(-pi,pi,Np);
x=zeros(1,Np);
x(1)=1;
f=zeros(1,Np);
f(1)=x(1);
f(2)=x(1)+x(2);
for p=3:Np
  f(p)=x(p-2)+2*x(p-1)+x(p);
end
subplot(2,1,1)
plot(f)
subplot(2,1,2)
plot(n,fftshift(abs(fft(f))))
%
%=========================
% IIR y[n]=0.9*x[n-1]+x[n]
%=========================
%
%
figure
x=zeros(1,Np);
x(1)=1;
f=zeros(1,Np);
f(1)=x(1);
for p=2:Np
  f(p)=0.99*x(p-1)+x(p);
end
subplot(2,1,1)
plot(f)
subplot(2,1,2)
plot(n,fftshift(abs(fft(f))))
%
%
%=========
% partie 2
%=========
% 
%
% 
%
%=======================
% Etude de l'apodisation
%=======================
%
%
Np=256;
n=linspace(-pi,pi,Np);% Creer un vecteur de longueur Np,
porte=zeros(1,Np);
l=32;
porte(1:l)=1;
porte(Np-50+1:Np)=1;
P=fft(porte);
figure
subplot(3,2,1)
plot(fftshift(porte))
subplot(3,2,2)
plot(n,real(fftshift(P)))
Pt=zeros(1,Np);
Pt(1:Np/8)=P(1:Np/8);
Pt(Np-Np/4+1:Np)=P(Np-Np/4+1:Np);
subplot(3,2,4)
plot(n,real(fftshift(Pt)))
portet=ifft(Pt);
subplot(3,2,3)
plot(real(fftshift(portet)))
h=hanning(Np).';
subplot(3,2,6)
plot(n,real(fftshift(P).*h))
porte2=ifft(P.*ifftshift(h));
subplot(3,2,5)
plot(real(fftshift(porte2)))
%
% A quoi sert l'apodisation ?
%
%
%=======================
% Etude de l'interpolation
%=======================
%
%
Np=32;
n=linspace(-pi,pi,Np);% Creer un vecteur de longueur Np,
sc=sinc(n*6);
Sc=fft(sc);
figure
subplot(2,2,1)
plot(sc)
subplot(2,2,2)
plot(abs(fft(sc)))
Sc2=[Sc(1:round(Np/2)), zeros(1,100), Sc(round(Np/2)+1:Np)];
subplot(2,2,3)
plot(real(ifft(Sc2)))
subplot(2,2,4)
plot(abs(Sc2))
%
% A quoi sert ce preocede ?
%
