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
%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
I need help in MATLAB. I'm working on a circuits lab report and I want to...
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 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 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 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);...
Can somebody help me with my matlab code? I am plotting the POWER SPECTRAL DENSITY OF Manchester, Polar, UNIPOLAR, and BIPOLAR. It wont run. The error I am getting is "incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform element wise multiplication, use '.*'. " clc; clear all; %Declaration of variables bandwidth = 1; total_bandwidth = 1/bandwidth; f = 0:.05*bandwidth:2*total_bandwidth; x=f*total_bandwidth; %Manchester Power...
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);...
Execute the function, using 11 as Non, and 8 as Noff. function fourier_example(Non,Noff) %this function demonstrates fourier analysis and synthesis for a simple %periodic rectangular wave of varying duty cycle. %Inputs: Non= integer number of seconds per period that the signal is on % Noff = integer number of seconds per period the signal is off t=-30:.001:30; %time scale Nharm = 20; %number of harmonics to calculate %construct a periodic square-wave with desired duty cycle x=zeros(size(t)); for k1=-Nharm:Nharm x =...
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)');
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 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,...