Question

I need help in MATLAB. I'm working on a circuits lab report and I want to...

I need help in MATLAB. I'm working on a circuits lab report and I want to plot the derivative of an input signal. The circuit is a differentiator OpAmp. It is receiving a triangle wave as an input and should output a square wave. (I've included my existing code.)

The output formula is:

Vout = -(Rf)*C*(dVin/dt) Where Rf is feedback resistance: Rf = 1*10^6; and C = 1*10^-6.

EXISTING CODE:

%% This section is copied, and then modified from another problem for use as the input.

%%Does not need to be changed.

clc

clear all

close all

R1 = 1000;

C1 = (1*10^-3);

t = linspace(0,20);

In1 = square(t);

f=@(t) [2*[(-1/(R1*C1))*(integral(@(t) square(t),0,t))]/(3)]+1;

for i=1:numel(t)

Vo1(i) = f(t(i));

end

%% Setting up new circuit values.

Rf = 1*10^6;

C2 = 1*10^-6;

%% Now I need to use the outut of the modified previous problem as input.

% Vout = -(R_feedback)*C*[d(Vin)/dt] *Again Vin here, is Vo1 from

% the previous problem.*

%

%% I originally thought this was where my mistake was, however I believe its actually in the subplot.

% My answers for Vo2 in the array are oscillating the way a square wave does, but it doesn't plot properly.

Vo2 = -Rf*C2*diff(Vo1)

%% Plotting outputs.

subplot(2,1,1)

plot(t/pi,Vo1,'r.-')

title('Input Voltage')

xlabel('t')

ylabel('V(t)')

xlim([0 5])

ylim([-1.5, 1.5])

grid on

subplot(2,1,2)

plot(t/pi,Vo2,'g.-')

title('Inverted Output Voltage')

xlabel('t')

ylabel('V(t)')

xlim([0 5])

grid on

0 0
Add a comment Improve this question Transcribed image text
Answer #1

%the diff function returns a vector of length 1 less than the original , since it calculates the difference. Thats why it gave error because you tried plotting it against the same length t vector. I skipped the last t value, so now it plots.

%% This section is copied, and then modified from another problem for use as the input.

%%Does not need to be changed.

clc

clear all

close all

R1 = 1000;

C1 = (1*10^-3);

t = linspace(0,20);

In1 = square(t);

f=@(t) [2*[(-1/(R1*C1))*(integral(@(t) square(t),0,t))]/(3)]+1;

for i=1:numel(t)

Vo1(i) = f(t(i));

end

%% Setting up new circuit values.

Rf = 1*10^6;

C2 = 1*10^-6;

%% Now I need to use the outut of the modified previous problem as input.

% Vout = -(R_feedback)*C*[d(Vin)/dt] *Again Vin here, is Vo1 from

% the previous problem.*

%

%% I originally thought this was where my mistake was, however I believe its actually in the subplot.

% My answers for Vo2 in the array are oscillating the way a square wave does, but it doesn't plot properly.

Vo2 = -Rf*C2*diff(Vo1)

%% Plotting outputs.

subplot(2,1,1)

plot(t/pi,Vo1,'r.-')

title('Input Voltage')

xlabel('t')

ylabel('V(t)')

xlim([0 5])

ylim([-1.5, 1.5])

grid on

subplot(2,1,2)

plot(t(1:end-1)/pi,Vo2,'g.-')%change made, plotting against t with last value unused

title('Inverted Output Voltage')

xlabel('t')

ylabel('V(t)')

xlim([0 5])

grid on


Add a comment
Know the answer?
Add Answer to:
I need help in MATLAB. I'm working on a circuits lab report and I want to...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Reproduce Figures 9.2b and 9.2c on MATLAB, assuming that the square wave (Figure 9.2b) is a...

    Reproduce Figures 9.2b and 9.2c on MATLAB, assuming that the square wave (Figure 9.2b) is a periodic symmetric square wave of normalized amplitude (A=1). Each student group should decide the power spectral density level of the channel noise. Compute the Fourier transform of the periodic square wave. clear all close all %%%% T=12*pi; %number of period x=linspace(0,T); t=x/pi y0=square(x); %square wave signal y0ft=fft(y0); %calculating Fourier Transformof signal y0fts=fftshift(y0ft); y0ftFinal=abs(y0ft); AWGN= rand(size(x)); %Calculating whit noise Att=(1/3); nSig= Att*AWGN; y=y0+nSig; %Square wave...

  • I wrote a Matlab program for the figure below. When I plot the waves, they look...

    I wrote a Matlab program for the figure below. When I plot the waves, they look the same. Why do the two waves frequencies look same and How do I avoid it? (I really do need this part of the question answered.) N = 200; % Total number of time domain samples in simulation. Fs = 100 ;% sampling frequency. F1 = 10; % frequency of wave - 1. F2 = 90; % frequency of wave - 2. phi =...

  • Need help with this simple MATLAB code. I'm trying to plot a new set of Y...

    Need help with this simple MATLAB code. I'm trying to plot a new set of Y values from input X values. I get an error that says: "not enough input arguments." clear all clc close all Q = 3.44E+18; D = 1.51E-17; t = 7200; x = [1E-6 2E-6 2.5E-6 3E-6 4.32E-6]; y = Q/sqrt((pi*D*t))*exp^(-(x)^2/(4*D*t)) plot(x,y, '*r') xlabel('Depth'), ylabel('Concentration')

  • please help me with this MATLAB CODE and explain to me what each line does and...

    please help me with this MATLAB CODE and explain to me what each line does and what is used for? leave your comments as words, not as pictures. ..................................................................................................................................................................... clear all; close all; % For a script file, you better start with clear all and close all                        % However, for a fucntion, you better NOT to start                        % with them %% End of cell mode example %% Plot function t = 0:0.1:5; x1 = sin(2*5*t); x2 = cos(3*7*t);...

  • MATLAB code starts here --------- clear T0=2; w0=2*pi/T0; f0=1/T0; Tmax=4; Nmax=15; %--- i=1; for t=-Tmax: .01:Tmax...

    MATLAB code starts here --------- clear T0=2; w0=2*pi/T0; f0=1/T0; Tmax=4; Nmax=15; %--- i=1; for t=-Tmax: .01:Tmax T(i)=t; if t>=(T0/2) while (t>T0/2) t=t-T0; end elseif t<=-(T0/2) while (t<=-T0/2) t=t+T0; end end if abs(t)<=(T0/4) y(i)=1; else y(i)=0; end i=i+1; end plot(T,y),grid, xlabel('Time (sec)'); title('y(t) square wave'); shg disp('Hit return..'); pause %--- a0=1/2; F(1)=0; %dc freq C(1)=a0; for n=1:Nmax a(n)=(2/(n*pi))*sin((n*pi)/2); b(n)=0; C(n+1)=sqrt(a(n)^2+b(n)^2); F(n+1)=n*f0; end stem(F,abs,(C)), grid, title(['Line Spectrum: Harmonics = ' num2str(Nmax)]); xlabel('Freq(Hz)'), ylabel('Cn'), shg disp('Hit return...'); pause %--- yest=a0*ones(1,length(T)); for n=1:Nmax yest=yest+a(n)*cos(2*n*pi*T/T0)+b(n)*sin(2*n*pi*T/T0);...

  • I'm trying to solve this differential equations by using matlab. But I don't know the reason why I can't ge...

    I'm trying to solve this differential equations by using matlab. But I don't know the reason why I can't get the solutions. I've attached matlab code and few differential equation. Please find a the way to solve this problem. second oder ode2.m x+ function, second-oder-ode2 t-0:0.001:30 initial-x = 0; initial-dxdt = 0: lt.影=ode45( @rhs, t, [initial.x initial.dxdt ] ); plot(t.(:,1l): xlabel( t); ylabel(x): 申 function dxdt=rhs( t, x) dxdt-1 =x(2); dxdt-2 (-50 x(2)+61.25+((1-cos(4 pi 10 t))/2) (47380 x(1)-3-7428 x(1) 2...

  • I'm trying to solve this problem by using matlab. But I don't know reason why I can't get the solutions. I w...

    I'm trying to solve this problem by using matlab. But I don't know reason why I can't get the solutions. I wanna get a plot of this differential equation. Please find a way how to solve this problem. May there're errors in the code. Please check it.    second-oder-ode2.m x 曱function, second-oder-ode2 t=0:0.001 :30; initial-× = 0; in i t i al-dxdt 0; lt,影=ode45( @rhs, t. [initial.x initial-dxdt ] ); plot( (:, 1) ) ; xlabel( 't); ylabel(): function dxdt=rhs( t,...

  • Hello, i have this matlab code where i have to track a red ball from and...

    Hello, i have this matlab code where i have to track a red ball from and uploaded video, and plot its direction in x-y direction My Question is how can i add x vs time plot and y vs time plot in this code. Thank you if exist('V','var') delete(V); end clear;clc; V=VideoReader('video.mp4'); figure(1); x=[];y=[]; i=1; while hasFrame(V) J=readFrame(V); figure(1);imshow(J);title(['Frame No. ',num2str(i)]); if (i>=28 && i<=132) bw=J(:,:,1)>200 & J(:,:,2)<80 & J(:,:,3)<80; bw=imfill(bw,'holes'); A=regionprops(bw,'Centroid'); x(end+1)=A.Centroid(1); y(end+1)=A.Centroid(2); hold on; plot(x,y,'*k');hold off; end i=i+1;...

  • Project in matlab. I have the correct ak value but not the correct ao value. My code is attached ...

    Project in matlab. I have the correct ak value but not the correct ao value. My code is attached below also 2. Determine and plot the magnitude and phase spectrum of the Fourier series coefficients a, that is, plot ja, I as a function of discrete frequencies Jok and La, as a function of discrete frequencies fok 03 025 蓋0.2 0.15 0.1 o o5 ·10-8-6 4610 phase -2 -2 8- t= 0: .01:4; 9- to = 4; 10- fo =1/4;...

  • Hi I need help understanding this matlab code. Can you add comments or at least state what the lines in this code are doing. Thanks! close all; clear all;clc; t=1:0.025:5; desired=5*sin(2*3.*t); noi...

    Hi I need help understanding this matlab code. Can you add comments or at least state what the lines in this code are doing. Thanks! close all; clear all;clc; t=1:0.025:5; desired=5*sin(2*3.*t); noise=5*sin(2*50*3.*t); refer=5*sin(2*50*3.*t+ 3/20); primary=desired+noise; subplot(4,1,1); plot(t,desired); ylabel('desired'); subplot(4,1,2); plot(t,refer); ylabel('refer'); subplot(4,1,3); plot(t,primary); ylabel('primary'); order=2; mu=0.005; n=length(primary) delayed=zeros(1,order); adap=zeros(1,order); cancelled=zeros(1,n); for k=1:n, delayed(1)=refer(k); y=delayed*adap'; cancelled(k)=primary(k)-y; adap = adap + 2*mu*cancelled(k) .* delayed; delayed(2:order)=delayed(1:order-1); end subplot(4,1,4); plot(t,cancelled); ylabel('cancelled');

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT