Plot rectangular square wave

13 visualizaciones (últimos 30 días)
J B
J B el 22 de Dic. de 2017
Comentada: John BG el 4 de En. de 2018
I have a matlab code which generates a PWM waveform (basically a square wave) which I print into a pdf file. I want to use this PWM waveform in an illustration and especially I want to be able to heavily zoom into this waveform and maintain its "steep edges". The problem is that if I enlarge the signal, the edges are not strictly vertical anymore and the waveform becomes more trapeziodal (see attached picture). I require an ideal square wave.
What I tried is to increase the number of datapoints. I generate the figure by plotting the PWM waveform with the "plot" command and than print it into a pdf. However, even if I increase the number of datapoints the problem remains. What is really confusing is, that the size of the pdf file sometimes reduces in size, even if I use ten times the amount of datapoints. The code I use is (simplfied version):
t = 0:dt:Tend-dt;
PWM = vector with set of data, each point can either be 0 or 1, nothing else
plot(t,PWM);
print(gcf, '-dpdf', [outputname,'.pdf']);
I use a dt of 1e-9, Tend is 1.2e-3, so I end up with 1.2e6 datapoints.
Does matlab use some kind of compression before saving waveforms into a pdf? What would be a proper solution for my problem?
Edit: Forgot to attach the figure
  1 comentario
John BG
John BG el 4 de En. de 2018
Hi J B
PWM is widely used in communications and motor driving.
In these applications, despite the data may really run as you mention, just 0 or 1 values, at a certain point, the diverse requirements of EMC standards, avoidance of cross talk among physically close lines, avoiding requesting the generation of too high currents that may unnecessarily drain battery current, the soft clipping of voltage and current by deliberately applying certain slope on both voltage and current is a common practice.
TTL standards define pulse trains not with sharp shoulders but with slopes.
Bear in mind that OAs OTAs that most of times have to be cheap to allow cheap production costs.
Cheap operational amplifiers means not so high slew rate , therefore when you really apply a 01 or 10 step, the OA will really follow a ramp, and if the right support components are chosen there should be no 'over reaction'.
So, the 'data' you supply actually shows such slopes, there's nothing wrong with them, you cannot expect to have perfectly sharp transitions when you extract data from electronic board with real components pumping currents.

Iniciar sesión para comentar.

Respuestas (1)

Stephen23
Stephen23 el 22 de Dic. de 2017
Editada: Stephen23 el 22 de Dic. de 2017
If you want a "perfect" square wave (which is of course physically impossible), then you could simply plot two points at each discontinuity. Here I assumed that each PWM value continues until the next PWM value occurs: note that this makes the relationship between the time and PWM values ambiguous (hence I do not claim that this is a correct interpretation of that data).
PWM = [1,0,0,1,1,1,0,1,1,0,0];
t_V = 1:numel(PWM);
idx = diff(PWM)~=0;
X = repmat(t_V([true,idx]),2,1)
Y = repmat(PWM([true,idx]),2,1)
X = X(2:end);
Y = Y(1:end-1);
plot(X,Y)
ylim([-0.1,1.1])

Categorías

Más información sobre Periodic Waveform Generation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by