How to create, play an infinite length signal ?

1 view (last 30 days)
Hello guys, I need to create both sine and chirpwave signal that has infinite length in GUI. The signal will be generated, sampled and analyzed at the same time until i stop it. Generated signal will be played as wav file. This signal will transmit from output of the headphone to computer microphone input. I combined these cables. Signal sine and chirpwave will be generated separately on different GUI files. How can i do that ? I'm not an expert Matlab user and didnt find a proper way. Thanks for helps.

Accepted Answer

John D'Errico
John D'Errico on 30 Nov 2014
Um, you cannot create anything of infinite size. Your computer has finite size. Case closed.
You can create signals of FINITE size, that grow. Of course, you will be sorry when you create this big thing that is grown continuously, since MATLAB will dynamically reallocate memory to this object. Something that grows in size like that will take quadratically increasing time just to store, since each time MATLAB replaces the object, it must copy the entire object to a new place in memory.
There are ways to reduce the quadratic time penalty, by creating a cell array in advance to store segments of signal. Or you can simply not grow the signal at all, storing only the most recent part, essentially a moving window of information. But then your signal processing may be impacted. You may choose to not store the entire signal in memory at all if it will get large, but store it on disk, writing it out as it is generated.
You will want to think carefully about your task here.
  2 Comments
Mustafa
Mustafa on 30 Nov 2014
Thank you so much. I guess i'm mixed up with this terminologies. This appoach make my way harder. How about that, can i create a sine signal that doesn't change in time but keep it play until i stop ? The signal value will be replicated in time until i stop, is that possible ?
John D'Errico
John D'Errico on 30 Nov 2014
Edited: John D'Errico on 30 Nov 2014
This is not something I have any expertise in, so I hope others will offer their help.
It would seem the simple answer is to just play a signal, then play it again and again immediately after the previous one stops. Of course, there will probably be a finite time in between those iterations.
To do what you want, you might need to provide C code to do this, continuously driving the sound output until it is time to stop.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 30 Nov 2014
I think you'll have to make up some stretch of signal in advance and then call sound(). Though I don't see any capability to play the sounds synchronously, which is what you'd need if you wanted to play one sound only after the other one stops, otherwise if you start the second one before the first one is done, they'll both play simultaneously. You might need to call some low level API function or something.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!