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.
its called a constant block. just set it to the peak
value of the sinusoid and you are done.
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.
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!
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