Offer to write "spectrogram" function for signal package

Hi Octave Developers,

I noticed when using Octave (6.1.0) with the Signal package (1.4.1) that the spectrogram function is not supported.

As a long time MATLAB user and signal processing engineer I have developed a spectrogram function based on the standard fft function (thereby not needing the MATLAB Signal Processing Toolbox).

Are you interested in my help adding a spectrogram function to the Octave SIgnal Package? If yes, please let me know; this would be my first code contribution and I would appreciate some help/guidance for how to proceed.

Regards,

Karl A Sweitzer
Alumni of: University of Southampton, UK; Syracuse University, NY, USA; Virginia Tech, VA, USA; Clarkson College, NY, USA
Former Adjunct Professor: Rochester Institute of Technology, NY, USA

Thanks very much for your offer.
Looks like a very useful contribution to me; I’d say: please go ahead.

Some hints:

Contributions for new (= previously unimplemented) functions and new functionality of existing functions are welcome at the patch tracker,
https://savannah.gnu.org/patch/index.php?group=octave
(BTW seems to be down ATM, Sat. Feb 21:00 CET)

We have a coding style guide,
https://wiki.octave.org/Octave_style_guide

and BIST tests are very much appreciated, just look in some of Octave’s .m-file functions for examples.

Thanks for the prompt reply.

The patch tracker still looks to be down Sun Feb 7 @ 07:30 EST

I have looked at a similar Octave Signal function pwelch and see that much of the code is devoted to MATLAB version compatibility and adherence to basic MATLAB functions.

Questions:
I don’t have access to past versions of MATLAB to be able to understand how the spectrogram function may have changed over time. How important is it for Octave Code to follow multiple versions of MATLAB?

I see that the pwelch function reproduces some of the functions found in the Octave Signal package using basic math. For example, the hanning function is in the Signal package, but the pwelch function reproduces it inside its main function instead of calling the package function. Are there style recommendations for this technique?

The Octave Signal pwelch has additional arguments not found in the MATLAB 2020b version and the input argument for Signal pwelch can be two vectors (x and x, y) whilst MATLAB pwelch allows the main input x to be a matrix. What is the guidance for Octave function strict compatibility with MATLAB? Is it an option to make an “improved” Octave function with a different name then have the MATLAB compatible function call the Octave function?

Is it possible to collaborate with others to build an Octave function? My software skills are not great (e.g. handling multiple variable arguments); can someone else help with argument handling code whilst I contribute to the signal processing code?

Are these sorts of questions best kept to the patch tracker?

Regards, Karl S

The patch tracker still looks to be down Sun Feb 7 @ 07:30 EST

Patch tracker was up again this evening. Savannah sometimes has its quirks :slight_smile: (but not very often)

How important is it for Octave Code to follow multiple
versions of MATLAB?

I’d say just the latest releases, seems most practical to me. However I think the package maintainer’s opinion weighs in more than mine :slight_smile: Probably best discussed in the patch tracker.
It is important to support the oldest Octave version the signal processing package supports.

<snip> … reproduces it inside its main function instead of
calling the package function. Are there style recommendations
for this technique?

Hmm, remarkable. But maybe it was done for performance, to circumvent overhead in the external hanning function? I have no idea.
In general I’m all in favor of eliminating duplicate code, even if (in this case) e.g. the existing hanning function would need to be adapted to mimic what the subfunction in pwelch does; if at all needed.
But again, in this case, I just don’t know.

What is the guidance for Octave function strict compatibility
with MATLAB? Is it an option to make an “improved” Octave function with
a different name then have the MATLAB compatible function call the
Octave function?

No need for other function names or wrapper functions. Octave should be able to run existing Matlab code, but not necessarily the other way round.
As to the coding process, it’s best to start with something simple but reliable and then gradually improve / extend the code step by step. Full Matlab compatibility in the sense of complete functionality in one fell swoop is often too ambitious.
spectrogram looks like a complex beast so this advice applies especially here I think :slight_smile:

… collaborate with others … can someone else help with argument handling code …

Sure, TTBOMK that’s the way it usually works here, more or less.
Again, we are all volunteers each with different interests and skills (and available time), so it’ll depend on collaborators at hand. Please don’t be alarmed if the project stalls a bit now and then.

Are these sorts of questions best kept to the patch tracker?

This general discussion looks to be “at home” here, yes.

I’d say come up with a basic but functional skeleton function in the patch tracker that at least does one or two things properly and from there “we” can help you develop & finish it.

Hint: glance through some patch tracker reports to get a taste of what the process looks like (no two patch process submissions are the same)

I will second all of Philip’s advice.

For this particular case, you might reach out to @mtmiller who I believe maintains the signal package. Since this is going in to a package, rather than core Octave, it is the package maintainer who has the final word about what is accepted.

I can help with programming i’m EE and know both C & Octave , I dont know about the O6.1v ( i run 5.2. for a while more, usualy i wait 6months to update) , but Function Reference: specgram

looks to me pretty simillar to matlab’s function. The point is exact compatibility? I’d say compatibity on the visual (ploting part) is tougher (maybe not even needed?) than the signal processing per se. no?
Jo

Thanks for the replies. As Jo points out, the signal package does have a version of the legacy specgram function which has been replaced in MATLAB by the spectrogram function. I also realized that the ltfat package also has a related sgram function. I will start a patch to recommend the updated spectrogram function at GNU Octave - Patches: Browse Items [Savannah] in the near future.

Karl