Question

I am using matlab and getting a "matrix dimensions error below" for line 22. Can someone...

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)')

Homework Answers

Answer #1

#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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Below are three different codes in Matlab, please copy those your matlab and answer the following...
Below are three different codes in Matlab, please copy those your matlab and answer the following questions: Thank you for your help!!!! 1.1 Baseband Signal a) Plot time versus baseband signal (m_sig). b) Plot freq versus baseband signal spectrum (M_fre). 1.2 Amplitude Modulation – Suppressed Carrier. a) Plot time versus the DSB-SC signal (s_dsb). b) Plot freq versus the DSB-SC signal spectrum (S_dsb). 1.3 Coherent Demodulation a) Plot freq versus the pre-filtered signal (S_dem). b) Plot freq versus the post-filtered...
Question : Design the low and high pass filter for the signal, x(t) = 10 sin...
Question : Design the low and high pass filter for the signal, x(t) = 10 sin (10 t) + 1 sin (1000 t) by MATLAB Is below answer right? at ?High pass , 5row shouldn't this change from sin(100*t) ? sin(1000*t) x = 10*sin(10*t) + 1*sin(100*t); ?   x = 10*sin(10*t) + 1*sin(1000*t); ??? ..................................................................................................................................................... ?Low pass clc; rng default Fs=2000; t=linspace(0,1,Fs); x=10*sin(10*t)+sin(1000*t)%given signal n=0.5*randn(size(t));%noise x1=x+n; fc=150; Wn=(2/Fs)*fc; b=fir1(20,Wn,'low',kaiser(21,3)); %fvtool(b,1,’Fs’,Fs) y=filter(b,1,x1); plot(t,x1,t,y) xlim([0 0.1]) xlabel('Time (s) ') ylabel('Amplitude') legend('Original Signal','Filtered Data')...
PLEASE USE MAT LAB ONLY. THANK YOU (a) Create and plot the signals listed below and...
PLEASE USE MAT LAB ONLY. THANK YOU (a) Create and plot the signals listed below and save your Matlab code in a script file. i) Cosine signal of frequency 100 Hz over the range [0,0.1] seconds and samples spaced 10^- 4 seconds apart with a phase of pi/2 and an amplitude of 1.   PLEASE USE MAT LAB ONLY. THANK YOU ii) A square wave that oscillates between 0 and 1 every five samples, plot 3 periods of the waveform. iii)...
Modify your Free Fall program below to plot the energy vs. time for a baseball dropped...
Modify your Free Fall program below to plot the energy vs. time for a baseball dropped from a height of 1000 feet until it hits the ground. Now add in the effects of air resistance into your program. This time, on the energy plot, you will plot four quantities: KE (Red line), PE (Green line), Energy lost due to air resistance (purple line), and total Energy (blue circles). Note, you must calculate the energy lost by using the definition of...