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); % plot FSK signal
%% b
a= abs('DSP');
b = dec2bin(a,8);
c = b- '0';
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
B = [c(1,:), c(2,:),c(3,:)];
X = [];
for i= 1:length(B)
if B(i)==1
X = [X,x1];
elseif B(i)==0
X = [X,x0];
end
end
T=[];
for i=0:length(B)-1
T=[T,tn+0.005*i];
end
figure(2)
plot(T,X)
Is it correct?
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); % plot FSK signal
%% b
a= abs('DSP');
b = dec2bin(a,8);
c = b- '0';
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
B = [c(1,:), c(2,:),c(3,:)];
X = [];
for i= 1:length(B)
if B(i)==1
X = [X,x1];
elseif B(i)==0
X = [X,x0];
end
end
T=[];
for i=0:length(B)-1
T=[T,tn+0.005*i];
end
figure(2)
plot(T,X)
Is it correct?
Yes, your code is correct. And the best thing is that you have commented your code so,it's a good practice to carry on.
matlab help, please my code is here: %% exercise2 %a Fs = 8000; % sampling frequency tn = 0:1/Fs:0.005; % here, bit dura...
Program from problem 1: (Using MATLAB)
% Sampling frequency and sampling period
fs = 10000;
ts = 1/fs;
% Number of samples, assume 1000 samples
l = 1000;
t = 0:1:l-1;
t = t.*ts; % Convert the sample index into time for generation and
plotting of signal
% Frequency and amplitude of the sensor
f1 = 110;
a1 = 1.0;
% Frequency and amplitude of the power grid noise
f2 = 60;
a2 = 0.7;
% Generating the sinusoidal waves...
Need help converting the following code from Matlab into Python: N=2048; fs=4.9; t=0:1/fs:(N-1)/fs; fs1=200; t1=0:1/fs1:(N-1)/fs1; x2=0.5+0.6366.*cos(2.*pi.*t1)+0.1273.*cos(10.*pi.*t1)-0.0909.*cos(14.*pi.*t1); x=0.5+0.6366.*cos(2.*pi.*t)+0.1273.*cos(10.*pi.*t)-0.0909.*cos(14.*pi.*t); X=fftshift(fft(x)); f=linspace(-fs/2,fs/2,N); plot(f,abs(X)./N); xlabel('f'); ylabel('|F(f)|'); title('magnitude spectrum of sampled signal'); x1=ifft(fftshift(X)); figure plot(t(1:100),x1(1:100)); xlabel('t'); ylabel('f(t)'); title('f(t) obtained by inverse transform'); figure plot(t1(1:1000),x2(1:1000)); xlabel('t'); ylabel('f(t)'); title('original f(t)');
Can you please help me answer Task 2.b?
Please show all work.
fs=44100; no_pts=8192;
t=([0:no_pts-1]')/fs;
y1=sin(2*pi*1000*t);
figure;
plot(t,y1);
xlabel('t (second)')
ylabel('y(t)')
axis([0,.004,-1.2,1.2]) % constrain axis so you can actually see
the wave
sound(y1,fs); % play sound using windows driver.
%%
% Check the frequency domain signal. fr is the frequency vector and
f1 is the magnitude of F{y1}.
fr=([0:no_pts-1]')/no_pts*fs; %in Hz
fr=fr(1:no_pts/2); % single-sided spectrum
f1=abs(fft(y1)); % compute fft
f1=f1(1:no_pts/2)/fs;
%%
% F is the continuous time Fourier. (See derivation...