Sunteți pe pagina 1din 2

>> figure(1); clf;

>> n = 2;
>> T = 200; % perioada
>> t1 = 2*(-T/2:0.1:T/2); % intervalul de timp
>> y1 = zeros(1, length(t1)); % initializare
>> nt = 2*n-1; % numarul maxim de armonici
>> m = 0;
>> for k = 1:2:nt
y1 = y1 + ((-1)^m)*cos(k*2*pi*t1/T)/k;
m = m+1;
end;
>> y1 = y1*4/pi;
>> subplot(311), plot(t1,y1);
>> title(['Reconstructia semnalului cu n = ',num2str(n),...
' armonici']);
>> grid;

>> n = 10;
>> T = 200; % perioada
>> t2 = 2*(-T/2:0.1:T/2); % intervalul de timp
>> y2 = zeros(1, length(t2)); % initializare
>> nt = 2*n-1; % numarul maxim de armonici
>> m = 0;
>> for k = 1:2:nt
y2 = y2 + ((-1)^m)*cos(k*2*pi*t2/T)/k;
m = m+1;
end;
>> y2 = y2*4/pi;
>> subplot(312), plot(t2,y2);
>> title(['Reconstructia semnalului cu n = ',num2str(n),...
' armonici']);
>> grid;

>> n = 20;
>> T = 200; % perioada
>> t3 = 2*(-T/2:0.1:T/2); % intervalul de timp
>> y3 = zeros(1, length(t3)); % initializare
>> nt = 2*n-1; % numarul maxim de armonici
>> m = 0;
>> for k = 1:2:nt
y3 = y3 + ((-1)^m)*cos(k*2*pi*t3/T)/k;
m = m+1;
end;
>> y3 = y3*4/pi;
>> subplot(313), plot(t3,y3);
>> title(['Reconstructia semnalului cu n = ',num2str(n),...
' armonici']);
>> grid;
>> xlabel('Timpul in secunde ');
>> figure(2); clf;
>> plot(t1,[y1',y2',y3']);

S-ar putea să vă placă și