Skip to content

Instantly share code, notes, and snippets.

@Zolomon
Last active February 25, 2016 10:28
Show Gist options
  • Save Zolomon/08c369e90ebed62be079 to your computer and use it in GitHub Desktop.
Save Zolomon/08c369e90ebed62be079 to your computer and use it in GitHub Desktop.
laboration 2 - applied mathematics
startlab2;
whos;
% close all;
%% %%%%%%%%% 2.2
% plot the theta function (t > t_0 = 1, t < t_0 = 0)
%figure;plot(t, theta);
% plot the DeltaDirac-function (t = t_0 ==> 1, else 0)
%figure;plot(t, delta);
%figure
%plot(t, sin(t).*(t>0) + cos(t).*((5-t)>0));
%pause;
%close all;
%%%%%%%%%%%% end of 2.2
%% %%%%%%%%%%% 2.3
krekt = (t>0)-(t>1);
triangel = (t+1).*(t>-1)-2*t.*(t>0)+(t-1).*(t>1);
kcos = cos(t).*(t>0);
% figure;
% hold on
% plot(t, krekt);
% plot(t, triangel);
% plot(t, kcos);
% hold off
%
%% %%%%%%%%%%% 2.4
% pause;
% close all;
% y=lpfilter(theta);
% plot(t,y);
%
%% %%%%%%%%%%% 2.5
% pause; close all;
% plotsyst('lpfilter',theta);
%% %%%%%%%%%% 2.6
% % pause;
% % The one-wheeled car.
% % input signal f(t) = theta(t) represents the road height
% % output signal y = S*f(t) represents the cars position as height, viewed
% % in cross-section from the side, like in Super Mario.
% close all;
% plotsyst('bil',theta);
%% %%%%%%%%%% 2.7
% % In this model, the input signal is
% plotsyst('brygga', theta);
% % Svar: Ja, det tror jag. Eftersom y(t) = S(t)*f(t) borde vi ju kunna styra
% % hur utsignalen genom att styra R och C för att få den utsignal vi vill.
% % Det står även i kursboken att
%% %%%%%%%%% 2.8
% % hold
% figure;
% subplot(2,2,1);
%
% plot(t, delay(triangel, 2));
% title('triangel, 2 shift');
% xlabel('insignal');
% grid;
%
% subplot(2,2,3);
% plot(t, delay(triangel, -3));
% xlabel('insignal');
% title('triangel, -3 shift');
% grid;
%
% subplot(2,2,2);
% plot(t, delay(kcos, 2));
% title('kcos, 2 shift');
% xlabel('insignal');
% grid;
%
% subplot(2,2,4);
% plot(t, delay(kcos, -3));
% title('kcos, -3 shift');
% grid;
%% %%%%%%%% 2.9
% figure;
% close all;
% plotsyst('differentiator', triangel);
% plotsyst('differentiator', krekt);
% plotsyst('differentiator', theta);
% plotsyst('differentiator', delta);
% plotsyst('differentiator', kcos);
%
% % Svar: Spikarna kan representeras med hjälp av DeltaDirac-funktioner med
% % DeltaDirac(t - a) där spikarna uppstår.
%% %%%%%%% 2.11
% lintest('lpfilter', triangel, kcos, -3, 4);
%% %%%%%%%% 2.12
% plotsyst('lpfilter', triangel);
% plotsyst('lpfilter', delay(triangel, 2));
% plotsyst('lpfilter', delay(triangel, -3));
% delaytest('lpfilter', triangel, 2);
% delaytest('lpfilter', triangel, -3);
% delaytest('lpfilter', triangel, 1);
%% %%%%%%%%%% 2.14
% plotsyst('lpfilter', triangel + delay(triangel, -5) + delay(triangel, -15));
%% %%%%%%%%%% 2.15
% close all;
% lintest('syst1', theta, theta, 1,1);
% lintest('syst2', theta, theta, 1,1);
% lintest('syst3', theta, theta, 1,1); % Not linear?
% lintest('syst4', theta, theta, 1,1);
% lintest('syst5', theta, theta, 1,1);
% lintest('syst6', theta, theta, 1,1);
%
% lintest('syst1', theta,1-theta,1,1); % Not linear?
% lintest('syst2', theta,1-theta,1,1);
% lintest('syst3', theta,1-theta,1,1);
% lintest('syst4', theta,1-theta,1,1);
% lintest('syst5', theta,1-theta,1,1); % Not lienar?
% lintest('syst6', theta,1-theta,1,1);
% How am I supposed to test linearity? It's not linear if for any
% y(t) != 0?
%plotsyst('lpfilter', (1-theta));
close all;
% delaytest('syst1', triangel, 2);
% delaytest('syst1', triangel, -3);
%
% delaytest('syst2', triangel, 2);
% delaytest('syst2', triangel, -13);
% % svar: Den här verkar ju INTE vara tidsvariant!!
%
% delaytest('syst3', triangel, 2);
% delaytest('syst3', triangel, -13);
%
% delaytest('syst4', triangel, 2);
% delaytest('syst4', triangel, -13);
% delaytest('syst5', triangel, 12);
% delaytest('syst5', triangel, -13);
% delaytest('syst6', triangel, 12);
% delaytest('syst6', triangel, -13);
% % svar: Den här verkar ju INTE vara tidsvariant!!
% delaytest('syst1', delta, 2);
% delaytest('syst1', delta, -3);
% delaytest('syst1', delta, 10);
% pause
% delaytest('syst2', delta, 2);
% delaytest('syst2', delta, -3);
% delaytest('syst2', delta, 10);
% pause
% delaytest('syst3', delta, 2);
% delaytest('syst3', delta, -3);
% delaytest('syst3', delta, 10);
% pause
% delaytest('syst4', delta, 2);
% delaytest('syst4', delta, -3);
% delaytest('syst4', delta, 10);
% pause
% delaytest('syst5', delta, 2);
% delaytest('syst5', delta, -3);
% delaytest('syst5', delta, 10);
% pause
% delaytest('syst6', delta, 2);
% delaytest('syst6', delta, -3);
% delaytest('syst6', delta, 10);
%% %%%%%%%%%%%%% 2.16
h = syst1(delta);
y = falt(h, triangel);
plotsyst('syst1', triangel);
figure;
subplot(211);
plot(t,y);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment