Set the ordinate of the spectrogram to decibel scale

In the spectrum analysis of the signal, sometimes the amplitude of the spectrum has a large dynamic range, and the logarithm of the amplitude must be converted into a decibel value.

There are two solutions: one is to use logarithmic coordinates on the Y axis; the other is to take the logarithm of the amplitude, convert it into decibels and then draw the graph.
(1) Y-axis uses logarithmic coordinates:
when drawing, Y-axis uses logarithmic coordinates. In MATLAB, the X-axis, Y-axis, or XY-axis can use logarithmic coordinates. The corresponding functions are semilogx, semilogy, and loglog. These three functions are all functions used in graphing, which are equivalent to the commonly used graphing function plot. For example, if we want to use logarithmic coordinates for the Y axis, we only need to change the original plot (x, y) to semilogy (x, y).
(2) After converting to decibel values, draw the graph:
the amplitude of the known signal y(n) after FFT is abs(Y), and they can be converted into decibel values. Generally, the following formula is used:
Y_db =20*log10( abs(Y))
where the base 10 logarithm of abs(Y) is multiplied by 20. In this way, the dynamic range between the original amplitudes is reduced when drawing the graph, and it is easy to see the peaks in the graph.
Case: read in a set of experimental data files (the file name is sndatal.mat), and make a spectrogram of the set of data. To find the size and frequency of the largest and smallest peaks in a spectrogram, the procedure is as follows:

clear all; clc; close all;

load sndata1.mat            % 读入数据
X=fft(y);                   % FFT
n2=1:L/2+1;                 % 计算正频率索引号
freq=(n2-1)*fs/L;           % 频率刻度
% 第一部分
% 线性幅值作图
pos = get(gcf,'Position');
set(gcf,'Position',[pos(1), pos(2)-100,pos(3),(pos(4)-140)]);
plot(freq,abs(X(n2)),'k'); grid
xlabel('频率/Hz'); ylabel('幅值')
title('线性幅值')
set(gcf,'color','w');
pause
% 第二部分
% 用对数坐标作图
figure
pos = get(gcf,'Position');
set(gcf,'Position',[pos(1), pos(2)-100,pos(3),(pos(4)-140)]);
semilogy(freq,abs(X(n2)),'k'); grid;
xlabel('频率/Hz'); ylabel('幅值')
title('对数坐标幅值'); hold on
set(gcf,'color','w');
% 计算分贝值作图
figure
X_db=20*log10(abs(X(n2)));
pos = get(gcf,'Position');
set(gcf,'Position',[pos(1), pos(2)-100,pos(3),(pos(4)-140)]);
plot(freq,X_db,'k'); grid;
xlabel('频率/Hz'); ylabel('幅值/dB')
title('分贝幅值'); hold on
set(gcf,'color','w');

The result of the operation is as follows:

 

 

From a numerical point of view, the difference between the maximum peak value and the minimum peak value is greater than 40dB, so it is more convenient to use the decibel value to express both visual observation and numerical calculation. It is displayed in logarithmic coordinates. Although the observation is improved, the calculation is not as good as using the decibel value. convenient.

 The experimental data download link is as follows:

https://download.csdn.net/download/qq_42233059/86405507

References: 85 Practical Cases of MATLAB Digital Signal Processing - Introduction to Advanced; Song Zhiyong (edited) 

Guess you like

Origin blog.csdn.net/qq_42233059/article/details/126450037#comments_28096642