Plotting spectrograph from spectrum analyzer data
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Cesium Modern
el 23 de Feb. de 2024
Comentada: Star Strider
el 28 de Feb. de 2024
I have the following data obtained the following data from a spectrum analyzer. I need some pointers on plotting it to obtain the spectrogram as shown in this image
I have attached my data in this question. The Header contains data from the instrument (such as center frequency) and the Timedata has unsigned array of 10x131071 and Value has the value at each point of time (same size)
_________________
I tried using the following but to no avail
% Convert time_data to double and calculate the sampling frequency
dt = double(time_data(1, 2) - time_data(1, 1)); % Assuming a constant time interval
fs = 1 / dt;
% Transpose the amplitude_data matrix
amplitude_data = amplitude_data';
% Number of rows in amplitude_data
num_rows = size(amplitude_data, 1);
% Plot spectrogram for each row
for row = 1:num_rows
figure;
spectrogram(amplitude_data(row, :), hamming(256), 250, 256, fs, 'yaxis');
title(['Spectrogram for Row ', num2str(row)]);
xlabel('Time');
ylabel('Frequency');
colorbar; % Display the color scale
end
1 comentario
Respuesta aceptada
Star Strider
el 23 de Feb. de 2024
Yiour data needed a bit of tweaking. Tehe times in the ‘TimeData’ matrix are contiguous, so they can be converted into a vector using reshape, and then the same with the ‘Values’ matrix.
Try this —
files = dir('*.mat');
for k = 1:numel(files)
load(files(k).name)
end
% Header
TimeData = double(TimeData);
TimeV = sort(reshape(TimeData.', [], 1)); % Vector From Matrix
Ts = mean(diff(TimeV))
fs = 1/Ts
ValuesV = reshape(Values.', [], 1); % Vector From Matrix
figure
semilogy(TimeV, ValuesV)
xlabel('Time (unit)')
ylabel('Amplitude nit)')
figure;
spectrogram(ValuesV, hamming(256), 250, 256, fs, 'yaxis');
% title(['Spectrogram for Row ', num2str(row)]);
xlabel('Time');
ylabel('Frequency');
colormap(turbo)
colorbar; % Display the color scale
[p,f,t] = pspectrum(ValuesV,fs,'spectrogram');
figure
surfc(f,t,p', 'EdgeColor','interp')
xlabel('Frequency (cycles/time unit)')
ylabel('Time (unit)')
zlabel('Magnitude')
wtf = gca;
wtf.XDir = 'reverse';
view([30 45])
colormap(turbo)
colorbar
figure
surfc(f,t,mag2db(p'), 'EdgeColor','interp')
xlabel('Frequency (cycles/time unit)')
ylabel('Time (unit)')
zlabel('Magnitude (dB)')
wtf = gca;
wtf.XDir = 'reverse';
view([30 45])
colormap(turbo)
colorbar
figure
surfc(f,t,mag2db(p'), 'EdgeColor','interp')
xlabel('Frequency (cycles/time unit)')
ylabel('Time (unit)')
zlabel('Magnitude (dB)')
wtf = gca;
wtf.XDir = 'reverse';
view([30 45])
colormap(turbo)
hcb = colorbar;
hcb.Label.String = 'Magnitude (dB)';
view(90,90)
I did this with both spectrogram and pspectrum (that I actually prefer fot these sorts of analyses).
.
4 comentarios
Star Strider
el 28 de Feb. de 2024
As always, my pleasure!
It would help to know what the actual time values are. They must correspond to something useful, however I cannot figure out how to convert them.
Más respuestas (0)
Ver también
Categorías
Más información sobre Multirate Signal Processing 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!










