MATLAB
TP1 et TP2
Réaliser par :
Sana ANES
Mariem SAMOUT
Groupe :
II1D
2019/2020
Code
function [ wh,bk ] = traitement_image_2D( x )
img=imread(x);
imshow(img);
[m,n,k]=size(img);
wh=0;
bk=0;
for i= 1:m
for j=1:n
if ((img(i,j,1)>=0 &&img(i,j,1)<=30 )&&(img(i,j,2)>=0
&&img(i,j,2)<=30 )&&(img(i,j,3)>=0 &&img(i,j,3)<=30 ))
bk=bk+1;
Exécution
>> [b,n]=traitement_image_2D( 'color.jpg' )
b =
14305
n =
7212
2
Exercice 2 :
Le fichier utilisé :
file.txt
Code :
function [ pt ] = traitement_surface_3D( in )
file=fopen(in);
data= fscanf(file,'%f ',[3 inf]);
fclose(file);
x=data(1,:);
y=data(2,:);
z=data(3,:);
plot3(x,y,z);
x1=mean(x);
y1=mean(y);
z1=mean(z);
pt=[x1,y1,z1];
end
Exécution :
>> traitement_surface_3D( 'file.txt' )
ans =
1.5000 1.5000 1.2903
3
TP2 : Génération des signaux
Résultat
Résultat
4
2. Génération des signaux périodiques
2.1. Signal sinusoïdal décalé
Code
n=0:49;
f=0.08;
phase=pi/2;
A=2.5;
arg=2*pi*f*n-phase;
x=A*cos(arg);
clf;
stem(n,x);
axis([0 50 -3 3]);
grid;
title('Signal Sinusoidal');
xlabel('temps indexé en n');
ylabel('amplitude');
Résultat
5
2.2. Génération de plusieurs signaux sinusoïdales
𝜋
x(n) = sin (17 𝑛) 0 ≤ 𝑛 ≤ 35
n=0:35;
f=0.0294; %1/(2*17)
phase=0;
A=1;
arg=2*pi*f*n-phase;
x=A*cos(arg);
clf;
stem(n,x);
axis([0 35 -2 2]);
grid;
title('Signal Sinusoidal');
xlabel('temps indexé en n'); ylabel('amplitude');
𝜋
x(n) = sin (17 𝑛) −15 ≤ 𝑛 ≤ 25
n=-15:25;
f=0.0294; %1/(2*17)
6
phase=0;
A=1;
arg=2*pi*f*n-phase;
x=A*cos(arg);
stem(n,x);
axis([-15 25 -2 2]);
grid;
title('Signal Sinusoidal');
xlabel('temps indexé en n');
ylabel('amplitude');
𝜋
x(n) = sin (3𝜋𝑛 + 2 ) −15 ≤ 𝑛 ≤ 15
n=-15:15;
f=1.5;
phase=pi/2;
A=1;
arg=2*pi*f*n-phase;
x=A*cos(arg);
clf;
stem(n,x);
axis([-15 15 -2 2]);
grid;
title('Signal Sinusoidal');
xlabel('temps indexé en n');
ylabel('amplitude');
7
x(n) = sin (√23 𝑛)
𝜋
0 ≤ 𝑛 ≤ 50
n=0:50;
f=0.1043;
phase=0;
A=1;
arg=2*pi*f*n-phase;
x=A*cos(arg);
clf;
stem(n,x);
axis([0 50 -2 2]);
grid;
title('Signal Sinusoidal');
xlabel('temps indexé en n');
ylabel('amplitude');
8
2.3. Génération des signaux triangulaire et rectangulaire
Code
fs=10000;
t=0:1/fs:1.5;
x1=sawtooth(2*pi*50*t);
x2=square(2*pi*50*t);
subplot(211),plot(t,x1),
xlabel('time(sec)');
ylabel('amplitude');
title('Sawtooth Periodic Wave');
subplot(212),plot(t,x2),
xlabel('time(sec)');
ylabel('amplitude');
title('Square Periodic Wave');
Résultat
9
Résultat
10
Résultat
11
12