I have been attempting to evaluate Wolfram System Modeler (WSM) and it has not been going smoothly. It looks like some of the Modelica Models (combiTable1D for instance) supplied are not complete or not functional in WSM. I am working with Wolfram Support to get some clarification on that, but after days of trying I have been unable to get a simple output=input model working.
What I am trying to do as a first step is to just get an audio file into simulation and to port this straight through to an output to verify that it got in with reasonable accuracy. To do this I start with a very simple model:
model AudioProcessing
Modelica.Blocks.Interfaces.RealInput u=5;
Modelica.Blocks.Interfaces.RealOutput y;
equation
connect(u,y)
end AudioProcessing;
Here I have set the input to the constant 5 just to see if I can run the simulations without error and indeed this works fine.
In order to bring in the .WAV file I have tried many things, but the best results I get so far is to use WSMLink
and the WSMInputFunctions
option of WSMSimulate
to provide and interpolated version of the .WAV to the simulation. For instance:
Needs["WSMLink`"]
rawAudio = Import["C:\\Users\\vandel\\Desktop\\Mathematica\\Guitar_Sample.wav"]
samplePeriod = N[1/First[rawAudio][[-1]]];
sampleData = First[rawAudio][[1, 1]];
audioTimeSeries = Table[{n*samplePeriod, sampleData[[n + 1]]}, {n, 0, Length[sampleData] - 1}];
audiofunction = Interpolation[audioTimeSeries];
Plot[audiofunction[t], {t, 0, 10}, PlotRange -> All]
This plot looks fine and I can generate reasonable audio using the interpolation function.
Now I try to bring that into WSM as follows:
M = WSMSimulate[audioSignal, {0, 10}, WSMInputFunctions -> {"u" -> (audiofunction[#] &)}];
This runs fine but when I plot this as follows:
WSMPlot[M,"y", PlotRange -> All]
The resolution is so reduced that the sound can not be reproduced. The same takes place with the variable u
and when I use the returned interploation table to build a new signal with higher time resolution such as:
{outputVector} = M[{"u"}];
testPlot = Table[outputVector[t], {t, 0, 10, .00001}];
ListPlot[testPlot, PlotRange -> All]
The plot from this looks just like the earlier plot.
I have tried using different solver methods and high numbers of InterpolationPoints
and InterpolationOrder
to no avail.
Any insight would be appreciated and if there is a better way to get a real world signal sample into the application I'd be happy to look at that as well.