I am using matlab and getting a "matrix dimensions error below" for line 22. Can someone spot the error and try the code to fix the error.
%The beginning step is to generate a functionf(t) that consists
of the sum
%of the following components
% 25 Hz cosine function of magnitude 1
% 50 Hz sine function of magnitude 1
% 40 Hz square wave function of magnitude 1
clear; clc;
close all;
%sample rate is given at 2500 Hz and consists of 4 seconds of
points
samp=2500;
time=4;%seconds
n=time*samp+1;
t=0:1/samp:2;
freq=(-samp/2:samp/(n-1):samp/2);
f1=cos(2*pi*25*t);
f2=sin(2*pi*50*t);
f3=square(2*pi*40*t);
f=f1+f2+f3;
fmax=max(f);fmin=min(f);
f=(f-fmin)/(fmax-fmin)*4-2;
noise=(rand(1,(time*samp+1))-0.10)/2;%noise between -0.2 and
0.2;
f=f+noise; %noisy f
----------------------------------------------------------------------------------------******THis
is where I'm getting an error******
%fc given as 1000Hz
fc=cos(2*pi*1000*t);
phi1=1.2*(1+0.25*f).*fc;%DSB-LC of f with A=1.2 and m=0.25
phi2=1.2*(1+0.5*f).*fc;%DSB-LC of f with A=1.2 and m=0.5
phi3=1.2*(1+1*f).*fc;%DSB-LC of f with A=1.2 and m=0.5
%plot for 250/2500=0.1 seconds
%plot of f and phis for 0.1 seconds
subplot(2,2,1)
plot(t(1:250).f(1:250))
xlabel('Time(sec)');
legend('f(t)')
subplot(2,2,2)
plot(t(1:250),phi1(1:250))
xlabel('Time(sec)');
legend('phi1(t))')
subplot(2,2,3)
plot(t(1:250),phi2(1:250))
xlabel('Time(sec)');
legend('phi2(t))')
subplot(2,2,4)
plot(t(1:250),phi3(1:250))
xlabel('Time(sec)');
legend('phi3(t)')
#Note : error are mentioned in red
#New code:
function Matrix_Dimension
%The beginning step is to generate a functionf(t) that consists of
the sum
%of the following components
% 25 Hz cosine function of magnitude 1
% 50 Hz sine function of magnitude 1
% 40 Hz square wave function of magnitude 1
clear; clc;
close all;
%sample rate is given at 2500 Hz and consists of 4 seconds of
points
samp=2500;
time=4;%seconds
n=time*samp+1;
t=0:1/samp:4; % intially t was defined as
t=0:1/samp:2
freq=(-samp/2:samp/(n-1):samp/2);
f1=cos(2*pi*25*t);
f2=sin(2*pi*50*t);
f3=square(2*pi*40*t);
f=f1+f2+f3;
fmax=max(f);fmin=min(f);
f=(f-fmin)/(fmax-fmin)*4-2;
noise=(rand(1,(time*samp+1))-0.10)/2;%noise between -0.2 and
0.2;
sizeof(f)
sizeof(noise)
f=f+noise;# Initially
noise size is 80008 and size of f=40008 , after correction both
have size 80008
%noisy f
----------------------------------------------------------------------------------------******THis
is where I'm %getting an error******
%fc given as 1000Hz
fc=cos(2*pi*1000*t);
phi1=1.2*(1+0.25*f).*fc;%DSB-LC of f with A=1.2 and m=0.25
phi2=1.2*(1+0.5*f).*fc;%DSB-LC of f with A=1.2 and m=0.5
phi3=1.2*(1+1*f).*fc;%DSB-LC of f with A=1.2 and m=0.5
%plot for 250/2500=0.1 seconds
%plot of f and phis for 0.1 seconds
subplot(2,2,1)
plot(t(1:250),f(1:250)); % initially
it was 'plot(t(1:250).f(1:250))' there was dot '.'between
arguments %of plot instead of ','
comma
xlabel('Time(sec)');
legend('f(t)')
subplot(2,2,2)
plot(t(1:250),phi1(1:250))
xlabel('Time(sec)');
legend('phi1(t))')
subplot(2,2,3)
plot(t(1:250),phi2(1:250))
xlabel('Time(sec)');
legend('phi2(t))')
subplot(2,2,4)
plot(t(1:250),phi3(1:250))
xlabel('Time(sec)');
legend('phi3(t)')
end
#output of program:
Get Answers For Free
Most questions answered within 1 hours.