i want a concise code to perform simple operations on an acquired signal which is in cvv format.
MATLAB: How to reverse,scale and shift an acquired signal
@signalreversing#signalacquisition#signals processing#signalsandsystems#signalscaling#signalshifting#signalsproject
Related Solutions
% FOR TIME VARITANT OR INVARIANT
clcclear allclose allt=-5:0.001:5l=length(t)for i=1:l if t(i)>=0 x1(i)=1; else x1(i)=0; endendx2=cos(pi*t)x3=cos(pi*(t-2))y1=x1.*x2y2=x1.*x3subplot(4,1,1)plot(t,x1)xlabel('t')ylabel('x1')title('for x1')grid ongtext('1841014009')subplot(4,1,2)plot(t,y1)xlabel('t')ylabel('y1')title('for y1')grid ongtext('1841014009')subplot(4,1,3)plot(t,x2)xlabel('t')ylabel('x2')title('for x2')grid ongtext('1841014009')subplot(4,1,4)plot(t,y2)xlabel('t')ylabel('y2')title('for y2')grid ongtext('1841014009')if round(y1)==round(y2) disp('time invariant');text(-2,-0.5, ('System Is Time Invariant')); else disp('time variant');text(-2,-0.5, ('System Is Time Variant'))end% FOR LINEARITY TEST
clcclear allclose allt=-4:0.001:5l=length(t)for i=1:l if t(i)>=0 x1(i)=1; else x1(i)=0; endend for i=1:lif t(i)>=1 x2(i)=1; else x2(i)=0;endend a1=2a2=3 y1=a1.*x1.*cos(pi*t)y2=a2.*x2.*cos(pi*(t-1)) y=((a1.*x1)+(a2.*x2)).*cos(pi*t) y3=y1+y2; subplot(4,1,1)plot(t,y)title('for y')xlabel('t')ylabel('y')grid ongtext('1841014009')subplot(4,1,2)plot(t,y1)title('for y1')xlabel('t')ylabel('y1')grid ongtext('1841014009') subplot(4,1,3)plot(t,y2)title('for y2')xlabel('t')ylabel('y2')grid ongtext('1841014009') subplot(4,1,4)plot(t,y3)title('for y3')xlabel('t')ylabel('y3')grid ongtext('1841014009') if round(y)==round(y3) disp('system is linear'); text(-2,-0.5, ('System Is Linear')); else disp('system is non linear'); text(-2,-0.5, ('System Is Non-Linear'));end% FOR STABILITY TEST
clcclear allclose allt=0:0.01:10l=length(t)for i=1:l if t(i)>=0 x(i)=1; else x(i)=0; endend y=exp(-2*t).*xc=0for i=1:l-1 if (y(i)>y(i+1)) c=c+1; endend subplot(2,1,1)plot(t,x)title('for x')xlabel('t')ylabel('x')grid ongtext('1841014009')subplot(2,1,2)plot(t,y)title('for y')xlabel('t')ylabel('y')grid ongtext('1841014009')if(c~=0) disp('system is stable'); text(2,0.5, ('System Is Stable'));else disp('system is unstable'); text(2,0.5, ('System Is Untable'));end
Give your functions outputs:
newtonfunction newtonx0 = input('Enter the initial guess value, x: ');tolerance = input('Enter the tolerance value, tol: ');max_i = input('Enter the maximum no. of iteration, max_i: ');r = input('Enter the value of relative roughness, e/D: ');RN = input('Enter the Reynolds number, RN: ');f = input('Enter the Friction factor, f: ');c = colebrook/colebrook_deriv;x=x0;for i=1:max_i y = x; x = y - (c); if abs(x-y)<= tolerance disp(['root = ', num2str(x)]) break endendfprintf('The number of iterations: %d\n', i) function CFd = colebrook %%Formula for C(fd)
CFd =(1/sqrt(f)) + 2*log10(r/(3.7)+ 2.51/(RN*sqrt(f))); end function CFd1 = colebrook_deriv CFd1 = 1/(2*f^(3/2)) + 2.51/RN*f^(3/2)*log(10)*(r/3.7) + 2.51/(RN*f^(1/2)); endend
Also check the function for colebrook_deriv i had to make a change (missing '*' i guess) tha you should correct if needed. Problems here:
CFd1 = 1/(2*f^(3/2)) + 2.51/RN*f^(3/2)log(10)(r/3.7) + 2.51/(RN*f^(1/2));% ^ ^
% | |
% ----------- Check here
Also i added the final end, because i suspect that you wanted to have nested functions.
Best Answer