How to set Spectrogram parameters
10 次查看(过去 30 天)
显示 更早的评论
Hello Everyone,
I would like to print the spectrogram of a curve, in order to observe variations. But I don't really understand how to set the parameters of the function "spectrogram" even with the Matlab help.
For now I have this :
But I can't observe any variation. Is it possible to obtain something more like that :
There is my code and the attached file to get all the datas :
clear all;
clc ;
close all;
Valeurs = xlsread('C:\Users\tlam\Desktop\Run 80.xlsx',"Data1");
Temps = Valeurs(:,1);
Accelero = Valeurs(:,2);
Moteur_rpm = Valeurs(:,3);
BV_rpm = Valeurs(:,4);
Delta = Moteur_rpm - BV_rpm;
M_temps = max(Temps);
Moteur_Hz = Moteur_rpm * 0.016667;
BV_Hz = BV_rpm * 0.016667 ;
Delta_Hz = Delta * 0.016667;
%%
F = figure( 'Position', [50 50 1600 900]) ; % Visible 'off' pour ne pas afficher
t = tiledlayout(3,3,'TileSpacing','Compact','Padding','Compact');
title(t,"Spectro FULL ")
% Mot_rpm(t) et BV_rpm(t) Run 1
nexttile([1 2])
plot(Temps,Moteur_rpm,'red',Temps,BV_rpm,'green')
xlim ([0 M_temps])
ylabel('Moteur & BV [rpm]')
legend ('Moteur','Boite de Vitesse')
grid on
Fs = 50000; %Hz
% Spectrogramme Run 1
nexttile([2 1])
spectrogram(Accelero,100,99,100,Fs,'yaxis','power')
hold on
plot(Temps,Moteur_Hz,'r',Temps,BV_Hz,'g',Temps,Delta_Hz,'b')
colormap('jet')
% Delta(t) Run 1
nexttile([1 2])
plot(Temps,Delta,'blue')
xlim ([0 M_temps])
ylabel('Delta [rpm]')
grid on
% Accelero(t) Run 1
nexttile([1 2])
plot(Temps,Accelero,'magenta')
xlabel('temps [s]')
xlim ([0 M_temps])
ylabel('acceleromètre [V]')
grid on
19 个评论
Mathieu NOE
2023-5-9
Hello
I played a bit with your code and data and tried to make a better spectrogram rendering
I added some high pass filetring on your accel data, otherwise the spectrogram has a very strong output at DC 'not very interesting !)
now you can play with NFFT and OVERLAP if you want to have different frequency and time resolution
also I noticed that inside your code you hardcoded Fs = 5000, whereas from the dat file it's 50 Hz, what is the correct value ?
I could not find any visual correlation between your accel spectrogram and the other signals (converted to Hz) but I wonder if it's correct to compare this way as it assumes that you are only looking at the first engine order (when you convert from RPM to Hz).
For an IC engine, the vibration are higher at multiple engine orders (2nd and above typically)
code a bit tweaked :
clear all;
clc ;
close all;
% Valeurs = xlsread('C:\Users\tlam\Desktop\Run 80.xlsx',"Data1");
Valeurs = xlsread('Run 1.xlsx',"Data1");
Temps = Valeurs(:,1);
dt = mean(diff(Temps));
Fs = 1/dt;
Accelero = Valeurs(:,2);
Moteur_rpm = Valeurs(:,3);
BV_rpm = Valeurs(:,4);
Delta = Moteur_rpm - BV_rpm;
M_temps = max(Temps);
Moteur_Hz = Moteur_rpm /60;
BV_Hz = BV_rpm /60 ;
Delta_Hz = Delta /60;
% high pass filtering of accel signal
f_high = 1; % Hz
order = 3
[b,a] = butter(3,2/Fs*f_high,'high');
Accelero_filtered = filtfilt(b,a,Accelero);
%%
% F = figure( 'Position', [50 50 1600 900]) ; % Visible 'off' pour ne pas afficher
F = figure() ; % Visible 'off' pour ne pas afficher
t = tiledlayout(3,3,'TileSpacing','Compact','Padding','Compact');
title(t,"Spectro FULL ")
% Mot_rpm(t) et BV_rpm(t) Run 1
nexttile([1 2])
plot(Temps,Moteur_rpm,'red',Temps,BV_rpm,'green')
xlim ([0 M_temps])
ylabel('Moteur & BV [rpm]')
legend ('Moteur','Boite de Vitesse')
grid on
%Fs = 50000; %Hz ???
% Spectrogramme Run 1
nexttile([2 1])
NFFT =200;
NOVERLAP = round(0.95*NFFT);
spectrogram(Accelero_filtered,hanning(NFFT),NOVERLAP,NFFT,Fs,'yaxis','power','MinThreshold',-80)
hold on
plot(Temps,Moteur_Hz,'r',Temps,BV_Hz,'g',Temps,Delta_Hz,'b')
colormap('jet')
% Delta(t) Run 1
nexttile([1 2])
plot(Temps,Delta,'blue')
xlim ([0 M_temps])
ylabel('Delta [rpm]')
grid on
% Accelero(t) Run 1
nexttile([1 2])
plot(Temps,Accelero,'magenta')
xlabel('temps [s]')
xlim ([0 M_temps])
ylabel('acceleromètre [V]')
grid on
Théo
2023-5-9
Thanks a lot that's way better !
And yea in fact the frequency is 50Hz (I have an other file with 50k Hz, but I couldn't share it too heavy)
Thanks again :)
Théo
2023-5-9
Are the parameters (NFFT, NOVERLAP) the same for a frequency of 50 000 Hz ?
thx Mathieu
Mathieu NOE
2023-5-9
as you increase the sampling rate , the frequency resolution df will decrease if you keep NFFT the same (because df = Fs/NFFT)
so you may have to increase it significantly
now for overlap , i rarely go above 75% of overlap if the transients are not super brutal (and you need a refined time resolution) , so you shouldn't have to change it all the time
Théo
2023-5-9
I tried on the 50000Hz File
I have this:
Seems like all the spectrogram is on the botom, do you know How I can change the scale ? I have tried to change the "MinThreshold" and add "MaxThreshold" but without success
Mathieu NOE
2023-5-9
try also to shift the high pass filter cut off frequency to a higher value (~ 1 kHz ?)
Mathieu NOE
2023-5-9
I'm curious
why did you apply a factor 1000 on the green and red frequency curves (that is like you are plotinng engine 1000th order frequency ?)
Mathieu NOE
2023-5-9
which brings me another remark from your spectrogram , as the energy sems to be vanishing above 1 kHz
what frequency range are you indeed looking for ?
Théo
2023-5-9
In the Excel file, which I am working currently the acquisition frequency is 50k Hz. I ploted the raw data and divided by 60 to get the value in Hz. I didn't apply a factor 1000, did I ?
I am not looking for a specific frequency, In fact I want to observe the judder on the spectrogram to determine if it's a geometrical judder :
or a "normal" one
Sorry I don't explain very well, I see what I am supposed to get but I can't explain it very well.
I tried to shift the high pass filter cut off frequency to a higher value :
% high pass filtering of accel signal
f_high = 1000; % Hz
Mathieu NOE
2023-5-9
I am a bit lost why you have either 50 Hz or 50 kHz sampling rate
are you measuring two distinct engines (one slow and one fast) ? or are you measuring the same engine with two different recording parameters ?
I just don't get why in the second case (Fs = 50 kHz), on the spectrogram , the green, blue and red curves shows values in the kHz range , whereas the RPM plots (data) seems the same as in the first case (Fs = 50 Hz)
I'm talking about these data :
Moteur_Hz = Moteur_rpm /60;
BV_Hz = BV_rpm /60 ;
Delta_Hz = Delta /60;
anyway it seems the spectrogram shows no energy that is close more or less to the 3 curves (only background noise)
Théo
2023-5-10
That's the same engine with two recording parameters..
The values are supposed to be the same. And you are right I dont really understand, suddenly I have got values in the kHz range on the spectrogram..
That's my code :
Valeurs = xlsread('C:\Users\tlam\Desktop\Run 80.xlsx',"Data1");
Temps = Valeurs(:,1);
Accelero = Valeurs(:,2);
Moteur_rpm = Valeurs(:,3);
BV_rpm = Valeurs(:,4);
Delta = Moteur_rpm - BV_rpm;
M_temps = max(Temps);
Moteur_Hz = Moteur_rpm /60;
BV_Hz = BV_rpm /60 ;
Delta_Hz = Delta /60;
I didn't apply any factor and the values between 50Hz and 50kHz are the same...
It works well for 50 Hz but not for 50 kHz strange ..
Mathieu NOE
2023-5-10
编辑:Mathieu NOE
2023-5-10
can you share your last version of the code with an extract of the 50 kHz data ? I don't need the full length of data
Théo
2023-5-10
Yea sure :
clear all;
clc ;
close all;
Valeurs = xlsread('C:\Users\tlam\Desktop\Run 80bis.xlsx',"Data1");
Temps = Valeurs(:,1);
Accelero = Valeurs(:,2);
Moteur_rpm = Valeurs(:,3);
BV_rpm = Valeurs(:,4);
Delta = Moteur_rpm - BV_rpm;
M_temps = max(Temps);
Moteur_Hz = Moteur_rpm /60;
BV_Hz = BV_rpm /60 ;
Delta_Hz = Delta /60;
dt = mean(diff(Temps));
Fs = 1/dt; %Hz
% high pass filtering of accel signal
f_high = 1000; % Hz
order = 3;
[b,a] = butter(3,2/Fs*f_high,'high');
Accelero_filtered = filtfilt(b,a,Accelero);
%%
F = figure( 'Position', [50 50 1600 900]) ; % Visible 'off' pour ne pas afficher
t = tiledlayout(3,3,'TileSpacing','Compact','Padding','Compact');
title(t,"Spectro FULL ")
% Mot_rpm(t) et BV_rpm(t) Run 1
nexttile([1 2])
plot(Temps,Moteur_rpm,'red',Temps,BV_rpm,'green')
xlim ([0 M_temps])
ylabel('Moteur & BV [rpm]')
legend ('Moteur','Boite de Vitesse')
grid on
nexttile([2 1])
NFFT =200;
NOVERLAP = round(0.95*NFFT);
spectrogram(Accelero_filtered,hanning(NFFT),NOVERLAP,NFFT,Fs,'yaxis','power','MinThreshold',-80)
hold on
plot(Temps,Moteur_Hz,'r',Temps,BV_Hz,'g',Temps,Delta_Hz,'b')
colormap('jet')
% Delta(t) Run 1
nexttile([1 2])
plot(Temps,Delta,'blue')
xlim ([0 M_temps])
ylabel('Delta [rpm]')
grid on
% Accelero(t) Run 1
nexttile([1 2])
plot(Temps,Accelero,'magenta')
xlabel('temps [s]')
xlim ([0 M_temps])
ylabel('acceleromètre [V]')
grid on
I linked a file with the first values at 50 kHz rate.
Thanks again Mathieu, taking time to help me that's realy kind :)
Mathieu NOE
2023-5-10
hello
try this new code
I let you discover the new spectrogram (with frequency axis in log scale to have good rendering both low and high freqs)
now the engine frequency trace is to be seen
by again I see no special event that coincide with the engine freq line
clear all;
clc ;
close all;
Valeurs = xlsread('Run 80bis.xlsx',"Data1");
Temps = Valeurs(:,1);
Accelero = Valeurs(:,2);
Moteur_rpm = Valeurs(:,3);
BV_rpm = Valeurs(:,4);
Delta = Moteur_rpm - BV_rpm;
M_temps = max(Temps);
Moteur_Hz = Moteur_rpm /60;
BV_Hz = BV_rpm /60 ;
Delta_Hz = Delta /60;
dt = mean(diff(Temps));
Fs = 1/dt; %Hz
% high pass filtering of accel signal
f_high = 5; % Hz
order = 2;
[b,a] = butter(3,2/Fs*f_high,'high');
Accelero_filtered = filtfilt(b,a,Accelero);
%%
F = figure( 'Position', [50 50 1600 900]) ; % Visible 'off' pour ne pas afficher
t = tiledlayout(3,3,'TileSpacing','Compact','Padding','Compact');
title(t,"Spectro FULL ")
% Mot_rpm(t) et BV_rpm(t) Run 1
nexttile([1 2])
plot(Temps,Moteur_rpm,'red',Temps,BV_rpm,'green')
xlim ([0 M_temps])
ylabel('Moteur & BV [rpm]')
legend ('Moteur','Boite de Vitesse')
grid on
nexttile([2 1])
NFFT =20000;
NOVERLAP = round(0.95*NFFT);
[S,F,T] = spectrogram(Accelero_filtered,hanning(NFFT),NOVERLAP,NFFT,Fs,'yaxis','power');
idf = (F>0); % remove zero (dc) freq
F = F(idf);
S = S(idf,:);
SdB = 20*log10(abs(S)); % convert S in dB
SdBmax = max(SdB,[],'all');
SdB_range = 80; % range in dB to display
SdB(SdB<SdBmax-SdB_range) = NaN; % remove data below threshold (corresponding to max value - SdB_range)
imagesc(T,F,SdB);
set(gca, 'YDir','normal'); % to have the y = 0 at the bottom and not at the top
set(gca, 'YScale','log'); %
colorbar('vert');
xlabel('temps [s]')
xlim ([0 M_temps])
ylabel('Freq (Hz)')
hold on
plot(Temps,Moteur_Hz,'r',Temps,BV_Hz,'g',Temps,Delta_Hz,'b')
colormap('jet')
% Delta(t) Run 1
nexttile([1 2])
plot(Temps,Delta,'blue')
xlim ([0 M_temps])
ylabel('Delta [rpm]')
grid on
% Accelero(t) Run 1
nexttile([1 2])
plot(Temps,Accelero,'magenta')
xlabel('temps [s]')
xlim ([0 M_temps])
ylabel('acceleromètre [V]')
grid on
Théo
2023-5-11
编辑:Théo
2023-5-11
Hello Mathieu,
I tried and get this :
I was supposed to work on the files with the acquisition freq of 50 kHz but the process time and the results are not convincing.
May I keep on the 50Hz even if the resolution of the spectrogram isn't the best.
Anyway thanks Mathieu for taking all this time for me, I have one last question to which I think I have the answer :
I tried the first code you did on an other vehicle test (freq : 50 Hz) And the curves on the spectrogram dont fit in the window.
I guess it's normal because the input signal in the spectrogram function is the accelerometer, then the engine curve wont necessarily fit. The windowing depends exclusively of the accelerometer.
Can you confirm I am right? Thanks
Mathieu NOE
2023-5-11
to you last question :
yes, the spectrogram max displayed frequency is Fs / 2 = 25 Hz
so any RPM trace above 25*60 = 1500 RPM will not appear
all the best for the future !
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)