diff --git "a/MATLAB\352\260\225\354\235\230/debugging/case1_no_additional_functions/main.m" "b/MATLAB\352\260\225\354\235\230/debugging/case1_no_additional_functions/main.m" new file mode 100644 index 0000000..1d617f5 --- /dev/null +++ "b/MATLAB\352\260\225\354\235\230/debugging/case1_no_additional_functions/main.m" @@ -0,0 +1,14 @@ +clear; close all; clc; + +disp('Hello there!'); + +a = 1; +b = 2; + +c = a * b + 3; + +for i = 1:5 + disp(['Hi. The iteration number is: ',num2str(i)]); +end + +disp(c) \ No newline at end of file diff --git "a/MATLAB\352\260\225\354\235\230/debugging/case2_with_function_inside/main.m" "b/MATLAB\352\260\225\354\235\230/debugging/case2_with_function_inside/main.m" new file mode 100644 index 0000000..7ed4eed --- /dev/null +++ "b/MATLAB\352\260\225\354\235\230/debugging/case2_with_function_inside/main.m" @@ -0,0 +1,20 @@ +clear; close all; clc; + +disp('Hello there!'); + +a = 1; +b = 2; + +cc = my_addition(a, b); + + +for i = 1:5 + disp(['Hi. The iteration number is: ',num2str(i)]); +end + +disp(cc) + +function c = my_addition(a, b) + +c = a + b; +end diff --git "a/MATLAB\352\260\225\354\235\230/debugging/case3_with_functions_outside/main.m" "b/MATLAB\352\260\225\354\235\230/debugging/case3_with_functions_outside/main.m" new file mode 100644 index 0000000..c361050 --- /dev/null +++ "b/MATLAB\352\260\225\354\235\230/debugging/case3_with_functions_outside/main.m" @@ -0,0 +1,24 @@ +clear; close all; clc; + +disp('Hello there!'); + +a = 1; +b = 2; + +cc = my_addition(a, b); + +for i = 1:5 + disp(['Hi. The iteration number is: ',num2str(i)]); +end + +ii=1; +while(1) + disp('aaaa'); + if ii == 5 + break; + end + ii=ii+1; +end + +disp(cc) + diff --git "a/MATLAB\352\260\225\354\235\230/debugging/case3_with_functions_outside/my_addition.m" "b/MATLAB\352\260\225\354\235\230/debugging/case3_with_functions_outside/my_addition.m" new file mode 100644 index 0000000..1884344 --- /dev/null +++ "b/MATLAB\352\260\225\354\235\230/debugging/case3_with_functions_outside/my_addition.m" @@ -0,0 +1,4 @@ +function c = my_addition(a, b) + +c = a + b; +end diff --git "a/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fig1.mp4" "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fig1.mp4" new file mode 100644 index 0000000..ed7441f Binary files /dev/null and "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fig1.mp4" differ diff --git "a/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fig2.mp4" "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fig2.mp4" new file mode 100644 index 0000000..46a63af Binary files /dev/null and "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fig2.mp4" differ diff --git "a/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fig3.mp4" "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fig3.mp4" new file mode 100644 index 0000000..7292a3c Binary files /dev/null and "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fig3.mp4" differ diff --git "a/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fun_plotComplexPlane.m" "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fun_plotComplexPlane.m" new file mode 100644 index 0000000..7161ca3 --- /dev/null +++ "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fun_plotComplexPlane.m" @@ -0,0 +1,36 @@ +function fun_plotComplexPlane(x1,x2,y1,y2,h_newfig) + +if h_newfig + figure; + set(gcf,'position',[500,100,1000,650]) + set(gcf,'color','w'); +end +set(gca,'visible','off') +mArrow2(x1,0,x2,0,{'color','k'}); +mArrow2(0,y1,0,y2,{'color','k'}); +xlim([x1 x2]) +ylim([y1 y2]) + +for i = (x1+1):(x2-1) + line([i i],[-0.05 0.05],'color','k') + line([-0.05 0.05],[i i],'color','k') + if i<=0 + t= text(i-0.2, -0.3,num2str(i)); + else + t= text(i-0.05, -0.3,num2str(i)); + end + t.FontSize=15; + + if i<0 + t = text(-0.4, i,num2str(i)); + elseif i>0 + t = text(-0.3, i,num2str(i)); + end + t.FontSize = 15; +end + +t = text(x2*0.9,0.3,'Real axis'); +t.FontSize = 15; +t = text(0.2,y2*0.9,'Imaginary axis'); +t.FontSize = 15; +axis square diff --git "a/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fun_plotNumberLine.m" "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fun_plotNumberLine.m" new file mode 100644 index 0000000..f8d79a2 --- /dev/null +++ "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/fun_plotNumberLine.m" @@ -0,0 +1,17 @@ +function fun_plotNumberLine(x1,x2,h_newfig) + +if h_newfig + figure; + set(gcf,'position',[500,100,1000,650]) + set(gcf,'color','w'); +end +set(gca,'visible','off') +mArrow2(x1-1,0,x2+1,0,{'color','k'}); +xlim([x1-1 x2+1]) +ylim([-1 1]) + +for i = x1:x2 + line([i i],[-0.025 0.025],'color','k') + t= text(i-0.1, -0.1,num2str(i)); + t.FontSize=15; +end diff --git "a/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/mArrow2.m" "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/mArrow2.m" new file mode 100644 index 0000000..9407bbe --- /dev/null +++ "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/mArrow2.m" @@ -0,0 +1,9 @@ + +function [ h ] = mArrow2(x1,y1,x2,y2,props) + +h = annotation('arrow'); +set(h,'parent', gca, ... + 'position', [x1,y1,x2-x1,y2-y1], ... + 'HeadLength', 10, 'HeadWidth', 10, 'HeadStyle', 'cback1', ... + props{:}); +end diff --git "a/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/pics.m" "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/pics.m" new file mode 100644 index 0000000..addb36e --- /dev/null +++ "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/210524lecture/pics.m" @@ -0,0 +1,138 @@ +clear; close all; clc; + +%% 3을 수직선 상에 표현해주는 그림 + +clear v +v = VideoWriter('fig1.mp4','MPEG-4'); +v.FrameRate = 50; +v.Quality = 100; +open(v); + +clear F + +fun_plotNumberLine(-4,4,true) +hold on; +the_num = 3; +n_step = 50; +for i_step = 1:n_step + + + len_arrows = linspace(1, the_num, n_step); + len_arrow = len_arrows(i_step); + + h = mArrow2(0,0,len_arrow,0,{'color','r','linewidth',3}); + F(i_step)=getframe(gcf); + + drawnow; + if i_step < n_step + delete(h) + end +end + + +for i=1:length(F) + % convert the image to a frame + frame = F(i) ; + writeVideo(v, frame); +end + +close(v) + + +%% -3을 수직선 상에 표현해주는 그림 + +clear v +v = VideoWriter('fig2.mp4','MPEG-4'); +v.FrameRate = 50; +v.Quality = 100; +open(v); + +clear F + +fun_plotNumberLine(-4,4,true) +hold on; +the_num = -3; +n_step = 50; +for i_step = 1:n_step + + + len_arrows = linspace(1, the_num, n_step); + len_arrow = len_arrows(i_step); + + h = mArrow2(0,0,len_arrow,0,{'color','r','linewidth',3}); + F(i_step)=getframe(gcf); + + drawnow; + if i_step < n_step + delete(h) + end +end + + +for i=1:length(F) + % convert the image to a frame + frame = F(i) ; + writeVideo(v, frame); +end + +close(v) + +%% 3x3을 수직선 상에 표현해주는 그림 + +clear v +v = VideoWriter('fig3.mp4','MPEG-4'); +v.FrameRate = 50; +v.Quality = 100; +open(v); + +clear F + +fun_plotNumberLine(-4,10,true) +hold on; +the_num = 3; +n_step = 50; +for i_step = 1:n_step + + + len_arrows = linspace(1, the_num, n_step); + len_arrow = len_arrows(i_step); + + h = mArrow2(0,0,len_arrow,0,{'color','r','linewidth',3}); + F(i_step)=getframe(gcf); + + drawnow; + if i_step < n_step + delete(h) + end +end + +for i = 1:10 + F(end+1) = getframe(gcf); +end + +delete(h) + +for i_step = 1:n_step + + + len_arrows = linspace(the_num, the_num^2, n_step); + len_arrow = len_arrows(i_step); + + h = mArrow2(0,0,len_arrow,0,{'color','r','linewidth',3}); + F(end+1)=getframe(gcf); + + drawnow; + if i_step < n_step + delete(h) + end +end + + +for i=1:length(F) + % convert the image to a frame + frame = F(i) ; + writeVideo(v, frame); +end + +close(v) + diff --git "a/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/calculus.m" "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/calculus.m" new file mode 100644 index 0000000..e25afb5 --- /dev/null +++ "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/calculus.m" @@ -0,0 +1,99 @@ +clear; close all; clc; + + +%% Fig 3. 한 점 (x,y)에서 순간 변화율과 평균 변화율 (동영상) +for x1 = [1, 0.5, 0.1]+1 + plotXY(-1,3,-1,3,true,20) + x = linspace(-1,3, 100); + y = 1/3*x.^2 + 1; + hold on; + plot(x,y,'k','linewidth',2) + + x = linspace(-0.5, 2.5, 100); + + plot(x, 2/3*x + 2/3,'b','linewidth',3) + plot(1, 4/3 ,'o','markerfacecolor','b','markeredgecolor','none','markersize',10) + + y1 = 1/3 * x1^2 + 1; + + y = (y1-4/3)/(x1-1) * (x-1) + 4/3; + h(1) = plot(x1, y1, 'o', 'markerfacecolor','r','markeredgecolor','none','markersize',10); + h(2) = plot(x, y, 'r','linewidth',3); + +end + + +%% Fig 3. 한 점 (x,y)에서 순간 변화율과 평균 변화율 (동영상) +clear v +v = VideoWriter('fig3.mp4','MPEG-4'); +v.FrameRate = 30; +v.Quality = 100; +open(v); + +clear F + +plotXY(-1,3,-1,3,true,20) +x = linspace(-1,3, 100); +y = 1/3*x.^2 + 1; +hold on; +plot(x,y,'k','linewidth',2) + +x = linspace(-0.5, 2.5, 100); + +plot(x, 2/3*x + 2/3,'b','linewidth',3) +plot(1, 4/3 ,'o','markerfacecolor','b','markeredgecolor','none','markersize',10) + +i=1; +for x1 = linspace(3,1,100) + + + y1 = 1/3 * x1^2 + 1; + + y = (y1-4/3)/(x1-1) * (x-1) + 4/3; + h(1) = plot(x1, y1, 'o', 'markerfacecolor','r','markeredgecolor','none','markersize',10); + h(2) = plot(x, y, 'r','linewidth',3); + drawnow; + + F(i)=getframe(gcf); + if x1>1 + delete(h) + end + i=i+1; +end + + +for i=1:length(F) + % convert the image to a frame + frame = F(i) ; + writeVideo(v, frame); +end + +close(v) + +%% 3d plot + +close all; +[X,Y] = meshgrid(linspace(-3,3,20)); + +surf(X, Y, -X.^2-Y.^2+1) +xlabel('$$x$$','interpreter','latex'); ylabel('$$y$$','interpreter','latex'); zlabel('$$z=-x^2-y^2+1$$','interpreter','latex'); +hold on; +xx = -1 * ones(1,100); +yy = linspace(-3,3,100); +zz = -xx.^2 - yy.^2 + 1; +plot3(xx,yy,zz,'r','linewidth',3) + +% tangential line +% (-1, -1, -1)에서...? +% round z round y = - 2y +t = linspace(-0.5,1,100); + +x = -1 * ones(1, 100); +y = -2 + 4 * t; +z = -4 + 16*t + +plot3(x,y,z,'k','linewidth',3); +plot3(-1,-2,-4,'o','markersize',7,'markerfacecolor','k','markeredgecolor','none') + +axis square + diff --git "a/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/fig3.mp4" "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/fig3.mp4" new file mode 100644 index 0000000..f905140 Binary files /dev/null and "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/fig3.mp4" differ diff --git "a/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/intro_plots.m" "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/intro_plots.m" new file mode 100644 index 0000000..7bbac39 --- /dev/null +++ "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/intro_plots.m" @@ -0,0 +1,27 @@ +clear; close all; clc; + +%% + +x1 = randn(1, 100) * 4 + 10; +x2 = randn(1, 100) * 4 + 25; + +x1(x1<0) = abs(x1(x1<0)); +x2(x2<0) = abs(x2(x2<0)); +rng(1) +figure('position',[1000, 650, 700, 350]); +histogram(x1); +hold on; +histogram(x2); +xlabel('귀의 길이(cm)'); +ylabel('count'); +title('고양이와 강아지의 귀의 길이를 통한 구별'); +grid on; + +figure; + +plot(x1, 0,'o','markerfacecolor','b','markeredgecolor','none'); +hold on; +plot(x2,0,'o','markerfacecolor','r','markeredgecolor','none'); + +xlabel('귀의 길이(cm)'); +title('귀의 길이 데이터를 1차원 벡터 공간 상에 매핑'); \ No newline at end of file diff --git "a/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/plotXY.m" "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/plotXY.m" new file mode 100644 index 0000000..1c8a116 --- /dev/null +++ "b/\352\263\240\353\240\244\353\214\200\355\225\231\352\265\220zoom\352\260\225\354\235\230/plotXY.m" @@ -0,0 +1,53 @@ +function plotXY(x1, x2, y1, y2,h_newfig, fontsize) + +% fontsize= 20; +if h_newfig + figure; + set(gcf,'position',[500,100,1000,650]) + set(gcf,'color','w'); +end + +mArrow2(x1,0,x2,0,{'color','k'}); +mArrow2(0,y1,0,y2,{'color','k'}); +xlim([x1,x2]) +ylim([y1,y2]) +set(gca,'visible','off'); + +% (x1+1):10:(x2-1) +for i = unique(round([linspace(x1*0.9, x2*0.9,7),0])) + line([i i],[-(y2-y1)*0.005 (y2-y1)*0.005],'color','k') + line([-(x2-x1)*0.005 (x2-x1)*0.005],[i i],'color','k') + + % xticks + if i<=0 + t= text(i-(y2-y1)*0.03, -(x2-x1)*0.025,num2str(round(i))); + else + t= text(i-(y2-y1)*0.02, -(x2-x1)*0.025,num2str(round(i))); + end + t.FontSize=fontsize; + + % yticks + if i<0 + t = text((y2-y1)*0.01, i, num2str(round(i))); + elseif i>0 + t = text((y2-y1)*0.01, i, num2str(round(i))); + end + t.FontSize = fontsize; +end + +t = text(x2*0.97,(y2-y1)*0.03,'$$x$$','Interpreter','latex'); +t.FontSize = fontsize; +t = text(-(x2-x1)*0.03,y2*1,'$$y$$','Interpreter','latex'); +t.FontSize = fontsize; +axis square + +end + +function [ h ] = mArrow2(x1,y1,x2,y2,props) + +h = annotation('arrow'); +set(h,'parent', gca, ... + 'position', [x1,y1,x2-x1,y2-y1], ... + 'HeadLength', 10, 'HeadWidth', 10, 'HeadStyle', 'cback1', ... + props{:} ); +end diff --git "a/\352\270\260\354\264\210\354\210\230\355\225\231/e^x\353\212\224 \354\231\234 \353\257\270\353\266\204\355\225\264\353\217\204 e^x\354\235\274\352\271\214/pics.m" "b/\352\270\260\354\264\210\354\210\230\355\225\231/e^x\353\212\224 \354\231\234 \353\257\270\353\266\204\355\225\264\353\217\204 e^x\354\235\274\352\271\214/pics.m" new file mode 100644 index 0000000..fe725c2 --- /dev/null +++ "b/\352\270\260\354\264\210\354\210\230\355\225\231/e^x\353\212\224 \354\231\234 \353\257\270\353\266\204\355\225\264\353\217\204 e^x\354\235\274\352\271\214/pics.m" @@ -0,0 +1,16 @@ +clear; close all; clc; + +fx = 1; +x = 0; + +for i = 1:5 + x = [x, x(i)+0.5]; + fx = [fx, fx(i)*1.5]; +end + +stem(x, fx,'linewidth',2) +grid on; +set(gca,'ytick',round(fx,2)) +xlabel('$$x$$','interpreter','latex'); +ylabel('$$f(x)$$','interpreter','latex'); +set(gca,'fontsize',11) \ No newline at end of file diff --git "a/\353\257\270\354\240\201\353\266\204\355\225\231/Jacobian/coordinate_transformation/polar_to_xy_circle_area_no_Jaco.mp4" "b/\353\257\270\354\240\201\353\266\204\355\225\231/Jacobian/coordinate_transformation/polar_to_xy_circle_area_no_Jaco.mp4" new file mode 100644 index 0000000..5d4f491 Binary files /dev/null and "b/\353\257\270\354\240\201\353\266\204\355\225\231/Jacobian/coordinate_transformation/polar_to_xy_circle_area_no_Jaco.mp4" differ diff --git "a/\353\257\270\354\240\201\353\266\204\355\225\231/Jacobian/coordinate_transformation/polar_to_xy_circle_area_with_Jaco.mp4" "b/\353\257\270\354\240\201\353\266\204\355\225\231/Jacobian/coordinate_transformation/polar_to_xy_circle_area_with_Jaco.mp4" new file mode 100644 index 0000000..7485028 Binary files /dev/null and "b/\353\257\270\354\240\201\353\266\204\355\225\231/Jacobian/coordinate_transformation/polar_to_xy_circle_area_with_Jaco.mp4" differ diff --git "a/\353\257\270\354\240\201\353\266\204\355\225\231/Jacobian/coordinate_transformation/transformation_of_grid_ver2.m" "b/\353\257\270\354\240\201\353\266\204\355\225\231/Jacobian/coordinate_transformation/transformation_of_grid_ver2.m" index 4d04848..09b4bc5 100644 --- "a/\353\257\270\354\240\201\353\266\204\355\225\231/Jacobian/coordinate_transformation/transformation_of_grid_ver2.m" +++ "b/\353\257\270\354\240\201\353\266\204\355\225\231/Jacobian/coordinate_transformation/transformation_of_grid_ver2.m" @@ -155,14 +155,28 @@ %% ȯ + ϱ +applying_jacobian = 0; % jacobian + +if applying_jacobian == 0 + v = VideoWriter('polar_to_xy_circle_area_no_Jaco.mp4','MPEG-4'); +elseif applying_jacobian == 1 + v = VideoWriter('polar_to_xy_circle_area_with_Jaco.mp4','MPEG-4'); +end + +v.FrameRate = 30; +v.Quality = 100; +open(v); + +clear F + close all -n_steps = 50; +n_steps = 100; n_points = 100; % Ŭ ϰ ׷ ̴. size = 10; my_colors = jet(n_points^2); r = 2; % radius -applying_jacobian = 1; % jacobian + [R,THETA] = ndgrid(linspace(0,r,n_points),linspace(0,2*pi,n_points)); scatter(R(:),THETA(:),size,my_colors,'filled') @@ -173,7 +187,7 @@ %%% Լ %%% new_R = R(:)+changeR*i_step/n_steps; new_THETA = THETA(:)+changeTHETA*i_step/n_steps; - + set(gcf,'color','w') if applying_jacobian == 0 scatter(new_R,new_THETA,size,my_colors,'filled'); hold on; else @@ -199,6 +213,20 @@ axis square drawnow; % pause; + + F(i_step+1)=getframe(gcf); end +for i_step = n_steps+1:n_steps+50 + F(i_step+1)=getframe(gcf); +end + +for i=1:length(F) + % convert the image to a frame + frame = F(i) ; + writeVideo(v, frame); +end + +close(v) + diff --git "a/\353\257\270\354\240\201\353\266\204\355\225\231/\353\257\270\353\266\204\353\260\251\354\240\225\354\213\235_phase_portrait/demo.m" "b/\353\257\270\354\240\201\353\266\204\355\225\231/\353\257\270\353\266\204\353\260\251\354\240\225\354\213\235_phase_portrait/demo.m" new file mode 100644 index 0000000..5446f1c --- /dev/null +++ "b/\353\257\270\354\240\201\353\266\204\355\225\231/\353\257\270\353\266\204\353\260\251\354\240\225\354\213\235_phase_portrait/demo.m" @@ -0,0 +1,38 @@ +clear; close all; clc; + +f = @(t,Y) [Y(2); -sin(Y(1))]; + +y1 = linspace(-2, 8, 20); +y2 = linspace(-2, 2, 20); + +[x,y] = meshgrid(y1,y2); +size(x) +size(y) + +u = zeros(size(x)); +v = zeros(size(x)); + +% we can use a single loop over each element to compute the derivatives at +% each point (y1, y2) +t=0; % we want the derivatives at each point at t=0, i.e. the starting time +for i = 1:numel(x) + Yprime = f(t,[x(i); y(i)]); + u(i) = Yprime(1); + v(i) = Yprime(2); +end + +quiver(x,y,u,v,'r'); figure(gcf) +xlabel('y_1') +ylabel('y_2') +axis tight equal; + +hold on + +for y20 = [0 0.5 1 1.5 2 2.5] + [ts,ys] = ode45(f,[0,50],[0;y20]); + plot(ys(:,1),ys(:,2),'b') + plot(ys(1,1),ys(1,2),'bo') % starting point + plot(ys(end,1),ys(end,2),'ks') % ending point +end +hold off +xlim([-2, 8]) diff --git "a/\353\257\270\354\240\201\353\266\204\355\225\231/\354\212\244\354\271\264\353\235\274\354\236\245\354\235\230 \352\270\260\354\232\270\352\270\260 (gradient)/gradient1_slope_of_a_plane.m" "b/\353\257\270\354\240\201\353\266\204\355\225\231/\354\212\244\354\271\264\353\235\274\354\236\245\354\235\230 \352\270\260\354\232\270\352\270\260 (gradient)/gradient1_slope_of_a_plane.m" index 58187c2..40a905e 100644 --- "a/\353\257\270\354\240\201\353\266\204\355\225\231/\354\212\244\354\271\264\353\235\274\354\236\245\354\235\230 \352\270\260\354\232\270\352\270\260 (gradient)/gradient1_slope_of_a_plane.m" +++ "b/\353\257\270\354\240\201\353\266\204\355\225\231/\354\212\244\354\271\264\353\235\274\354\236\245\354\235\230 \352\270\260\354\232\270\352\270\260 (gradient)/gradient1_slope_of_a_plane.m" @@ -12,6 +12,7 @@ end end +figure; surf(x,y,f) xlabel('x'); ylabel('y'); zlabel('f(x,y)') hold on; @@ -31,6 +32,9 @@ end quiver3(x,y,f,u_x,v_x,w_x) +view([-36, 80]) +xlim([-1.5, 1.5]) +ylim([-1.5, 1.5]) % y quiver ׸ @@ -45,7 +49,9 @@ end quiver3(x,y,f,u_y,v_y,w_y) - +view([-36, 80]) +xlim([-1.5, 1.5]) +ylim([-1.5, 1.5]) % xy quiver ׸ u_xy=zeros(length(x),length(y)); @@ -60,4 +66,7 @@ end quiver3(x,y,f,u_xy,v_xy,w_xy) +view([-36, 80]) +xlim([-1.5, 1.5]) +ylim([-1.5, 1.5]) diff --git "a/\353\257\270\354\240\201\353\266\204\355\225\231/\354\212\244\354\271\264\353\235\274\354\236\245\354\235\230 \352\270\260\354\232\270\352\270\260 (gradient)/gradient2_gradient_of_a_scalar_field.m" "b/\353\257\270\354\240\201\353\266\204\355\225\231/\354\212\244\354\271\264\353\235\274\354\236\245\354\235\230 \352\270\260\354\232\270\352\270\260 (gradient)/gradient2_gradient_of_a_scalar_field.m" index 90fc9d5..1fa7a52 100644 --- "a/\353\257\270\354\240\201\353\266\204\355\225\231/\354\212\244\354\271\264\353\235\274\354\236\245\354\235\230 \352\270\260\354\232\270\352\270\260 (gradient)/gradient2_gradient_of_a_scalar_field.m" +++ "b/\353\257\270\354\240\201\353\266\204\355\225\231/\354\212\244\354\271\264\353\235\274\354\236\245\354\235\230 \352\270\260\354\232\270\352\270\260 (gradient)/gradient2_gradient_of_a_scalar_field.m" @@ -13,6 +13,7 @@ title('temperature or something') axis tight colorbar +colormap(jet) %% Gradient [fx1,fy1,fz1]=gradient(T, 0.1); % spacing ߰. 2020 9 14. @@ -31,4 +32,6 @@ hold on; -quiver3(lon,lat,z,fx1,fy1,fz1); \ No newline at end of file +quiver3(lon,lat,z,fx1,fy1,fz1); + +view([0, 90]) \ No newline at end of file diff --git "a/\354\204\240\355\230\225\353\214\200\354\210\230/NMF/no01_NMF_on_face_dataset.m" "b/\354\204\240\355\230\225\353\214\200\354\210\230/NMF/no01_NMF_on_face_dataset.m" index 70a2083..ded993e 100644 --- "a/\354\204\240\355\230\225\353\214\200\354\210\230/NMF/no01_NMF_on_face_dataset.m" +++ "b/\354\204\240\355\230\225\353\214\200\354\210\230/NMF/no01_NMF_on_face_dataset.m" @@ -11,13 +11,35 @@ end %% NMF ϱ -n_features = 25; -[W, H] = nnmf(fea, n_features); +% n_features = 25; +% [W, H] = nnmf(fea, n_features); %MATLAB Լ ̿ + +% ڵغ +m = size(fea,1); +n = size(fea,2); +p = 25; % the number of features +n_epoch = 200; +rng(1) + +W = zeros(m, p, n_epoch); +H = zeros(p, n, n_epoch); + +W(:,:,1) = rand(m, p) * 255; +H(:,:,1) = rand(p, n) * 255; + +X = fea; +for i_epoch = 2:n_epoch + H(:,:,i_epoch) = H(:,:,i_epoch-1).*((W(:,:,i_epoch-1)'*X)./(W(:,:,i_epoch-1)'*W(:,:,i_epoch-1)*H(:,:,i_epoch-1))); + W(:,:,i_epoch) = W(:,:,i_epoch-1).*((X*H(:,:,i_epoch-1)')./(W(:,:,i_epoch-1)*(H(:,:,i_epoch-1)*H(:,:,i_epoch-1)'))); +end + +n_features = p; figure('position',[556, 237, 947, 699]); +i_epoch = n_epoch; for i_features = 1:n_features subplot(5,5,i_features) - imagesc(reshape(H(i_features,:), 32, 32)); colormap('gray'); + imagesc(reshape(H(i_features,:, i_epoch), 32, 32)); colormap('gray'); end % figure; imagesc(reshape(randn(1, 25) * H, 32, 32)); colormap('gray') @@ -31,3 +53,35 @@ subplot(5,5,i_features) imagesc(reshape(coeff(:, i_features), 32, 32)); colormap('gray'); end + + +%% NMF (epoch ȭ) + +newVid = VideoWriter('pic1', 'MPEG-4'); % New +newVid.FrameRate = 20; +newVid.Quality = 100; +open(newVid); + +figure('position',[556, 237, 947, 699]); +for i_epoch = 1:n_epoch + for i_features = 1:n_features + subplot(5,5,i_features) + imagesc(reshape(H(i_features,:, i_epoch), 32, 32)); colormap('gray'); + end + t = text(-11.9444, -185.5345, ['Epoch: ',num2str(i_epoch)],'fontsize',15); + + if i_epoch == 1 + for i = 1:15 % ù 750 ms + writeVideo(newVid, getframe(gcf)) + end + end + + writeVideo(newVid, getframe(gcf)) + drawnow; + if i_epoch < n_epoch + delete(t); + end +end + + +close(newVid) diff --git "a/\354\204\240\355\230\225\353\214\200\354\210\230/NMF/no02_for_demo.m" "b/\354\204\240\355\230\225\353\214\200\354\210\230/NMF/no02_for_demo.m" new file mode 100644 index 0000000..d3893a6 --- /dev/null +++ "b/\354\204\240\355\230\225\353\214\200\354\210\230/NMF/no02_for_demo.m" @@ -0,0 +1,49 @@ +clear; close all; clc; + +load('YaleB_32x32.mat'); % gnd는 사람 번호인듯. +% 출처: http://www.cad.zju.edu.cn/home/dengcai/Data/FaceData.html +% 사용한 데이터셋의 이름은 Extended Yale Face Database B임. + +figure('position',[556, 237, 947, 699]); +for i= 1:25 + subplot(5,5,i) + imagesc(reshape(fea(i,:), 32, 32)); colormap('gray') +end + +%% NMF 수행하기 +% n_features = 25; +% [W, H] = nnmf(fea, n_features); %MATLAB 함수 이용 시 + +% 직접 코딩해보기 +m = size(fea,1); +n = size(fea,2); +p = 25; % the number of features +rng(1) +W = rand(m, p)*255; +H = rand(p, n)*255; +n_epoch = 200; +X = fea; +for i_epoch = 1:n_epoch + H = H.*((W'*X)./(W'*W*H)); + W = W.*((X*H')./(W*(H*H'))); +end + +n_features = p; + +figure('position',[556, 237, 947, 699]); +for i_features = 1:n_features + subplot(5,5,i_features) + imagesc(reshape(H(i_features,:), 32, 32)); colormap('gray'); +end + +% figure; imagesc(reshape(randn(1, 25) * H, 32, 32)); colormap('gray') + +%% PCA 수행하기 + +[coeff, score, latent] = pca(fea); + +figure('position',[556, 237, 947, 699]); +for i_features = 1:n_features + subplot(5,5,i_features) + imagesc(reshape(coeff(:, i_features), 32, 32)); colormap('gray'); +end \ No newline at end of file diff --git "a/\354\204\240\355\230\225\353\214\200\354\210\230/NMF/pic1.mp4" "b/\354\204\240\355\230\225\353\214\200\354\210\230/NMF/pic1.mp4" new file mode 100644 index 0000000..8c1a87b Binary files /dev/null and "b/\354\204\240\355\230\225\353\214\200\354\210\230/NMF/pic1.mp4" differ diff --git "a/\354\204\240\355\230\225\353\214\200\354\210\230/SVD/matrix_as_a_linear_transform_3d.asv" "b/\354\204\240\355\230\225\353\214\200\354\210\230/SVD/matrix_as_a_linear_transform_3d.asv" deleted file mode 100644 index 7005aea..0000000 --- "a/\354\204\240\355\230\225\353\214\200\354\210\230/SVD/matrix_as_a_linear_transform_3d.asv" +++ /dev/null @@ -1,87 +0,0 @@ -clear; close all; clc; - -% A = [1,2,3; 1,2,1;3,5,4]; -% A = [1 2 3;2,1,4;3,4,1]; % shear -% A = [1,0,0;0,2,0;0,0,3]; % scaling -% A = [0,1,0; 1,0,0; 0,0,1] % xy permutation -% A = [1,0,0; 0,0,1; 0,1,0] % yz permutation -% A = [0,0,1; 0,1,0; 1,0,0] % xz permutation -% angle = pi/4; A = [1,0,0;0,cos(angle),-sin(angle);0,sin(angle),cos(angle)]; % rotation around x -% A=[1,0,0;0,1,0;0,0,0]; % projection on xy plane -vector1 = [-1,2,1]'; vector2 = [1,1,1]'; A = [vector1/norm(vector1) vector2/norm(vector2)]*[vector1/norm(vector1) vector2/norm(vector2)]'; % projection onto a plane defined with vectors 1 & 2 - -%% animation with dots -[X,Y,Z] = ndgrid(-1:0.3:1); -n_steps = 100; -n_cam=50; -step_mtx = eye(3); -newXYZ=A*[X(:), Y(:), Z(:)]'; -xyz_min=min(min(min([newXYZ(:),newXYZ(:),newXYZ(:)]')))*1.5; -xyz_max=max(max(max([newXYZ(:),newXYZ(:),newXYZ(:)]')))*1.5; -LIMS = [xyz_min, xyz_max]; - -dot_colors = jet(length(X(:))); - -figure(2) -scatter3(X(:),Y(:),Z(:),30,dot_colors,'filled'); -xlim(LIMS); ylim(LIMS); zlim(LIMS); -% axis off -grid on; -hold on; -line([xyz_min, xyz_max], [0,0], [0,0],'linewidth',3) -line([0,0], [xyz_min, xyz_max], [0,0],'linewidth',3) -line([0,0], [0,0], [xyz_min, xyz_max],'linewidth',3) -xlabel('x'); ylabel('y'); zlabel('z') -hold off; -pause; -for i_steps = 1:n_steps+n_cam - step_mtx = (A-eye(3))/n_steps*i_steps; - - new_xyz = (eye(3)+step_mtx)*[X(:), Y(:), Z(:)]'; - scatter3(new_xyz(1,:), new_xyz(2,:), new_xyz(3,:),30,dot_colors,'filled'); - grid on; hold on; - line([xyz_min, xyz_max], [0,0], [0,0],'linewidth',3) - line([0,0], [xyz_min, xyz_max], [0,0],'linewidth',3) - line([0,0], [0,0], [xyz_min, xyz_max],'linewidth',3) - hold off; - xlim(LIMS); ylim(LIMS); zlim(LIMS); - xlabel('x'); ylabel('y'); zlabel('z') - F(i_steps)=getframe(gcf); - if i_steps>n_steps - az=-37.5+360*i_steps/n_cam; - el=10; - view(az,el) - end - - pause(0.01); -end - -% create the video writer with 1 fps -writerObj = VideoWriter('nonlinear_transform3.avi'); -writerObj.FrameRate = 30; -% set the seconds per image -% open the video writer -open(writerObj); -% write the frames to the video -for i=1:length(F) - % convert the image to a frame - frame = F(i) ; - writeVideo(writerObj, frame); -end -% close the writer object -close(writerObj); - - - -%% SVD -[U,S,V] = svd(A); -hold on; -for i = 1:3 - mArrow3([0,0,0],[U(1,i)*S(i,i),U(2,i)*S(i,i),U(3,i)*S(i,i)],'color','b'); - hold on; -end - -for i = 1:3 - mArrow3([0,0,0],[V(1,i),V(2,i),V(3,i)],'color','g'); -end - diff --git "a/\354\204\240\355\230\225\353\214\200\354\210\230/SVD/matrix_as_a_linear_transform_3d.m" "b/\354\204\240\355\230\225\353\214\200\354\210\230/SVD/matrix_as_a_linear_transform_3d.m" index 99ed0ec..ee4db61 100644 --- "a/\354\204\240\355\230\225\353\214\200\354\210\230/SVD/matrix_as_a_linear_transform_3d.m" +++ "b/\354\204\240\355\230\225\353\214\200\354\210\230/SVD/matrix_as_a_linear_transform_3d.m" @@ -1,14 +1,14 @@ clear; close all; clc; % A = [1,2,3; 1,2,1;3,5,4]; -% A = [1 2 3;2,1,4;3,4,1]; % shear +A = [1 2 3;2,1,4;3,4,1]; % shear % A = [1,0,0;0,2,0;0,0,3]; % scaling % A = [0,1,0; 1,0,0; 0,0,1] % xy permutation % A = [1,0,0; 0,0,1; 0,1,0] % yz permutation % A = [0,0,1; 0,1,0; 1,0,0] % xz permutation % angle = pi/4; A = [1,0,0;0,cos(angle),-sin(angle);0,sin(angle),cos(angle)]; % rotation around x % A=[1,0,0;0,1,0;0,0,0]; % projection on xy plane -vector1 = [-1,2,1]'; vector2 = [1,1,1]'; A = [vector1/norm(vector1) vector2/norm(vector2)]*[vector1/norm(vector1) vector2/norm(vector2)]'; % projection onto a plane defined with vectors 1 & 2 +% vector1 = [-1,2,1]'; vector2 = [1,1,1]'; A = [vector1/norm(vector1) vector2/norm(vector2)]*[vector1/norm(vector1) vector2/norm(vector2)]'; % projection onto a plane defined with vectors 1 & 2 %% animation with dots [X,Y,Z] = ndgrid(-1:0.3:1); diff --git "a/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/FIR_filters/Hr_Type1.m" "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/FIR_filters/Hr_Type1.m" new file mode 100644 index 0000000..ae15e76 --- /dev/null +++ "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/FIR_filters/Hr_Type1.m" @@ -0,0 +1,19 @@ +function [Hr,w,a,L] = Hr_Type1(h); +% Computes Amplitude response Hr(w) of a Type-1 LP +% FIR filter +% ----------------------------------------------------------- % [Hr,w,a,L] = Hr_Type1(h) +% Hr = Amplitude Response +% w = 500 frequencies between [0 pi] over which Hr +% is computed +% a = Type-1 LP filter coefficients +% L = Order of Hr +% h = Type-1 LP filter impulse response +% +M = length(h); +L = (M-1)/2; +a = [h(L+1) 2*h(L:-1:1)]; % 1x(L+1) row vector +n = [0:1:L]; % (L+1)x1 column vector +w = [0:1:500]'*pi/500; +Hr = cos(w*n)*a'; + +Hr2 = cos(w*n)* a' + 1i * sin(w*n) * a'; \ No newline at end of file diff --git "a/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/Amplitude_Modulation_and_Demodulation.m" "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/Amplitude_Modulation_and_Demodulation.m" new file mode 100644 index 0000000..8c3bf7e --- /dev/null +++ "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/Amplitude_Modulation_and_Demodulation.m" @@ -0,0 +1,143 @@ +clear; close all; clc; + +load('data_baseband.mat') + +%% (1) ð ȣ ļ +Fs = 32.8*10^6; +L = length(data); +t = 0:1/Fs:(L-1)/Fs; +Y = fft(data, L); +f = Fs*(-L/2:(L-1)/2)/L; + +Freq = abs(fftshift(Y)); +Freq_dB = 20*log10(Freq); + +figure('position',[680, 638, 1200, 340]); +subplot(1,2,1); +plot(t,data); xlabel('time (s)'); +subplot(1,2,2); +plot(f,Freq); xlabel('freq (Hz)'); + +%% (2) +Omega_0 = 3.2*10^6; +carrier = 2 * cos(2*pi*Omega_0*t); +Y = fft(carrier, L); +f = Fs*(-L/2:(L-1)/2)/L; + +Carrier_FFT = abs(fftshift(Y)); +Carrier_FFT_dB = 20*log10(Carrier_FFT); + +figure('position',[680, 638, 1200, 340]); +subplot(1,2,1); +plot(t,carrier); xlabel('time (s)'); +xlim([0, 1.5*10^(-6)]) +subplot(1,2,2); +plot(f,Carrier_FFT_dB); xlabel('freq (Hz)'); + +%% (3) Amplitude Modulation + +data_AM = data.*carrier; +Y2 = 20 * log10(abs(fftshift(fft(data_AM, L)))); + + +figure; +subplot(2,2,1); +plot(t,data); xlabel('time (s)'); +xlim([0, 1.5*10^(-5)]) +title('Amplitude Modulation ') +subplot(2,2,2); +plot(f, Freq_dB); xlabel('freq (Hz)'); +title('AM ȣ ļ ') + +subplot(2,2,3); +plot(t,data_AM); xlabel('time (s)'); +xlim([0, 1.5*10^(-5)]) +title('Amplitude Modulation ') +subplot(2,2,4); +plot(f, Y2); xlabel('freq (Hz)'); +title('AM ȣ ļ ') + +%% (4) AM Demodulation +data_AM_demod = data_AM .* cos(2*pi*Omega_0*t); +Y3 = 20 * log10(abs(fftshift(fft(data_AM_demod, L)))); + +figure; +subplot(2,2,1); +plot(t,data); xlabel('time (s)'); +xlim([0, 1.5*10^(-5)]) +title('AM ȣ') +subplot(2,2,2); +plot(f, Freq_dB); xlabel('freq (Hz)'); +title('AM ȣ ļ ') + +subplot(2,2,3); +plot(t,data_AM_demod); xlabel('time (s)'); +xlim([0, 1.5*10^(-5)]) +title('AM + ݼ') +subplot(2,2,4); +plot(f, Y3); xlabel('freq (Hz)'); +title('AM + ݼ ļ ') + +%% (5) Lowpass filter + +load('LPF_1.mat') +LPF1 = LPF; +load('LPF_2.mat') +LPF2 = LPF; +load('LPF_3.mat') +LPF3 = LPF; + +data_AM_demod_LPF1 = conv(data_AM_demod, LPF1, 'same'); +data_AM_demod_LPF2 = conv(data_AM_demod, LPF2, 'same'); +data_AM_demod_LPF3 = conv(data_AM_demod, LPF3, 'same'); + +freq_data_AM_demod_LPF1= 20 * log10(abs(fftshift(fft(data_AM_demod_LPF1, L)))); +freq_data_AM_demod_LPF2= 20 * log10(abs(fftshift(fft(data_AM_demod_LPF2, L)))); +freq_data_AM_demod_LPF3= 20 * log10(abs(fftshift(fft(data_AM_demod_LPF3, L)))); + +% ȣ ȣ + +figure('position',[680, 96, 907, 882]); +% ȣ +subplot(4,2,1); +plot(t,data); +xlim([0, 1.5*10^(-5)]) +xlabel('time(s)'); +title(' ȣ ') +subplot(4,2,2); +plot(f, Freq_dB); +xlabel('freq (Hz)'); +title(' ȣ ļ ') + +% ȣ with LPF1 +subplot(4,2,3); +plot(t,data_AM_demod_LPF1); +xlim([0, 1.5*10^(-5)]) +xlabel('time(s)'); +title('LPF 1 ̿Ͽ ȣ ') +subplot(4,2,4); +plot(f, freq_data_AM_demod_LPF1); +xlabel('freq (Hz)'); +title('LPF 1 ̿Ͽ ȣ ļ ') + +% ȣ with LPF2 +subplot(4,2,5); +plot(t,data_AM_demod_LPF2); +xlim([0, 1.5*10^(-5)]) +xlabel('time(s)'); +title('LPF 2 ̿Ͽ ȣ ') +subplot(4,2,6); +plot(f, freq_data_AM_demod_LPF2); +xlabel('freq (Hz)'); +title('LPF 2 ̿Ͽ ȣ ļ ') + +% ȣ with LPF3 +subplot(4,2,7); +plot(t,data_AM_demod_LPF3); +xlim([0, 1.5*10^(-5)]) +xlabel('time(s)'); +title('LPF 3 ̿Ͽ ȣ ') +subplot(4,2,8); +plot(f, freq_data_AM_demod_LPF3); +xlabel('freq (Hz)'); +title('LPF 3 ̿Ͽ ȣ ļ ') \ No newline at end of file diff --git "a/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/Amplitude_Modulation_and_Demodulation.zip" "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/Amplitude_Modulation_and_Demodulation.zip" new file mode 100644 index 0000000..1948c68 Binary files /dev/null and "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/Amplitude_Modulation_and_Demodulation.zip" differ diff --git "a/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/LPF_1.mat" "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/LPF_1.mat" new file mode 100644 index 0000000..3fe4577 Binary files /dev/null and "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/LPF_1.mat" differ diff --git "a/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/LPF_2.mat" "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/LPF_2.mat" new file mode 100644 index 0000000..852b7a0 Binary files /dev/null and "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/LPF_2.mat" differ diff --git "a/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/LPF_3.mat" "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/LPF_3.mat" new file mode 100644 index 0000000..88fef2b Binary files /dev/null and "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/LPF_3.mat" differ diff --git "a/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/data_baseband.mat" "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/data_baseband.mat" new file mode 100644 index 0000000..e396639 Binary files /dev/null and "b/\354\213\240\355\230\270\354\262\230\353\246\254\354\235\274\353\260\230/ikoes\353\213\230_\354\247\210\353\254\270/data_baseband.mat" differ diff --git "a/\355\206\265\352\263\204\355\225\231/Kalman_filter/MouseMovement_Tracking/no01_TrackMouse_Kalman.m" "b/\355\206\265\352\263\204\355\225\231/Kalman_filter/MouseMovement_Tracking/no01_TrackMouse_Kalman.m" new file mode 100644 index 0000000..acab077 --- /dev/null +++ "b/\355\206\265\352\263\204\355\225\231/Kalman_filter/MouseMovement_Tracking/no01_TrackMouse_Kalman.m" @@ -0,0 +1,91 @@ +clear; close all; clc; +%{ +Kalman filter ̿ Mouse Position Tracking + +2021 4 7 +%} + + +%% DEFINITION +global C + +%% +figure; +set(gcf,'WindowButtonMotionFcn', @mouseMove); +history_C = []; +history_C_pred = []; + +while(1) + history_C = [history_C, [C(1,1); C(1,2)]]; + plot(history_C(1,:), history_C(2,:),'color',[0, 0.447, 0.741]); hold on; + plot(C(1,1), C(1,2), 'o','markerfacecolor','g','markeredgecolor','k'); + + [C_pred(1,1), C_pred(1,2)] = TrackKalman(C(1,1), C(1,2)); + history_C_pred = [history_C_pred, [C_pred(1,1); C_pred(1,2)]]; + + plot(history_C_pred(1,:), history_C_pred(2,:),'color',[0.85, 0.325, 0.098]); hold on; + plot(C_pred(1,1), C_pred(1,2), 'o','markerfacecolor','r','markeredgecolor','k'); + + xlim([0, 1]) + ylim([0, 1]) + pause(0.001); + + % history ʹ ȭ Ƿ shift . + if size(history_C, 2) > 500 + history_C = history_C(:, end-499:end); + end + + if size(history_C_pred, 2) > 500 + history_C_pred = history_C_pred(:, end-499:end); + end + + cla; +end + +function mouseMove (object, eventdata) +global C +C = get(gca, 'CurrentPoint'); +end + +function [xh, yh] = TrackKalman(xm, ym) +% +% +persistent A H Q R +persistent x P +persistent firstRun + + +if isempty(firstRun) + dt = 1; + + A = [ 1 dt 0 0 + 0 1 0 0 + 0 0 1 dt + 0 0 0 1 ]; + + H = [ 1 0 0 0 + 0 0 1 0 ]; + + Q = 0.0001*eye(4); % ۾ true õõ . + R = 200 * eye(2); + + x = [0, 0, 0, 0]'; + P = 100*eye(4); + + firstRun = 1; +end + + +xp = A*x; +Pp = A*P*A' + Q; + +K = Pp*H'*inv(H*Pp*H' + R); + +z = [xm ym]'; +x = xp + K*(z - H*xp); +P = Pp - K*H*Pp; + + +xh = x(1); +yh = x(3); +end \ No newline at end of file diff --git "a/\355\206\265\352\263\204\355\225\231/Kalman_filter/main.m" "b/\355\206\265\352\263\204\355\225\231/Kalman_filter/main.m" new file mode 100644 index 0000000..de65a33 --- /dev/null +++ "b/\355\206\265\352\263\204\355\225\231/Kalman_filter/main.m" @@ -0,0 +1,70 @@ +clear; close all; clc; + +measurements = [5, 6, 7, 9, 10]; +motion = [1, 1, 2, 1, 1]; +measurement_sig = 4; +motion_sig = 2; + +mu = 0; +sig = 10; + +xx = linspace(-2, 15, 1000); +yy1 = normpdf(xx, mu, sig); + +my_color = lines(3); +clear h + +figure; +h(1) = plot(xx, yy1,'color',my_color(1,:),'linewidth',2); hold on; % ù Prior +ylim([0, 0.35]) +disp('ù Prior '); +pause +for i = 1:length(measurements) + yy2 = normpdf(xx, measurements(i), measurement_sig); + + if i>1 + delete(h(2)); + end + + h(2) = plot(xx, yy2,'color',my_color(2,:),'linewidth',2); % measurement + disp('measure'); + pause; + + [mu, sig] = update(mu, sig, measurements(i), measurement_sig); + yy1 = normpdf(xx, mu, sig); + + if i>1 + delete(h(3)); + end + + + h(3) = plot(xx, yy1,'color',my_color(3,:),'linewidth',2); hold on; % Posterior . + disp('measure Prior Posterior Ʈ .'); + pause; + +% disp(['Update:',num2str(mu),'/',num2str(sig)]); + + [mu, sig] = predict(mu, sig, motion(i), motion_sig); + yy1 = normpdf(xx, mu, sig); + + delete(h(1)) + h(1) = plot(xx, yy1,'color',my_color(1,:),'linewidth',2); hold on; % Prior . + disp(' Prior ̵'); + pause; +% disp(['Predict:',num2str(mu),'/',num2str(sig)]); +end + +function [new_mean, new_var] = predict(mean1, var1, mean2, var2) + +new_mean = mean1 + mean2; +new_var = var1 + var2; +% new_var = var1; + +end + +function [new_mean, new_var] = update(mean1, var1, mean2, var2) + +new_mean = (var2 * mean1 + var1 * mean2) / (var1 + var2); +new_var = 1/(1/var1 + 1/var2); + +end diff --git "a/\355\206\265\352\263\204\355\225\231/sampling_and_standard_error/plots_for_PPT.m" "b/\355\206\265\352\263\204\355\225\231/sampling_and_standard_error/plots_for_PPT.m" index 73c3e1e..ba03f12 100644 --- "a/\355\206\265\352\263\204\355\225\231/sampling_and_standard_error/plots_for_PPT.m" +++ "b/\355\206\265\352\263\204\355\225\231/sampling_and_standard_error/plots_for_PPT.m" @@ -2,7 +2,8 @@ % rng(4) % data = round(randn(1,150)* 2 + 15); -load('C:\gongdols\\sampling_and_standard_error\data.mat') +% load('C:\gongdols\\sampling_and_standard_error\data.mat') +load('data.mat'); %% Fig. 1. close all; mksize = 8;