Vous êtes sur la page 1sur 10

Codage sous Matlab

Code – Signal Sinusoïdal


• fe=1000;
• te=1/fe;

• % Définition du Signal cosinus

• subplot(2,1,1);
• t=0:te:1;
• x=cos(2*pi*10*t);
• plot(t,x);
• xlabel('temps');
• ylabel('x(t)');
• title('cos(2.pi.f.t)');

• % Transformée de Fourier

• subplot(2,1,2);
• f=linspace(-fe/2,fe/2,length(t));
• Xf=fftshift(fft(x)/fe);
• stem(f,abs(Xf));
• axis([-20,20,0,1]);
• grid on;
• xlabel('frequence');
• ylabel('X(f)');

14
Graphiques

15
Transformée de Fourier Inverse
• % Transformée de Fourier inverse

• y=ifft(ifftshift(Xf))*fe ;
• plot(t,y) ;
• axis([0,1,-1,1]);
• xlabel('temps') ;
• ylabel('y(t)') ;

16
Code – Superposition de Signaux


fe=1000;
te=1/fe;
Sinusoïdaux
• % Définition du Signal superposition de sinus

• subplot(2,1,1);
• t=0:te:1;
• x=sin(2*pi*150*t)+0.6*sin(2*pi*40*t);
• plot(t,x);

• xlabel('temps');
• ylabel('x(t)');
• title('Superposition de signaux');

• % Transformée de Fourier

• subplot(2,1,2);
• f=linspace(-fe/2,fe/2,length(t));
• Xf=fftshift(fft(x)/fe);
• stem(f,abs(Xf));
• axis([-160,160,0,1]);
• grid on;
• xlabel('frequence');
• ylabel('X(f)');
17
Graphiques

18
Code – Signal Carré
• fe=1000;
• te=1/fe;

• % Définition du signal carré

• subplot(2,1,1);
• t=[-5:0.001:5];
• x=square(2*pi*t);
• plot(t,x);
• axis([-5,5,-2,2]);
• xlabel('temps');
• ylabel('x(t)');
• title('signal carre');

• % Transformée de Fourier

• subplot(2,1,2);
• f=linspace(-fe/2,fe/2,length(t));
• Xf=fftshift(fft(x)/fe);
• plot(f,abs(Xf));
• axis([-10,10,-10,10]);
• grid on;
• xlabel('frequence');
• ylabel('X(f)')
19
Graphiques

20
Application d’un filtre
• % Création d’un filtre composé de 0 et 1

• A=zeros(1,length(t));
• for i=4990:5020
• A(i)=1;
10
• end
8

• % Spectre du signal filtré 6


• plot(f,A.*abs(Xf));
4
• axis([-10,10,-10,10]);
• grid on; 2
• xlabel('frequence');

X(f)
0
• ylabel('X(f)')
-2

-4

-6

-8

-10
-10 -8 -6 -4 -2 0 2 4 6 8 10
frequence

21
Transformée de Fourier inverse
• % Transformée de Fourier inverse du signal filtré
2
• y=ifft(ifftshift(A.*Xf))*fe ;
• plot(t,y) ; 1.5
• axis([-5,5,-2,2]);
• xlabel('temps') ; 1
• ylabel('y(t)') ;
0.5

y(t) 0

-0.5

-1

-1.5

-2
-5 -4 -3 -2 -1 0 1 2 3 4 5
temps

22

Vous aimerez peut-être aussi