How do I write this chua oscillator to an audio file in matlab?

In summary, the code in the link will take the output of a MATLAB model of the circuit and write a *.wav file.
  • #1
matlab audio
3
1
TL;DR Summary
writing chua oscillator to an audio file using matlab
hello i would like to ask how to write the solution of this matlab program to an audio file using the audio tool box or any other technique. thanks very much.
function chua_oscillator %This program is computed by S.Sabarathinam %Based on: Nonlinear Dynamics: Integrability, Chaos and Patterns,by M Lakshmanan, S Rajaseekar % to see the period doubling change the value of "r" clear all figure(1) r=1920.0; ga = -0.758d-03; gb = -0.409d-03; c1 = 10.0d-09; c2 = 100.0d-09; bind = 20.0d-03; a = r*ga; b = r*gb; alpha = c2/c1; beta=(c2*r*r)/bind; %time step and initial condition tspan = 0:0.01:500; x10 = 0.11; x20 = 0.2; x30 = -0.3; y0 = [x10; x20; x30]; [t,y] = ode45(@(t,x) f(t,x,a,b,alpha,beta),tspan,y0); x1=y(:,1); x2=y(:,2); x3=y(:,3); %plot the variable x and y plot(x1,x2) function dy = f(t,y,a,b,alpha,beta) x1 = y(1); x2 = y(2); x3 = y(3); hx=b*x1 + 0.5d0*(a-b)*(abs(x1+1.0)-abs(x1-1.0)); dx1=alpha*(x2-x1-hx); dx2=x1-x2+x3; dx3=-beta*x2; dy = [dx1; dx2; dx3];
https://www.mathworks.com/matlabcen...ads/submissions/44972/versions/1/download/zip
https://www.mathworks.com/help/audio/index.html?s_tid=srchtitle_audio_1
 
Last edited:
Physics news on Phys.org
  • #2
Welcome to PF. :smile:

I didn't click on the ZIP file, but are you asking how to take the output of a MATLAB model of the circuit and write a *.wav file that you can play? Or are you asking something else.

Does the MATLAB model of the circuit use the differential equations mentioned in this Wikipedia article?

https://en.wikipedia.org/wiki/Chua's_circuit
 
  • #3
thanks for your response. yes that is my question. i edited my original post to include the code.
 
  • #4
Have you worked with *.wav files before? I've only worked with them a little, to process digitized audio data that was acquired at 44.1kHz. I think at the least you will want to adjust your sample rate in your code to match one of the standard *.wav sample frequencies. Maybe the audio toolbox helps you to create the header for your *.wav file that your MATLAB code will be calculating the data for...

https://ccrma.stanford.edu/courses/422-winter-2014/projects/WaveFormat/
 
  • Like
Likes matlab audio
  • #5
thanks a lot for your help.
 
  • Like
Likes berkeman
  • #6
From https://www.mathworks.com/help/matlab/ref/audiowrite.html :
audiowrite(filename,y,Fs) writes a matrix of audio data, y, with sample rate Fs to a file called filename.​
For WAV files, there are no restrictions on the value of Fs that you write to the file, though a non-standard value might not be playable depending on what you use to play it.
 
  • Informative
Likes berkeman

1. How do I write a Chua oscillator to an audio file in MATLAB?

To write a Chua oscillator to an audio file in MATLAB, you will need to use the "audiowrite" function. This function takes in the audio data, sample rate, and file name as inputs and creates a WAV file of the oscillator's output.

2. Can I adjust the parameters of the Chua oscillator before writing it to an audio file in MATLAB?

Yes, you can adjust the parameters of the Chua oscillator before writing it to an audio file in MATLAB. You will need to modify the equations for the oscillator and then use the "audiowrite" function to generate a new audio file with the updated parameters.

3. How do I generate a plot of the Chua oscillator's output before writing it to an audio file in MATLAB?

To generate a plot of the Chua oscillator's output before writing it to an audio file in MATLAB, you will need to use the "plot" function. This function takes in the time vector and oscillator output as inputs and creates a visual representation of the waveform.

4. Is there a specific format I need to follow when writing a Chua oscillator to an audio file in MATLAB?

Yes, when writing a Chua oscillator to an audio file in MATLAB, you will need to follow the WAV file format. This format includes specific headers and data structures that are necessary for the audio file to be read and played correctly.

5. Can I save the Chua oscillator's output as a different file type in MATLAB?

Yes, you can save the Chua oscillator's output as a different file type in MATLAB. In addition to WAV files, MATLAB also supports other audio file formats such as MP3 and AIFF. You will need to use the appropriate function for the desired file format, such as "mp3write" or "aiffwrite".

Back
Top