# Generating a sound that goes up and down in frequency - based on a vector of numbers

1 visualización (últimos 30 días)
Harriet Dempsey-Jones el 4 de Mzo. de 2019
Respondida: Greg Dionne el 7 de Mzo. de 2019
Dear all,
I am a psychologist with no maths/ programming background in a bit of a bind - any help would be greatly appreciated.
I have a vector of data from a force sensor - someone picks up an object and the sensor reads pressure on the object exerted by the finger. An example is below
I want to make a sound that represents the changes in force applied to the sensor. I was thinking, something that increased in frequency as force went up, and then decreased as force went down.
So far I have tried a few things and managed to get a sound that appears to increase as force *changes* i.e. steep slopes correspond with higher frequencies (see below). But this is not really what I wanted. For the force example I pasted above, I wanted the frequency to go up as the force ramped up, and stay up - fluctuating with the dips and increases. Sorry if that is not clear.
This was generated with:
y_r = sin(2*pi/15000.*ls_i.^2);
Where ls_i is the force vector
I was working off an example that does this:
tt = [linspace(0,9.5,10000) linspace(10,0,10000)];
y_r = sin(2*pi/10.*tt.^2);
Does anyone have any suggestions of what I might try?
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Greg Dionne el 4 de Mzo. de 2019
Editada: Greg Dionne el 4 de Mzo. de 2019
Do you have the Signal Processing Toolbox?
If so, I think you can try to get VCO to work for you:
You can always try making the frequency proportional to the log of your signal if you need other ideas for how it should sound.
If you need more datapoints between your samples, you can use RESAMPLE:
Hope this helps!
-Greg

Iniciar sesión para comentar.

Harriet Dempsey-Jones el 7 de Mzo. de 2019
Hi Greg,
That is amazing! So simple, works like a treat!
All I had to do was input my vector (vrescaled) as below:
y = vco(vrescaled,[0.1 0.4]*fs,fs);
And it worked :)
I'm not sure I am quite understanding the spectrogram properly - but it looks like its on the side. Should I be plotting it in a special way? I looked at the help spectrogram page but I can't make head-nor-tail of most of it... (left is my force reading)
spectrogram(y)
Thank you so much once again Greg! Not sure how/ if we are supposed to select answers as 'solved' or like them on this forum??
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Greg Dionne el 7 de Mzo. de 2019
Well, the main thing in my book is that you have your answer.
I'll reply to the spectrogram question as an actual answer, so you can accept it.
Best,
-Greg

Iniciar sesión para comentar.

### Más respuestas (1)

Greg Dionne el 7 de Mzo. de 2019
Hi Harriet,
I'm glad you have the Signal Processing Toolbox and were successfully able to use vco, resample, and spectrogram to visualize your results.
To get spectrogram to plot along the y-axis, just add 'yaxis' to the end of your argument list:
spectrogram(y,kaiser(128,5), 100, 128, fs, 'yaxis')
If you have a more recent version ot the Signal Processing Toolbox, you should know that there's a more 'modern' interface (pspectrum) you can try instead which plots in the more conventional way:
% EXAMPLE 5:
% Re-compute spectrogram of quadratic chirp using a 0.1 seconds time
% resolution.
Fs = 1e3;
t=0:(1/Fs):2;
y=chirp(t,100,1,200,'q');
pspectrum(y,Fs,'spectrogram','TimeResolution',0.1);
You can adjust the 'TimeResoultion' parameter to make the trade-off between time and frequency resolution.
-Greg
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Time-Frequency Analysis en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by