Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Matlab sinusoidal peak to peak detection

586 views
Skip to first unread message

rafiq khan

unread,
Mar 5, 2008, 1:29:02 AM3/5/08
to
Good day everyone. I'm rather new with MATLAB.

I'm currently using Simulink and would like to create a DC
signal from a sinusoidal signal. Tried using various blocks
but was unable to get it working.

Below are some links to pictures that may help explain what
I really need.

Pic 1: Input (sinusoidal wave)
http://i23.photobucket.com/albums/b395/rafiqos/sinewave.jpg

Pic 2: Peak detection
http://i23.photobucket.com/albums/b395/rafiqos/sinewave2.jpg

Pic 3: DC output (marked red)
http://i23.photobucket.com/albums/b395/rafiqos/sinewave3.jpg

The output should be a real-time continuous DC signal.

Thank you very much for your time.

David

unread,
Mar 5, 2008, 5:49:02 AM3/5/08
to
"rafiq khan" <tot...@hotmail.com> wrote in message
<fqleje$t38$1...@fred.mathworks.com>...

its called a constant block. just set it to the peak
value of the sinusoid and you are done.

rafiq khan

unread,
Mar 5, 2008, 8:27:03 PM3/5/08
to
"David " <da...@bigcompany.com> wrote in message
<fqltqu$fnn$1...@fred.mathworks.com>...


My peak value is not a constant. It will change with time in
response to the larger system's feedback.

I need to create an M-File that will extract the peaks of
the sinusoidal wave, create a DC line from the peaks, and
finally output the DC value for the sine wave.

Thank you for helping me out.

rafiq khan

unread,
Mar 5, 2008, 8:29:03 PM3/5/08
to
"David " <da...@bigcompany.com> wrote in message
<fqltqu$fnn$1...@fred.mathworks.com>...

Steve Amphlett

unread,
Mar 6, 2008, 6:20:18 AM3/6/08
to
"rafiq khan" <tot...@hotmail.com> wrote in message
<fqnhcv$evb$1...@fred.mathworks.com>...

I don't think the problem in the way you've described it
has a simple solution. What value do you want between
peaks? How can you tell a new peak has "peaked"? I guess
if you know the timing of each peak a priori, you could do
some kind of sample and hold strategy.

OTOH, you could implent a hilbert transformer. Don't ask
me how though!

rafiq khan

unread,
Mar 6, 2008, 8:44:02 PM3/6/08
to
"Steve Amphlett" <Firstname...@Where-I-Work.com> wrote
in message <fqok1i$ou4$1...@fred.mathworks.com>...


Spent about 5 hours yesterday on this. A friend of mine who
really has lots of experience working with Matlab helped me
out. Full credits to you Loga! We used a block in Simulink
called 'From Workspace'. This block imports data from an
M.file into the Simulink workspace. An M.file was later
created to list out the arrays from the Sinusoidal input and
perform calculations (comparison of slopes) to determine and
output points of the peaks into a DC format.

It's almost working now, except for the fact that it's not a
square wave, refer to Pic 3. Still trying to tweak and get a
perfect square wave output.

Pic 1 (sinewave with varying peaks) :
http://i23.photobucket.com/albums/b395/rafiqos/sine2.jpg

Pic 2 (peaks detected and DC output plotted) :
http://i23.photobucket.com/albums/b395/rafiqos/almostdc.jpg

Pic 3 (what i want - sorry for the crappy MSpaint job!)
http://i23.photobucket.com/albums/b395/rafiqos/whatiwant.jpg

Pic 4 (layout of the Simulink blocks used) :
http://i23.photobucket.com/albums/b395/rafiqos/layout.jpg

Next is the M.file codes. This is where I hope to get some
help to readjust my outputs to produce a perfect square wave
output!

tf=20;
dt=1;
q=0;
value=0;
valuearray=[value];

answer=0;
answerarray=[answer];

slope=0;
slopearray=[slope];


final.time=0;
final.signals.values=0;
final.signals.dimensions=1;
final.signals.label='';
final.signals.title='';
final.signals.plotStyle=0;
assignin('base','final',final);


for t=dt:dt:tf

[t,x,y]=sim('sine',[0 t]);
out1=[t,y];
assignin('base','y',out1);

value=out1(q+2,2);
valuei=out1(q+2,2);
valueprevious=out1(q+1,2);


assignin('base','value',value);

valuearray=[valuearray value];


assignin('base','valuearray',valuearray);

slope = valuei - valueprevious;
slopearray=[slopearray slope];

slopei=slopearray(1,q+2);
slopeprevious=slopearray(1,q+1);

if (slopei<0) && (slopeprevious>0)
answer=valueprevious;

end


answerarray=[answerarray answer];
assignin('base','answerarray',answerarray);


final.time=t;
final.signals.values=answerarray.';
final.signals.dimensions=1;
final.signals.label='';
final.signals.title='';
final.signals.plotStyle=0;
assignin('base','final',final);


q=q+1;
end

elmehd...@gmail.com

unread,
Mar 26, 2018, 6:14:40 AM3/26/18
to
Le mercredi 5 mars 2008 06:29:02 UTC, rafiq khan a écrit :
> Good day everyone. I'm rather new with MATLAB.
>
> I'm currently using Simulink and would like to create a DC
> signal from a sinusoidal signal. Tried using various blocks
> but was unable to get it working.
>
> Below are some links to pictures that may help explain what
> I really need.
>
> Pic 1: Input (sinusoidal wave)
> http://i23.photobucket.com/albums/b395/rafiqos/sinewave.jpg
> Hello,
i have a problem with my simulink project, i have a sinusoidal signal in the input its amplitude changes with time, i need to detect the peaks every period, how can i do that ?
0 new messages