% Matlab file convert_dec2bin.m
% Matlab function to convert decimal number to binary
% Input n - integer
% Output binary = binary representation of n
function [binary] = convert_dec2bin(n)
binary =''; % binary is a string
% loop continues till n!=0
while(n>0)
rem = mod(n,2); % find the modulus when n is divided by 2
binary = strcat(num2str(rem),binary);
n=fix(n/2); % get only the integer part
end
end
% End of convert_dec2bin.m
% Matlab file convert_dec2bin_script.m
% Matlab script calling convert_dec2bin function to convert decimal to
% binary
clc;
x = 24;
fprintf('Binary of %d is %s\n',x,convert_dec2bin(x));
% End of convert_dec2bin_script.m
Output:
% Matlab file convert_bin2dec.m
% Matlab function to convert binary number to decimal
% Input numStr - string containing binary representation of n
% Output decimal - decimal of numStr
function [decimal] = convert_bin2dec(numStr)
decimal =0;
% loop continues till we reach end of the string
for i = 1:length(numStr)
num = str2num(numStr(i)); % convert the element at i to number
decimal = decimal + num * power(2,length(numStr)-i);
end
end
% End of convert_bin2dec.m file
% Matlab file convert_bin2dec_script.m
% Matlab script calling convert_bin2dec function to convert binary to
% decimal
clc;
x = '101010';
fprintf('Decimal of %s is %d\n',x,convert_bin2dec(x));
% End of file convert_bin2dec_script.m
Output:
Need these 2 scripts written on matlab please Mtivity 4. Fun "ah Raary N.abn Free dei...
matlab help, please
my code is here:
%% exercise2
%a
Fs = 8000; % sampling frequency
tn = 0:1/Fs:0.005; % here, bit duration is 0.005s instead of
1/300s
phi1 = 0; phi0 = 0; % phases of the sinusoid
x1 = cos(2*pi*1650*tn + phi1); % tone for binary 1
x0 = cos(2*pi*1850*tn + phi0); % tone for binary 0
xx = [x1, x0]; % FSK signal for ¡°1,0¡±
tt = [tn, tn + 0.005]; % time
figure(1)
plot(tt, xx); %...