Plotting two different equations on the same graph/matlab -
while able plot fft( fast fourier transform) plot(x,y), unable plot fit line f(x) along fft. equations gathered curve fitting tool, took ten best fit , averaged come equation f(x).
what must f(x) plotted log(freq) , log(pow)
code:
row=69; col=69; colormap gray whitebg('black') iterations=10^3; next=zeros(row,col); laplacian=zeros(row,col); critical=zeros(row,col); b= zeros(row,col); lums=zeros(1000); flw=0.5; u=0.1; crit=5; %bns=200; bns=1000; k=1:iterations b=b+(rand(row,col)-0.5); next=b; rns=5.; i=1:row j=1:col rfromns=(col+rns-j); critical(i,j)=0; if i<=2 left=row; else left=(i-1);end if i==row right=1; else right=(i+1);end if (j<=2) top=1; else top=(j-1);end if (j==col) bottom=j; else bottom=(j+1);end l=b(i,top)+b(left,j)+b(right,j)+b(i,bottom)+0.5*(b(left,top)+b(right,top)+b(left,bottom)+b(right,bottom)); l=l-6.*b(i,j); laplacian(i,j)=l; bfromns=bns/rfromns^3; if (abs(l)/((abs(b(i,j))+bfromns)+0.01))>crit; critical(i,j)=1; end %if abs(l)>crit; critical(i,j)=1; end end end j = 1:col if (j==col) lum=0.;end = 1:row if (j>1) next(i,j)=(1-flw)*b(i,j)+flw*b(i,j-1); end; if (j==1) next(i,j)=(1-flw)*b(i,j); end; if (critical(i,j)==1)&& (j>1) next(i,j)=b(i,j)*(1-flw-flw*u)+flw*b(i,j-1)+(flw*u)*b(i,j)/5.; end; if i<2 left=row; else left=(i-1);end if i==row right=1; else right=(i+1);end if (j<=2) top=1; else top=(j-1);end if (j==col) bottom=j; else bottom=(j+1);end if (critical(left,j)==1) next(i,j)=next(i,j)+flw*u*b(left,j)/5.;end if (critical(right,j)==1) next(i,j)=next(i,j)+flw*u*b(right,j)/5.;end if (critical(i,top)==1) next(i,j)=next(i,j)+flw*u*b(i,top)/5.;end if (critical(i,bottom)==1) next(i,j)=next(i,j)+flw*u*b(i,bottom)/5.;end if (j==col) lum=lum+u*b(i,j)*b(i,j)+abs(laplacian(i,j)); end end end lums(k)=lum; b=next; %matplot(b) %if (k>00) surf(b); %plot(lums) %view([0 90]) %pause(0.001) %end end c=fft(lums(129:iterations)); pow=abs(c).^2; pow=pow(2:(iterations-128)/2); freq=(2:(iterations-128)/2); x=log(freq); y=log(pow); %x=length(x); x=0.6:.1:6.; %linear model poly2 a1 = -0.155; a2 = 0.2154; a3 = 15.1; af(x) = a1*x.^2 + a2*x + a3; %linear model poly3 b1 = 0.01805; b2 = -0.3687; b3 = 0.9874; b4 = 14.29; bf(x) = b1*x.^3 + b2*x.^2 + b3*x + b4; %general model power2 c1 = -0.09124; c2 = 2.179; c3 = 15.34; cf(x) = c1*x.^c2+c3; %general model rat02 d1 = 727.3; d2 = -3.447; d3 = 51.6; df(x) = (d1) / (x.^2 + d2*x + d3); %general model gauss1 e1 = 15.01; e2 = 1.346; e3 = 8.152; ef(x) = e1*exp(-((x-e2)/e3).^2); %general model gauss2 w1 = 1.737; w2 = 3.46; w3 = 2.333; w4 = 30.03; w5 = -23.14; w6 = 28.23; wf(x) = w1*exp(-((x-w2)/w3).^2) + w4*exp(-((x-w5)/w6).^2); %general model sin1 g1 = 15.11; g2 = 0.1526; g3 = 1.428; gf(x) = g1*sin(g2*x+g3); %linear model poly4 h1 = 0.0179; h2 = -0.252; h3 = 1.047; h4 = -1.97; h5 = 16.23; hf(x) = h1*x.^4 + h2*x.^3 + h3*x.^2 + h4*x + h5; %general model fourier1 m1 = 11.05; m2 = 3.31; m3 = 2.104; m4 = 0.3644; mf(x) = m1 + m2*cos(x*m4) + m3*sin(x*m4); %linear model p1 = 0.815; p2 = 0.1061; p3 = 8.904; pf(x) = p1*(sin(x-pi)) + p2*((x-10).^2) + p3; f(x)=(af(x)+bf(x)+cf(x)+df(x)+ef(x)+wf(x)+gf(x)+hf(x)+mf(x)+pf(x))/10; plot(x,y) plot(f(x))
matlab/octave therefore use hold
keyword.
if want plot several things on 1 graph, start program hold on
, execute 1 or more plot command, , finalize hold off
.
example:
hold on; x = -10:0.1:10; plot (x, sin (x)); plot (x, cos (x)); hold off;
documentation: https://www.gnu.org/software/octave/doc/interpreter/manipulation-of-plot-windows.html
as documentation describes, plot
call newplot
command, removes previous plot result, hold on;
such behavior prevented.
Comments
Post a Comment