Borrar filtros
Borrar filtros

I want to change the spectrogram time scale from minutes to seconds but I am unsure how.

46 visualizaciones (últimos 30 días)
I am using the audioread function to read a .wav file and I have generated a spectrogram using the spectrogram function from the data. I have resampled the sample with a different sampling frequency and now I would like to change the x scale to seconds instead of minutes.
trial1 = 'Charge_trial_1.wav';
[y1,Fs1] = audioread(trial1); %Reading the wav file
t1 = 0:1.00002/Fs1:length(y1)/Fs1; %Calculating the time
newFs1 = 3000; %New sampling frequency
[P1,Q1] = rat(newFs1/Fs1); %Assigning ratio values to new Fs
newy1 = resample(y1,P1,Q1); %Resampling the data
newt1 = 0:1.000002/newFs1:length(newy1)/newFs1; %Creating a new time
figure
spectrogram(newy1,256,250,[],newFs1,'yaxis','psd'); %Generating the spectrogram
title('Charge trial 1')
Here is a sample plot
  1 comentario
Peter O
Peter O el 6 de Jul. de 2021
I don't have a Signal Processing Toolbox handy so this is a stab in the dark here going off a lot of memory and typical advanced plotting behaviors. Bode plots from bode behave similarly. If you click in the middle of the spectrogram you should be able to get a handle to the spectrogram object using gco. There might be a TimeUnits or Units parameter to change.
  1. Click on center of spectrogram plot.
  2. Type spgm = gco in the command window of MATLAB
  3. Inspect the spgm struct that comes back for a TimeUnits or similar field that has "minutes"
  4. Try changing that to "seconds" if you find it.
  5. If that works, try passing the field name (e.g. TimeUnits) with the parameter you want to the function call: spectrogram(x,....,'TimeUnits','seconds') in order to do it automatically.
  6. The other possibility to access it, if you can't get it directly from gco is to inspect the children of the axis using get(gca,'Children') to see if there's a SpectrogramObject or something which has properties for tweaking.
Again, apologies if this doesn't work.

Iniciar sesión para comentar.

Respuesta aceptada

Chunru
Chunru el 6 de Jul. de 2021
You can change the xticklabel:
h = gca;
h.XTickLabel = string(h.XTick * 60);
xlabel('Time (s)');
Alternatively, compute the spectrogram by
[s, f, t] = spectrogram(...)
Then you can do your own plotting.

Más respuestas (0)

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by