How to plot separately fft plot and spectrogram?

Hello.
I am trying to plot FFT plot and Spectrogram, however, when I run the code, Spectrogram plot overlap FFT plot.
Also I would like to know how do I know if frequency domain plot has the right scale.
Here is the code:
clc;
close all;
clear;
workspace;
[y,Fs] = audioread("Saludos_Sistemas_Senales.m4a"); % Saludos_Sistemas_Senales.m4a, is an audio file I recorded
soundsc(y, Fs);
N = length(y);
dt = 1/Fs;
t = dt*(0:N-1);
subplot(2,2,1);
plot(t,y); % Plot the audio file in time domain.
X=fft(y);
X_abs=abs(X/N);
X_abs=X_abs(1:N/2+1);
f=Fs*(0:N/2)/N;
subplot(2,2,2);
plot(f,X_abs)
y1 = y(:,1);
MaxValue = max(y);
minValue = min(y);
meanvalue = mean(y);
stdvalue = std(y);
spectrogram(y1, 1024, 512, 1024, Fs, 'yaxis')

Answers (1)

Add the command figure before you create your second plot to force a new figure window.

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!