|
I had the same issue and just figured it out. Here's the solution:
Assuming a fixed step solver...
1) Add your time and data vectors into a lookup table.
2) Feed the lookup table with an enabled subsystem (where the enable
signal is your "trigger").
3) On your Enable block, set "states when enabling:" to "reset" so
that each time the enable signal goes high, the waveform is replayed
from the beginning.
4) In the enabled subsystem,
- add a constant block that is set to you system's timestep
- feed the constant block into a discrete time integrator (set to
accumulator mode)
- feed the integrator block into the subsystem's output
The enabled subsystem outputs a signal equal to the time elapsed since
the last time the enabled signal went high.
--Shane
On Nov 4, 9:05 pm, Justin <enigma.dark....@gmail.com> wrote:
> On Nov 4, 3:02 pm, Idin Motedayen-Aval
>
>
>
> <run.signat...@MATLAB.for.email> wrote:
> > Justin wrote:
> > > We are using simulink in order to play a finite file. We converted an audio file into a sample and time array and are using the from workspace simulink block in order to upload the needed data. However, before we can see the data on a scope, the signal has already passed through the system, and therefore we cannot see anything but 0. What we want to do is to essentially trigger the sending of the signal whenever we so choose (i.e. a switch). However, whenever we use a switch the signal is sent in the background. Is there a way to permanently save the signal from workspace into the simulink model and then trigger it when we want it to send? We have already attempted to use an embedded matlab function in order to load the data from workspace but it gives an error about command duality.
>
> > Justin,
> > Three things come to my mind:
> > 1. Why don't you set the "From Workspace" block to "Cyclic repetition"
> > after the data runs out?
> > 2. If cyclic repetition is not an option, you can use an enabled
> > subsystem (i.e. put the source block inside an enabled subsystem, and
> > enable that subsystem when you need the data to be sent).
> > 3. If you have Signal Processing Toolbox, you can read audio files
> > directly using a "From Wave file" or "From multimedia file" blocks.
>
> > btw, Embedded MATLAB is probably complaining because you're using a
> > syntax like this:
> > load foo.mat
> > This is a command-line type syntax that is not allowed; you must use
> > function-style syntax for everything:
> > load('foo.mat')
> > And if you use load, remember to declare the "load" function as
> > eml.extrinsic since it's not supported natively in Embedded MATLAB.
>
> > HTH,
> > Idin
>
> > --
> > Idin Motedayen-Aval
> > The MathWorks, Inc.
> > zq=[4 2 5 -15 -1 -3 24 -57 45 -12 19 -12 15 -8 3 -7 8 -69 53 12 -2];
> > char(filter(1,[1,-1],[105 zq])), clear zq
>
> thanks for replying. I have tried all of your suggestions. However,
> the from .wav file block is not compatible with the mpc555 blockset
> that we are using (this will be placed on an embedded system).
> Additionally, the cyclic repetition is not an option since the signal
> needs to be triggered by an input (logical 1). The enabled system
> seemed promising, however, the signal still sends out even if it is
> not enabled ( once it is triggered, it stays at a zero output).
> However, when the trigger was left on and then the simulation was
> carried out, the audio signal played as usual, however we could not
> trigger it. We tried the embedded matlab function, but it will not
> allow us to output the values located in the loaded file it returns an
> error telling us that the output is not numeric. Is this a problem
> with syntax?
|