clc; clear all; n=input('Enter the value of n:'); k=input('Enter the vaue of k:'); disp('Message bits'); m=randint(1,k,[0,1]); disp(m); disp('Cyclic Polynomial'); p=cyclpoly(n,k,'min'); disp(p); disp('Encoded Word'); x=encode(m,n,k,'cyclic/fmt',p); disp(x); disp('Error Pattern Generation'); e=randerr(1,n,[1,0]); disp(e); disp('Received Code Vector'); r=rem(plus(x,e),2); disp(r); disp('Decode Message Bits'); msg=decode(r,n,k,'Cyclic'); disp(msg);
clc; clear all; close all; fc=input('Enter the carrier frequency,fc='); fm=input('Enter the modulating frequency,fm='); ac=input('Enter the carrier amplitude,ac='); am=input('Enter the modulating signal amplitude,am='); fs=input('Enter the sampling frequency,fs='); t=0:1/fs:1; Am=am*cos(2*pi*fm*t); Ac=ac*cos(2*pi*fc*t); m=am/ac; y=Ac.*(1+m*cos(2*pi*fm*t)); subplot(3,1,1); plot(t,Am); xlabel('Time'); ylabel('Amplitude of modulating signal'); title('Modulating signal'); subplot(3,1,2); plot(t,Ac); xlabel('Time'); ylabel('Amplitude of carrier signal'); title('Carrier signal'); subplot(3,1,3); plot(t,y); xlabel('Time'); ylabel('Amplitude of modulated signal'); title('Modulated signal'); xlabel('Time'); ylabel('Amplitude of carrier signal'); title('Carrier signal'); subplot(3,1,3); plot(t,y); xlabel('Time'); ylabel('Amplitude of modulated signal'); title('Modulated signal');
clear all clc X = [0 1 2 3 4 5 6 7 8 9 10 11]; Y = [47.22 45.57 47.35 49.41 48.58 51.05 52.41 52.23 50.17 50.29 50.75 45.51]; % X = [0 2 4 6 ]; % Y = [47.22 47.35 48.58 52.41]; % Polynomial Order Setting % M = length(X)-1; M = 4; % A = [x^M ... x^0] Order = M:-1:0; rep_Order = repmat(Order,length(X),1); rep_X = repmat(X',1,M+1) A = rep_X.^rep_Order Y' % Data Normalize - Important for Gradient Descent nor_A = ones(length(X),M+1); varA = zeros(1,M); mn_A = zeros(1,M); for iM = 1:M varA(iM) = var(A(:,iM)); mn_A(iM) = mean(A(:,iM)); nor_A(:,iM) = (A(:,iM)-mn_A(iM))/varA(iM); end if(M == (length(X)-1) ) w = inv(A)*Y'; else % ML Close Form Solution % w = inv(A'*A)*A'*Y' A = nor_A; w = zeros(M+1,1); Max_Big_Loop = 10; Max_Small_Loop = 1000; eta = 0.01; h = 0.1; tolerant = 10; Ew_Rec = zeros(1,Max_Big_Loop); for iBig = 1:Max_Big_Loop for iw = 1:length(w) for iSmall = 1:Max_Small_Loop w_h = w; w_h(iw) = w_h(iw) + h ; E_w = sum((A*w - Y').^2); E_w_h = sum((A*w_h - Y').^2); grad_Ew = (E_w_h - E_w)/h; w(iw) = w(iw) - eta*grad_Ew; if (min([E_w E_w_h])<tolerant) , break, end ; end end Ew_Rec(iBig)=min([E_w E_w_h]); end end plt_X = 0:0.2:12; rep_Order = repmat(Order,length(plt_X),1); rep_plt_X = repmat(plt_X',1,M+1); A_plt = rep_plt_X.^rep_Order; nor_A_plt = ones(length(plt_X),M+1); for iM = 1:M nor_A_plt(:,iM) = (A_plt(:,iM)-mn_A(iM))/varA(iM); end if(M == (length(X)-1) ) Y_Estimation = A_plt*w; else Y_Estimation = nor_A_plt*w; end fig = figure; line1 = plot(X,Y); hold on; line2 = plot(plt_X,Y_Estimation); set(line1,'color','r','linestyle','-','marker','*'); set(line2,'color','b','linestyle','-','marker','o'); title('X-Y Curve Fitting'); xlabel('X '); ylabel('Y ');
files = dir('*.jpg'); for k = length(files(:,1)) % Leer la matricula mat = imread(files(k).name); % Preparar la carpeta para el output [filepath,name,ext] = fileparts(files(k).name); mkdir name; % Matricula a escala de grises mat_gris = rgb2gray(mat); threshold = graythresh(mat_gris); % Binarizar en funcion del color del fondo mat_binaria = imcomplement(imbinarize(mat_gris, threshold*0.8)); mat_binaria_menos_ruido = bwareaopen(mat_binaria, 200); % Extraer los componentes [L, n] = bwlabel(mat_binaria_menos_ruido); % Calcular los BoundingBox de cada comonente bb = regionprops(L,'BoundingBox'); % comp = cell(n,1); for i = 1:n bb_i = ceil(bb(i).BoundingBox); idx_x = [bb_i(1) bb_i(1)+bb_i(3)]; idx_y = [bb_i(2) bb_i(2)+bb_i(4)]; im = L==i; comp{i} = im(idx_y(1):idx_y(2),idx_x(1):idx_x(2)); end % Guardar los componentes en imagenes for i = 2:n imwrite(comp{i}, strcat(strcat(strcat(name,'/'),int2str(i-1)),'.jpg')); end end
clear all, clc, close all %% 1. Setup L = 1; % [m] Length W = 0.5; % [m] Width h = 10; % [W/m^2 K] Convection coefficient [south face] Tinf = .5; % [K] Temperature for convection [south face] qs = 10; % [W/m^2] incident heat flux [north face] k = 1; % [W/m K] thermal conductivity q0 = 0; % [W/m^3] generation rate N =50; % nodes for discretization (x) M =50; % nodes for discretization (t) dx = L/(N-1); % Step size dy = W/(M-1); % Step size x = 0:dx:L; % vector of positions y = 0:dy:W; % vector of positions A = zeros(N*M,N*M); b = zeros(N*M,1); %% 2. Interior Nodes for i1 = 2:N-1 for i2 = 2:M-1 in = i1+(i2-1)*N; A(in,in) = -2/(dx)^2 - 2/(dy)^2; A(in,in-1) = 1/dx^2; A(in,in+1) = 1/dx^2; A(in,in+N) = 1/dy^2; A(in,in-N) = 1/dy^2; b(in,1) = -q0/k; end end %% 3. Boundary Nodes % East Face [incl. NorthEast and SouthEast Corners] i1 = N; for i2 = 1:M in = i1+(i2-1)*N; A(in,in) = 1; b(in,1) = 0; end % West Face i1 = 1; for i2 = 2:M-1 in = i1+(i2-1)*N; A(in,in) = -2/(dx)^2 - 2/(dy)^2; A(in,in+1) = 2/dx^2; A(in,in+N) = 1/dy^2; A(in,in-N) = 1/dy^2; b(in,1) = -q0/k; end % North Face i2 = M; for i1 = 2:N-1 in = i1+(i2-1)*N; A(in,in) = -1/(dx)^2 - 1/(dy)^2; A(in,in-1) = 1/(2*dx^2); A(in,in+1) = 1/(2*dx^2); A(in,in-N) = 1/dy^2; b(in,1) = -q0/(2*k)-qs/(k*dy); end % South Face i2 = 1; for i1 = 2:N-1 in = i1+(i2-1)*N; A(in,in) = -1/(dx)^2 - 1/(dy)^2 - h/(k*dy); A(in,in-1) = 1/(2*dx^2); A(in,in+1) = 1/(2*dx^2); A(in,in+N) = 1/dy^2; b(in,1) = -q0/(2*k)-h/(k*dy)*Tinf; end % SouthWest Corner [in-1 = in +1] i1 = 1; i2 = 1; in = i1+(i2-1)*N; A(in,in) = -1/(dx)^2 - 1/(dy)^2-h/(k*dy); A(in,in+1) = 2/(2*dx^2); A(in,in+N) = 1/dy^2; b(in,1) = -q0/(2*k)-h/(k*dy)*Tinf; % NorthWest Corner [in-1 = in +1] i1 = 1; i2 = M; in = i1+(i2-1)*N; A(in,in) = -1/(dx)^2 - 1/(dy)^2; A(in,in+1) = 2/(2*dx^2); A(in,in-N) = 1/dy^2; b(in,1) = -q0/(2*k)-qs/(k*dy); %% 4. Solve T = A\b; %% 5. Plot Tij = reshape(T,M,N)'; figure(1), clf % surf(x,y,Tij), shading interp, colorbar % % xlabel('y') % % ylabel('x') % % zlabel('T') contourf(x,y,Tij,25)%, shading interp xlabel('x') ylabel('y') print -dpng figure.png
img1=imread('Lines.jpg'); imshow(img1) img1=rgb2gray(img1); imshow(img1) img2=im2bw(img1,graythresh(img1)); imshow(img2) img2=~img2; imshow(img2) B = bwboundaries(img2); imshow(img2) text(10,10,strcat('\color{green}Objects Found:',num2str(length(B)))) hold on for k = 1:length(B) boundary = B{k}; plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 0.2) end
lines (13 sloc) 428 Bytes % Create a Gaussian pyramid % Essentially this uses reduce for a total of levels times. % Each image in one scale is half the size of the previous scale % First scale is simply the original image function [gaussout] = gauss_pyramid(im, levels) gaussout = cell(1,levels+1); gaussout{1} = im; subsample = im; for i = 2 : levels+1 subsample = reduce(subsample); gaussout{i} = subsample; end end
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more