Discussion:
Converting the signal from Structure to Array form in Simulink
(too old to reply)
Serkan
2009-06-25 00:33:02 UTC
Permalink
Hello
I have been coping with a simple semester project for the uni :) in the simulink i need to convert a signal from Structure to Array form. only then i can get the mean value of the signal. but as a Structure i cant edit the signal at all. i put a workspace block and sent the signal to the base as an "Array" and then i was able to get the mean via "mean" command. is there any way doing this directly in the simulink as a block, converting the signal from structure to array? then i could use the block "Mean" directly in my model.
thank you for any comment in advance
serkan ?zt?rk
Phil Goddard
2009-06-25 14:50:02 UTC
Permalink
Simulink signals are not structures they are matrices so there is no conversion required.
(The conversion to a structure takes place when the data gets saved to MATLAB.)

What you most likely need to do is buffer your signal so that you are feeding a vector (rather than a scalar) into the mean block.

Phil.
Serkan
2009-06-25 16:44:02 UTC
Permalink
Thank you very much for the help but it doesnt work when i directly feed the Mean block with my signal. If you just put a Sine Wave source and Mean Block you may see what i mean. Mean Block doesnt make any effect on the signal at all. What i expect though is getting just zero, since the values of Sine Wave changes from +1 to -1 Amplitude.. My case is sure a bit different. I have a PWM signal, which is likely an angular form of a sin function. Amplitude varies +/-32Volt and mean value has to be 24Volt.. When i send this to the base as an array and get the mean with the Mean command i have the 24 but in simulink i cant do it somehow.. i tried everything with the Meanblock properties but still no solution. if you can help more i appreciate very much
serkan ozturk
Phil Goddard
2009-06-25 18:15:03 UTC
Permalink
If you feed the output of the sine wave block into the mean block you should get a sine wave back out again -- i.e. the block is doing as expected.

At each time step the output of the mean block will be the mean of the inputs to the block at that time step.
Since the output of the sine wave block is a single number at each time step, the input to the mean block will be a single number, and the output of it will also be that single number.

If you want the mean of a signal over a number of periods then you need to buffer the signal then feed that buffered signal into the mean block.

If you are using the mean block from the Signal Processing blockset then you need to look for the buffer block and insert it before the mean block.
You may also want to unbuffer the signal after the mean block to get it back to a scalar value.

Phil.
Serkan
2009-06-25 22:15:04 UTC
Permalink
Thank you again for the explanations. Sorry i thought you had meant with buffer the signal "keep the signal as it is" :)) well when you dont know such a block exists you figure out sth.else :)
if we stay on Sine Wave example, as you offered i put the Buffer block before the Mean Block and then i got an error " Continious sample times are not allowed". I changed in the Sine Wave source block properties Sine Type from Time Based to Sample Based.. played with the other properties and got rid of that error message but still Mean Block doesnt give me some scalar but what Sine Wave feeds it.. I added Unbuffer block after the Mean as well and nope :)
i dont want to bother too much but please can you explain some more. As you see i am not familiar with matlab..
Phil Goddard
2009-06-26 01:55:02 UTC
Permalink
You need to spend some time look at the Simulink doc to understand some fundamentals of how it works, and pressing the help button on each block to see how it specifically works.

Create a new model, and have
Sine Wave -> buffer -> mean -> unbuffer -> scope

Make only one change from the default values:
change the "Sample Time" parameter of the Sine block to be 2*pi/64.

When you run the model the scope should show zero, but why?
The sample time of the Sine has been set so that it has 64 samples per cycle of the sine wave.
The buffer block has a default length of 64 samples with no overlap, so it fits one complete sine wave in it.
The mean block takes each buffer (i.e. all 64 elements) and takes its mean, which will be zero for a complete cycle of a sine wave.
That gets unbuffered and displayed on the scope.

Now change the Sine's sample time to be 2*pi/128.
The buffer block still holds 64 samples at a time, but now 64 samples only represents half of a sine wave.
The mean block takes the mean, which gets unbuffered and displayed.
Nothing happens on the scope for the first 64 samples because that's the buffer first filling up, at which point the output jumps the the mean of the positive half of a sine wave which is a little over +0.5.
Then after another 64 samples the buffer contains the -ve part of the sine wave, which has it's mean taken and displayed, just less than -0.5.
The result will be a square wave.

Now play around with different sample times and with overlapping the buffer.
Depending on what you ask the blocks to do it is very possible to have a sine wave as the output of the mean of a series of samples from a sine wave.
Infact that's the basis of averaging filters.

Phil.
Serkan
2009-06-26 23:14:02 UTC
Permalink
:)) I am very very thankful. finally managed to get zero for the output from Sine.. now trying to apply this to my model. And you are right I am trying to do this without knowledge of Matlab..but you explained very well. thanks for your patience
serkan ozturk

Loading...