Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
square wave

Subject: square wave

From: dwi

Date: 4 Dec, 2012 19:07:08

Message: 1 of 2

I have a square wave which I have scaled to be in the interval [0,1].I want to put the value 1 when I have a square pulse and zero otherwise (so as when summing the sequential aces I would have the duration of each the pulse). THen I want to plot the original wave and the one with the zeros and aces in the same graph. I did this:
data=sima
%scale
simafin=(sima-min(sima))/(max(sima)-min(sima));
plot(simafin);
simafin=round(simafin);
b(1:simafin(1)) = zeros(1,simafin(1));
for ii = 2:length(simafin)
  if mod(ii,2)==0
    b = [b ones(1,simafin(ii))];
  else
     b = [b zeros(1,simafin(ii))];
  end
end
hold on
plot (b,'m')

but when i tried to plot b, its pulses weren't in the same place as the pulses of simafin.Any ideas what I'm doing wrong?

Subject: square wave

From: dwi

Date: 5 Dec, 2012 15:33:08

Message: 2 of 2

"dwi" wrote in message <k9lhks$9ud$1@newscl01ah.mathworks.com>...
> I have a square wave which I have scaled to be in the interval [0,1].I want to put the value 1 when I have a square pulse and zero otherwise (so as when summing the sequential aces I would have the duration of each the pulse). THen I want to plot the original wave and the one with the zeros and aces in the same graph. I did this:
> data=sima
> %scale
> simafin=(sima-min(sima))/(max(sima)-min(sima));
> plot(simafin);
> simafin=round(simafin);
> b(1:simafin(1)) = zeros(1,simafin(1));
> for ii = 2:length(simafin)
> if mod(ii,2)==0
> b = [b ones(1,simafin(ii))];
> else
> b = [b zeros(1,simafin(ii))];
> end
> end
> hold on
> plot (b,'m')
>
> but when i tried to plot b, its pulses weren't in the same place as the pulses of simafin.Any ideas what I'm doing wrong?
Just a clarification:
My data aren't actually a square wave but it has noise, thus the round command

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us