Why did the signal get delayed?

1 visualizzazione (ultimi 30 giorni)
세민
세민 il 21 Ott 2023
Commentato: Star Strider il 22 Ott 2023
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
Dyuman Joshi
Dyuman Joshi il 21 Ott 2023
How exactly is the signal 'pt' delayed?
세민
세민 il 22 Ott 2023
0.00025s delayed

Accedi per commentare.

Risposte (1)

Star Strider
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)
y0 = 6.1232e-17
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
세민
세민 il 22 Ott 2023
oh, thanks to your answer, I knew the expression 'delay' is wrong.
But how do I modify the code to make the signal like the picture I added to the question????
Star Strider
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.)
.

Accedi per commentare.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by