- Click on center of spectrogram plot.
- Type spgm = gco in the command window of MATLAB
- Inspect the spgm struct that comes back for a TimeUnits or similar field that has "minutes"
- Try changing that to "seconds" if you find it.
- 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.
- 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.
I want to change the spectrogram time scale from minutes to seconds but I am unsure how.
46 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sebastian Vazquez
il 5 Lug 2021
Commentato: Sebastian Vazquez
il 7 Lug 2021
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/675348/image.png)
1 Commento
Peter O
il 6 Lug 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.
Again, apologies if this doesn't work.
Risposta accettata
Chunru
il 6 Lug 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Spectral Measurements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!