Latest Updates

Showing posts with label matlab. Show all posts
Showing posts with label matlab. Show all posts

Matlab : Flat top sampling using matlab

November 07, 2016



clear all;
close all;

p=0.001:.001:1;

o=ones(1,length(p));
z=zeros(1,length(p));

m=repmat([z o z o z o z o z o z o z o z o z o z o],[1,4]);

t=0.001:.001:length(m)/1000;

    y=.5*sin(t/10);
     

    x=y.*m;

    y1=x;
for i = 2:length(t)
    if m(i) == 1 && m(i-1) == 0 %if the rising edge is detected
        y1(i) = m(i) * y(i);    %sampling occurs
    elseif m(i) == 1 && m(i-1) == 1 %and while the carrier signal is 1
        y1(i) = y1(i-1);              %the value of y1 remains constant
    else
        y1(i) = 0;                %otherwise, y is zero
    end
end
 
   
subplot(3,1,1);
plot(t,y);

subplot(3,1,2);
plot(t,x);

subplot(3,1,3);
plot(t,y1);

Matlab : Gibbs phenomenon of given harmonics

November 05, 2016
Gibbs phenomenon of given harmonics

Code:


clc;
clear all;
close all;


t=linspace(-2,2,2000);
u=linspace(-2,2,2000);
sq=[zeros(1,500),2*ones(1,1000),zeros(1,500)];
k=2;
prompt='Enter Harmonics No: ';
N =input(prompt);
%N=[5];
for n=1:1;
an=[];
for  m=1:N(n)
    an=[an,2*k*sin(m*pi/2)/(m*pi)];
end;
fN=k/2;
for m=1:N(n)
    fN=fN+an(m)*cos(m*pi*t/2);
end;
nq=int2str(N(n));
plot(u,sq,'r','LineWidth',2);hold on;
plot(t,fN,'LineWidth',2); hold off; axis([-2 2 -0.5 2.5]);grid;
xlabel('Time'), ylabel('y_N(t)');title(['N= ',nq]);
end;


Output: 




Matlab : 2 | Input number

November 05, 2016



Take number input by this code


prompt='Enter your name: ';
N =input(prompt)





Matlab : 1 | Add two number

November 05, 2016



Open Matlab>New Script>


paste this code

a=12;
b=34;
c=a+b



Run/Press F5
 
Copyright © Ebots.