Professional Documents
Culture Documents
TECHNOLOGY
Submitted By:
Name: Faria Sultana Mimi
Roll: 1931001
Batch: 2k19
Year: 2’nd
Semester: 2’nd
edit dct;
edit sin;
Output:
function b=dct(a,varargin)
%DCT Discrete cosine transform.
% Y = DCT(X) returns the discrete cosine transform of vector X.
% If X is a matrix, the DCT operation is applied to each
% column. For N-D arrays, DCT operates on the first non-singleton
% dimension. This transform can be inverted using IDCT.
%
% Y = DCT(X,N) pads or truncates the vector X to length N
% before transforming.
%
% Y = DCT(X,[],DIM) or Y = DCT(X,N,DIM) applies the DCT operation along
% dimension DIM.
%
% Y = DCT(...,'Type',K) specifies the type of discrete cosine transform
% to compute. K can be one of 1, 2, 3, or 4, to represent the DCT-I,
% DCT-II, DCT-III, and DCT-IV transforms, respectively. The default
% value for K is 2 (the DCT-II transform).
%
% % Example:
% % Find how many DCT coefficients represent 99% of the energy
% % in a sequence.
%
% x = (1:100) + 50*cos((1:100)*2*pi/40); % Input Signal
% X = dct(x); % Discrete cosine transform
% [XX,ind] = sort(abs(X)); ind = fliplr(ind);
% num_coeff = 1;
% while (norm([X(ind(1:num_coeff)) zeros(1,100-num_coeff)])/norm(X)<.99)
% num_coeff = num_coeff + 1;
% end
% num_coeff
%
% See also FFT, IFFT, IDCT.
% References:
% 1) A. K. Jain, "Fundamentals of Digital Image
% Processing", pp. 150-153.
% 2) Wallace, "The JPEG Still Picture Compression Standard",
% Communications of the ACM, April 1991.
if nargin == 0
error(message('signal:dct:Nargchk'));
end
if nargin > 1
[varargin{:}] = convertStringsToChars(varargin{:});
end
if isa(a,'gpuArray')
coder.internal.errorIf(~ismatrix(a),'signal:dct:NotAMatrixGPU');
if ~isempty(varargin)
coder.internal.errorIf(~isscalar(varargin{1})||length(varargin)>1,...
'signal:dct:TooManyInputs');
end
end
function b = dctinternal(varargin)
p = inputParser;
p.addRequired('X');
p.addOptional('N',[]);
p.addOptional('DIM',[]);
p.addParameter('Type',2);
p.parse(varargin{:});
r = p.Results;
x = r.X;
type = r.Type;
if isempty(r.N) && isempty(r.DIM)
[dim,n] = firstNonSingletonDimension(x);
elseif isempty(r.N)
dim = r.DIM;
n = size(x,dim);
elseif isempty(r.DIM)
dim = firstNonSingletonDimension(x);
n = r.N;
else
dim = r.DIM;
n = r.N;
end
validateattributes(n,{'numeric'},{'integer','scalar','positive','finite'});
validateattributes(dim,{'numeric'},{'integer','scalar','positive','finite'});
n = double(n);
if type==1
x = x .* scale(type);
idc = dimselect(dim,size(x));
x(1+idc) = x(1+idc) * dcscale(type);
if size(x,dim) >= n
x(end-idc) = x(end-idc) * dcscale(type);
end
elseif type==3
x = x .* scale(type);
idc = 1+dimselect(dim,size(x));
x(idc) = x(idc) * dcscale(type);
end
if n==1
if dim==1
b = matlab.internal.math.transform.mldct(x(1,:),n,dim,'Variant',type);
elseif dim==2
b = matlab.internal.math.transform.mldct(x(:,1),n,dim,'Variant',type);
else
b = matlab.internal.math.transform.mldct(x,n,dim,'Variant',type);
end
else
b = matlab.internal.math.transform.mldct(x,n,dim,'Variant',type);
end
if type==1
idc = dimselect(dim,size(b));
b(idc+1) = b(idc+1) * sqrt(0.5);
b(end-idc) = b(end-idc) * sqrt(0.5);
elseif type==2
b = b .* scale(type);
idc = 1+dimselect(dim,size(b));
b(idc) = b(idc) * dcscale(type);
elseif type==4
b = b .* scale(type);
idc = 1+dimselect(dim,size(b));
b(idc) = b(idc) * dcscale(type);
end
function b = dctcodegen(a,n)
if nargin==1
n = size(a,1);
end
% Cast to enforce precision rules
n = signal.internal.sigcasttofloat(n,'double','dct','N','allownumeric');
m = size(a,2);
if isreal(a)
b = real(b);
end
if do_trans
b = b.';
end
Help rand
Output:
rand Uniformly distributed pseudorandom numbers.
same class as Y.
the uniform random number generator that underlies rand, RANDI, and RANDN.
Examples:
r = a + (b-a).*rand(100,1);
r = randi(100,1,5);
Example 3: Reset the random number generator used by rand, RANDI, and
RANDN to its default startup settings, so that rand produces the same
rng('default')
rand(1,5)
Example 4: Save the settings for the random number generator used by
rand, RANDI, and RANDN, generate 5 values from rand, restore the
s = rng
u1 = rand(1,5)
rng(s);
RANDI, and RANDN with a seed based on the current time. rand will
rand(1,5)
See Replace Discouraged Syntaxes of rand and randn to use RNG to replace
>> a=3;
>> b=5;
>> c=7;
>> clear b
Output:
Experiment-02
Answer to the exercise 1(a):
>> inv(x)
ans =
-0.1034 0.1379
0.2759 -0.0345
ans =
>> sum(x)
ans =
9 7
>> sum(sum(x))
ans =
16
>> x'
ans =
1 8
4 3
>> x= [2 8 5; 9 7 1];
>> max(x)
ans =
9 8 5
>> max(max(x))
ans =
>> min(x)
ans =
2 7 1
>> min(min(x))
ans = 1
>> median(x)
ans =
2 7 5
>> median(median(x))
ans =
> x( end+1, : ) = b
x=
2 8 5
9 7 1
2 4 5
>> a=mean(x)
a=
x=
ans =
9.0000
15.0000
10.0000
7.6667
6.0000
11.0000
5.3333
3.0000
1.0000
>> eye(4)
ans =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
>> b=[5:5:100]
b=
Columns 1 through 16
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80
Columns 17 through 20
85 90 95 100
>> numel(b)
ans =
20
Experiment-03:
Answer to the exercise 1(a):
>> x=2
x=
>> y=4
y=
>> z=sqrt(5*x^2+y^2)
z=
>> x=pi/4
x=
0.7854
>> z=4*cos(x)+i*6*sin(x)
z=
2.8284 + 4.2426i
>> x=pi/3
x=
1.0472
>> y=2
y=
>> z=3*sin(x)+4*cos(x)+3*exp(y)
z=
26.7652
>> x=[0:2*pi]
x=
0 1 2 3 4 5 6
>> y=sin(x)/x
y=
-0.0705
>> b=[3;7;4];
>> solution=a\b
solution =
>> floor(1.3)
ans =
>> fix(1.5)
ans =
>> round(1.9)
ans =
>> fix(11.9)
ans =
11
>> ceil(-2.9)
ans =
-2
>> floor(-3.9)
ans =
-4
>> round(3.4)
ans = 3
>> r=2*10^-13
r=
2.0000e-13
>> Q=1.6e-19
Q=
1.6000e-19
>> K=9e9
K=
9.0000e+09
>> Electromagnetic_Force=K*Q^2/r^2
Electromagnetic_Force =
0.0058
>> [2:0.15:3.5]
ans =
Columns 1 through 9
Columns 10 through 11
3.3500 3.5000
Experiment-04
Answer to the exercise 1(a):
v = (x | y) & z
w = ~ (x | y) & z
x = input('Enter the bit sequence in MAT to test for Even parity: ');
t = 0;
if(x(i))
end
end
if(mod(t,2)~=0) %check if not even then attach another '1' to make the
parity
even
else %check if even then attach another '0' to let the parity be even
end
disp(y); %display the resultant bit sequence after parity bit addition
Output:
Answer to the exercise 3:
a=rand(10,10)>0.5;
currently
its a 100x100 binary matrix %you can provide your own matrix of any size
but
g(:,1) = a(:,1); %assign the 1st element of each row to the resultant 'g',
as
it is.for i = 2:size(a,2)
end
disp('Input: ');
disp(a);
disp('Output: ');
disp(g);
Output:
>> q>2
ans =
0 1 1 1 1 0 1 1 1 1 0
2 4 5
1 1 1 0 1 1 1 1 0 1 0
v=
0 1
1 1
(b) >> w=z>=y
w=
0 1
0 0
u=
1 0
1 1
t=
0 0
0 0
Experiment-05
Answer to the exercise 1:
>> t=0:0.001:30;
A=4;
w=2*pi*2;
y=A*sawtooth(w*t);
plot(t,y)
>> x=[-2*pi:0.1:2*pi];
>> y=sin(x)./x;
>> plot(y)
Experiment 06
Answer to the exercise 1:
>> z=2+5i
z=
2.0000 + 5.0000i
>> abs_of_z=abs(z)
abs_of_z =
5.3852
>> angle_of_z=angle(z)*180/pi
angle_of_z =
68.1986
>> Y=-3-3i
Y=
-3.0000 - 3.0000i
>> abs_of_Y=abs(Y)
abs_of_Y =
4.2426
>> angle_of_Y=angle(Y)*180/pi
angle_of_Y =
-135
>> D=-2+6i
D=
-2.0000 + 6.0000i
>> abs_of_D=abs(D)
abs_of_D =
6.3246
>> angle_of_D=angle(D)*180/pi
angle_of_D =
108.4349
>> Conjugate_of_Z=conj(z)
Conjugate_of_Z =
2.0000 - 5.0000i
>> Conjugate_of_D=conj(D)
Conjugate_of_D =
-2.0000 - 6.0000i
>> Conjugate_of_Y=conj(Y)
Conjugate_of_Y =
-3.0000 + 3.0000i
>> W=5*cosd(30)+5*sind(30)*i
W=
4.3301 + 2.5000i
>> A=2.5*cosd(-20)+2.5*sind(-20)*i
A=
2.3492 - 0.8551i
>> r=3e+15
r=
3.0000e+15
>> Q=r*cosd(-73)+r*sind(-73)*i
Q=
8.7712e+14 - 2.8689e+15i
Experiment 07
Answer to the exercise 1:
a=
4
>> disp([s num2str(a)])
The sum of 1st row =4
b=
7
>> disp([t num2str(b)])
The sum of 2nd row =7
a=
0.9649 0.9572 0.1419
0.1576 0.4854 0.4218
0.9706 0.8003 0.9157
>> d=diag(a)
d=
0.9649
0.4854
0.9157
>> s='The Diagonal of This Matrix ='
s=
'The Diagonal of This Matrix ='
b=d'
b=
0.9649 0.4854 0.9157
>> disp([s num2str(b)])
The Diagonal of This Matrix =0.96489 0.48538 0.91574
y= double(x);
disp(y);
Output:
sultana_avg = mean([75,80,70]);
mimi_avg = mean([80,90,85]);
Name Degree
----------------------
Faria 80
Sultana 75
Mimi 85
lower(W)
Experiment 08
Answer to the exercise 1:
if y>=4*x*z;
S = sqrt(y^2-4*x*z);
else y<4*x*z;
S = inf;
end