Why did the signal get delayed?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
D = 50;
A =1;
T = 1e-3;
tau = 0.5e-3;
R = 1e3;
C = tau/R;
f0 = 1/T;
t = 0 : T/100 : 10*T;
pt = zeros(size(t));
y = cos(2*pi*f0*t);
y0 = cos(2*pi*f0*tau/2);
ii1 = find(y<y0);
pt(ii1) = A;
plot(t, pt);

This is the signal i want
I want a signal that repeats every period of T=1ms, with 0 for 0~0.5ms, and 1 for 0.5ms~1ms.
3 Commenti
Risposte (1)
Star Strider
il 21 Ott 2023
I am not certain what you intend by ‘delayed’. You are plotting a cosine curve, and the ‘ii1’ value is defined as being true when the cosine curve is less that ‘y0’ (essentially zero). Since the cosine curve begins at 1, the ‘delay’ (such as it is), is the time for ‘y’ to reach ‘y0’ at which point ‘ii1’ satisfies the test.
Plotting them together demonstrates this —
D = 50;
A =1;
T = 1e-3;
tau = 0.5e-3;
R = 1e3;
C = tau/R;
f0 = 1/T;
t = 0 : T/100 : 10*T;
pt = zeros(size(t));
y = cos(2*pi*f0*t);
y0 = cos(2*pi*f0*tau/2)
ii1 = find(y<y0);
pt(ii1) = A;
figure
plot(t, pt, 'DisplayName','pt')
hold on
plot(t, y, 'DisplayName','y')
hold off
grid
legend('Location','best')
.
2 Commenti
Star Strider
il 22 Ott 2023
One option is the pulstran function. However if you want to do this yourself, choose a sine curve with a period of 1 ms, (a frequency of 1 kHz), with an appropriate sampling frequency (1 MHz here to avoid Nyquist problems), then threshold it —
L = 10; % Signal Length (s), Change As Needed
Fs = 1E+6; % Sampling Frequency (Hz)
t = linspace(0, L*Fs, L*Fs+1)/Fs; % Time Vector
s = sin(2*pi*t*1000); % Sine Signal
A = 1.0; % Square Wave Pulse Amplitude (Can Be Any Reasonable Value, Positive Or Negative)
sqwv = ((1-sign(s+eps))/2)*A; % Square Wave Pulse Train
figure
plot(t, s, 'DisplayName','Sine Signal')
hold on
plot(t, sqwv, 'LineWidth',2, 'DisplayName','Square Wave Pulse Train')
hold off
grid
Ax = gca;
Ax.XAxis.Exponent = 0;
axis([[0 2.75]*1E-3 -2 2])
xlabel('Time (s)')
ylabel('Signal Amplitude')
legend('Location','best')
To me, this bears a strong resemblance to the signal you illustrate. Creating it is straightforward using the sign function to threshold the sin curve. Adding eps to the sine curve avoids the initial zero value so that the sign result works efficiently. (The sin curve is plotted here only for reference. It is not necessary to plot it if you do not need it.)
.
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!