0

I am using the audioread(filename,y,Fs) function of Matlab and it converts an audio file to a matrix. I want to know how is each value of that matrix generated. Is it possible to produce a specific sound like the sound of a guitar by giving your own values to the matrix and then sounding it using the sound() function?

Jordan
  • 713
  • 15
  • 30
  • "audioread (...) reads an audio file (...) returning the sampled data" - i.e. you get a sample for every sampling interval (the reciprocal of the sampling rate or frequency). Of course you can also generate your own sound signal, e.g. by adding up different sine/cosine waves (have a look at Fourier series/ transform). [This](http://dsp.stackexchange.com/questions/28803/how-to-create-a-guitar-waveform-using-arduino-dac) _might_ be related. – Matthias W. Feb 11 '16 at 11:00

1 Answers1

3

1) how is each value of that matrix generated
The matrix will have as many columns as there are channels (1 channel = mono = 1 column ; 2 channels = stereo = 2 columns). As an additional input you can specify 'dataType': if 'dataType' is 'native' Matlab will import the same values used for compression and you can use the audioinfo() function to know a priori such values. If 'dataType' is not specified or 'double' (default) these values are normalized in range [-1;+1].

2) Is it possible to produce a specific sound
Sure you can. Although it might take you quite a while to generate complex sounds like guitars. But can easily generate a sinusoidal tone at a given frequency and play it. Of course pay attention to the sinusoide frequency and the sampling frequency for your audio file.
A quick demo:

fs = 16000;            % sampling frequency in Hz
T = 5;                 % 5 seconds duration

t = 0:(1/fs):T;
f = 440;               % tone frequency (A4 note)
a = 0.5;               % amplitude (volume)
y = a*sin(2*pi*f*t);   % tone matrix
sound(y, fs);          % rock it! 
AlessioX
  • 3,167
  • 6
  • 24
  • 40
  • Actually I want to know how to calculate a specific matrix of values (like the one generated by audioread function) in order to produce a specific sound. @Alessiox – Jordan Feb 11 '16 at 12:30
  • In this demo the matrix `y` will contain a sound which is a simple sound (440Hz sinusoidal tune). That's when the creativity kicks in: you can start with a sinusoidal tune and then process such tunes with filters (lowpass, highpass or more complex structures). You can write your very own processing chain (pretty much like a stompbox for a guitarist) and feed `y` to this chain. Also using `audiowrite()` you can save your audio file and then re-import it using `audioread()` – AlessioX Feb 11 '16 at 12:33
  • So there is no actual formula sort of thing for this! I have to go for creativity instead! – Jordan Feb 11 '16 at 13:16
  • Indeed. Let's say you want to reproduce a certain guitarist sound, there's no such formula that automatically codes his sound into a matrix. That's simply impossibile. You might want to start with several notes/tones and play around with them using any DSP/technique you like and see what can you get from that. Matlab has a fantastic signal processing toolbox, you might want to refer to that for further documentation. – AlessioX Feb 11 '16 at 13:19
  • I am focusing on removing noise/distortion from a music file. That is why i was interested in knowing the procedure by which all these values of matrix are formed. If i get to know it, i can define the noise in the music on the basis of these values and can remove it. This was the actual concern! – Jordan Feb 18 '16 at 15:01