# Ploting a spectrogrma view from sample points in an audio signal

3 visualizzazioni (ultimi 30 giorni)
Cutie il 23 Giu 2021
Risposto: Sai Pavan il 12 Apr 2024
I extracted some samples from an audio signal. I am to plot and have the output in a spectrogram format without using the spectrogram function in Matlab
I arranged the signal in a matrix with eaxh column representing a frame of sample size 8192, I have 20 frames extracted 20 frames as shown below.
How do I go further from here.
fl = 8192; % frame length
% frame = signal (1:8192); % the frame is the window size.
Overlap = 0.5 % window overlap
for i = 1:20
frame = signal(((i-1)*fl + 1):i*fl)
frame_signal (:,i) = (frame);
end
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Sai Pavan il 12 Apr 2024
Hello,
I understand that you want to plot the spectogram of an audio signal without using the inbuilt MATLAB function.
We can utilize the Fast Fourier Transform (FFT) to compute the frequency spectrum for each frame and then plot these spectra to visualize the spectrogram. Please refer to the below workflow to perform this task:
1. For each column in the "frame_signal" matrix, compute the FFT. This gives us the frequency content of each frame.
2. Since the FFT results are complex, calculate the magnitude to get the amplitude spectrum.
3. Plot the magnitude of the FFT for each frame as a function of frequency.
Please refer to the code snippet attached below that illustrates the workflow mentioned above:
fl = 8192; % frame length
Overlap = 0.5; % window overlap
nFrames = 20; % Number of frames
frame_signal = zeros(fl, nFrames); % Preallocate matrix for speed
for i = 1:nFrames % Extract frames
frame_start = round((i-1)*fl*Overlap) + 1;
frame_end = frame_start + fl - 1;
if frame_end > length(signal)
break; % Avoid exceeding the signal length
end
frame_signal(:,i) = signal(frame_start:frame_end);
end
nFFT = fl; % Number of FFT points
freqResolution = Fs/nFFT;
freqAxis = (0:nFFT-1)*freqResolution;
fftMatrix = zeros(nFFT/2+1, nFrames); % Only half+1 due to symmetry of FFT
% Compute FFT for each frame and store the magnitude
for i = 1:nFrames
frameFFT = fft(frame_signal(:,i), nFFT);
fftMatrix(:,i) = abs(frameFFT(1:nFFT/2+1)); % Take half due to symmetry
end
figure;
imagesc([1 nFrames], freqAxis(1:nFFT/2+1), 20*log10(fftMatrix+1)); % Using log scale for magnitude
axis xy; % Flip the axis so lower frequencies are at the bottom
xlabel('Frame Number');
ylabel('Frequency (Hz)');
title('Spectrogram');
colorbar;
Hope it helps!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Signal Processing Toolbox in Help Center e File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by