Month: September 2024
How to plot the loss function on the overall dataset in Training Progress
I am writing a Convolutional Neural Network for regression in MATLAB R2021b. I’m using the trainNetwork function in Deep Learning Toolbox and in options I have ‘Plots’,’training-progress’.
I have understood that in the Training Progress, for each iteration, I have the MSE value computed on the mini-batch.
I wuold like to know whether I can plot in the training progress the MSE value on the overall Training Set and Validation Set respectively and not on the mini-batch.
Thanks in advance.I am writing a Convolutional Neural Network for regression in MATLAB R2021b. I’m using the trainNetwork function in Deep Learning Toolbox and in options I have ‘Plots’,’training-progress’.
I have understood that in the Training Progress, for each iteration, I have the MSE value computed on the mini-batch.
I wuold like to know whether I can plot in the training progress the MSE value on the overall Training Set and Validation Set respectively and not on the mini-batch.
Thanks in advance. I am writing a Convolutional Neural Network for regression in MATLAB R2021b. I’m using the trainNetwork function in Deep Learning Toolbox and in options I have ‘Plots’,’training-progress’.
I have understood that in the Training Progress, for each iteration, I have the MSE value computed on the mini-batch.
I wuold like to know whether I can plot in the training progress the MSE value on the overall Training Set and Validation Set respectively and not on the mini-batch.
Thanks in advance. training progress, trainnetwork MATLAB Answers — New Questions
Connecting mesh to merge two surfaces
Hello,
Is there a way to connect the mesh of these two surfaces, transforming into just one(surface)?
Thanks in advance.
clear all;
% Welding parameters
%—————————-
U = 33; %Voltage (V)
I = 325; %Current (A)
n = 0.75; %Efficiency
Q = U*I*n;
% Goldak Double-ellipsoid
%————————
a = 4.645; %Metade da largura (mm)
b = 6.5; %Penetração (mm)
C1 = 4.645;
C2 = 16;
FF = 0.6;
FR = 1.4;
x = [-10:.2:10];
y= 0;
z1 = [-10:.2:0];
z2 = [0:.2:10];
[xx,zz] = meshgrid(x,z1);
A1 = ((6*sqrt(3)*FF*Q)/(a*b*C1*pi*sqrt(pi)));
B1 = exp(-1.7*(xx.^2/a.^2)).*exp(-5.0*(zz.^2/C1.^2));
[xa,za] = meshgrid (x,z2);
A2 = ((6*sqrt(3)*FR*Q)/(a*b*C2*pi*sqrt(pi)));
B2 = exp(-1.7*(xa.^2/a.^2)).*exp(-5.0*(za.^2/C2.^2));
q1 = A1.*B1;
q2 = A2.*B2;
[X,Z] = meshgrid (x,-15:.05:15);
mesh(xx,zz,q1);
hold on
mesh(xx,za,q2);
shading interp
colormap jet
xlabel(‘ x (mm)’)
ylabel(‘ Welding direction (mm)’)
zlabel(‘ Power Density (W/mm³)’)
<</matlabcentral/answers/uploaded_files/81300/DE.jpg>>Hello,
Is there a way to connect the mesh of these two surfaces, transforming into just one(surface)?
Thanks in advance.
clear all;
% Welding parameters
%—————————-
U = 33; %Voltage (V)
I = 325; %Current (A)
n = 0.75; %Efficiency
Q = U*I*n;
% Goldak Double-ellipsoid
%————————
a = 4.645; %Metade da largura (mm)
b = 6.5; %Penetração (mm)
C1 = 4.645;
C2 = 16;
FF = 0.6;
FR = 1.4;
x = [-10:.2:10];
y= 0;
z1 = [-10:.2:0];
z2 = [0:.2:10];
[xx,zz] = meshgrid(x,z1);
A1 = ((6*sqrt(3)*FF*Q)/(a*b*C1*pi*sqrt(pi)));
B1 = exp(-1.7*(xx.^2/a.^2)).*exp(-5.0*(zz.^2/C1.^2));
[xa,za] = meshgrid (x,z2);
A2 = ((6*sqrt(3)*FR*Q)/(a*b*C2*pi*sqrt(pi)));
B2 = exp(-1.7*(xa.^2/a.^2)).*exp(-5.0*(za.^2/C2.^2));
q1 = A1.*B1;
q2 = A2.*B2;
[X,Z] = meshgrid (x,-15:.05:15);
mesh(xx,zz,q1);
hold on
mesh(xx,za,q2);
shading interp
colormap jet
xlabel(‘ x (mm)’)
ylabel(‘ Welding direction (mm)’)
zlabel(‘ Power Density (W/mm³)’)
<</matlabcentral/answers/uploaded_files/81300/DE.jpg>> Hello,
Is there a way to connect the mesh of these two surfaces, transforming into just one(surface)?
Thanks in advance.
clear all;
% Welding parameters
%—————————-
U = 33; %Voltage (V)
I = 325; %Current (A)
n = 0.75; %Efficiency
Q = U*I*n;
% Goldak Double-ellipsoid
%————————
a = 4.645; %Metade da largura (mm)
b = 6.5; %Penetração (mm)
C1 = 4.645;
C2 = 16;
FF = 0.6;
FR = 1.4;
x = [-10:.2:10];
y= 0;
z1 = [-10:.2:0];
z2 = [0:.2:10];
[xx,zz] = meshgrid(x,z1);
A1 = ((6*sqrt(3)*FF*Q)/(a*b*C1*pi*sqrt(pi)));
B1 = exp(-1.7*(xx.^2/a.^2)).*exp(-5.0*(zz.^2/C1.^2));
[xa,za] = meshgrid (x,z2);
A2 = ((6*sqrt(3)*FR*Q)/(a*b*C2*pi*sqrt(pi)));
B2 = exp(-1.7*(xa.^2/a.^2)).*exp(-5.0*(za.^2/C2.^2));
q1 = A1.*B1;
q2 = A2.*B2;
[X,Z] = meshgrid (x,-15:.05:15);
mesh(xx,zz,q1);
hold on
mesh(xx,za,q2);
shading interp
colormap jet
xlabel(‘ x (mm)’)
ylabel(‘ Welding direction (mm)’)
zlabel(‘ Power Density (W/mm³)’)
<</matlabcentral/answers/uploaded_files/81300/DE.jpg>> merge surfaces MATLAB Answers — New Questions
How to convert Text to Date?
I’ve extracted a sheet like this with a webscrapper tool but it formates dates like this – is there a formula etc to make sure it formats it into a mm/yy format? Even if it says 3 years ago, wouldnt mind if it was current month but 3 years ago etc
Thanks
I’ve extracted a sheet like this with a webscrapper tool but it formates dates like this – is there a formula etc to make sure it formats it into a mm/yy format? Even if it says 3 years ago, wouldnt mind if it was current month but 3 years ago etcThanks Read More
Problems with slrttest in the reboot
Hello, I’m trying to connect to a custom target computer via a LAN cable at MATLAB/Simulink R2017b, but when I run the srttest an error comes out:.
## Simulink Real-Time Test Suite
### Host-Target interface is: TcpIp
### Test 1, Ping target computer ‘TargetPC1’ using system ping: … OK
### Test 2, Ping target computer ‘TargetPC1’ using SLRTPINGTARGET: … OK
### Test 3, Software reboot the target computer ‘TargetPC1’: error: slrttest (line 181)
message: "The input string format is not correct."
source: "mscorlib"
181 error( booterror.message );Hello, I’m trying to connect to a custom target computer via a LAN cable at MATLAB/Simulink R2017b, but when I run the srttest an error comes out:.
## Simulink Real-Time Test Suite
### Host-Target interface is: TcpIp
### Test 1, Ping target computer ‘TargetPC1’ using system ping: … OK
### Test 2, Ping target computer ‘TargetPC1’ using SLRTPINGTARGET: … OK
### Test 3, Software reboot the target computer ‘TargetPC1’: error: slrttest (line 181)
message: "The input string format is not correct."
source: "mscorlib"
181 error( booterror.message ); Hello, I’m trying to connect to a custom target computer via a LAN cable at MATLAB/Simulink R2017b, but when I run the srttest an error comes out:.
## Simulink Real-Time Test Suite
### Host-Target interface is: TcpIp
### Test 1, Ping target computer ‘TargetPC1’ using system ping: … OK
### Test 2, Ping target computer ‘TargetPC1’ using SLRTPINGTARGET: … OK
### Test 3, Software reboot the target computer ‘TargetPC1’: error: slrttest (line 181)
message: "The input string format is not correct."
source: "mscorlib"
181 error( booterror.message ); srttest MATLAB Answers — New Questions
Recessionplot not including 2020
Dear Experts,
I am having a challenge with recessionplot. I have plotted this monthly time series data (1971M1-2021M10) and clicked ‘recessionplot’.
However, the recessionplot algorithm does not shade (grey) the COVID-19 recession (2020M02-2020M04).
How do I add the COVID-19 recession to the graph?
Thank you,
MphoDear Experts,
I am having a challenge with recessionplot. I have plotted this monthly time series data (1971M1-2021M10) and clicked ‘recessionplot’.
However, the recessionplot algorithm does not shade (grey) the COVID-19 recession (2020M02-2020M04).
How do I add the COVID-19 recession to the graph?
Thank you,
Mpho Dear Experts,
I am having a challenge with recessionplot. I have plotted this monthly time series data (1971M1-2021M10) and clicked ‘recessionplot’.
However, the recessionplot algorithm does not shade (grey) the COVID-19 recession (2020M02-2020M04).
How do I add the COVID-19 recession to the graph?
Thank you,
Mpho recessionplot MATLAB Answers — New Questions
my graph won’t show the exponential graph as the alpha value is 0, can someone help fix this problem?
%a
cockrach=importdata(‘cockroach_population.xlsx’);
num_cockrach=cockrach.data;
days=num_cockrach(:,1);
cockraches=num_cockrach(:,2);
%b
ylin=cockraches;
xlin=log(days);
[a0,a1,r2] = linreg(xlin,ylin);
p=polyfit(days,cockraches,2);
alpha=(exp(1)).^a0;
Beta=a1;
text1=sprintf(‘parabola-cockraches rate: cockraches= %.2fx^2+%.2fx+%.2f’,p);
%c
exponential_curve= alpha.*exp(1).^(Beta.*days);
text2=sprintf(‘exponential-cockraches rate: cockraches= %.2fe^%.2fxn’,alpha, Beta);
figure
plot(days,cockraches,’b.’);
hold on
plot(days,polyval(p,days),’r-‘,’LineWidth’,3);
plot(days,exponential_curve,’g-‘,’LineWidth’,3)
title(‘numbers of cockraches vs times(days)’);
xlabel(‘cockraches’);
ylabel(‘days’);
legend(‘unlinearised’,text1,text2)%a
cockrach=importdata(‘cockroach_population.xlsx’);
num_cockrach=cockrach.data;
days=num_cockrach(:,1);
cockraches=num_cockrach(:,2);
%b
ylin=cockraches;
xlin=log(days);
[a0,a1,r2] = linreg(xlin,ylin);
p=polyfit(days,cockraches,2);
alpha=(exp(1)).^a0;
Beta=a1;
text1=sprintf(‘parabola-cockraches rate: cockraches= %.2fx^2+%.2fx+%.2f’,p);
%c
exponential_curve= alpha.*exp(1).^(Beta.*days);
text2=sprintf(‘exponential-cockraches rate: cockraches= %.2fe^%.2fxn’,alpha, Beta);
figure
plot(days,cockraches,’b.’);
hold on
plot(days,polyval(p,days),’r-‘,’LineWidth’,3);
plot(days,exponential_curve,’g-‘,’LineWidth’,3)
title(‘numbers of cockraches vs times(days)’);
xlabel(‘cockraches’);
ylabel(‘days’);
legend(‘unlinearised’,text1,text2) %a
cockrach=importdata(‘cockroach_population.xlsx’);
num_cockrach=cockrach.data;
days=num_cockrach(:,1);
cockraches=num_cockrach(:,2);
%b
ylin=cockraches;
xlin=log(days);
[a0,a1,r2] = linreg(xlin,ylin);
p=polyfit(days,cockraches,2);
alpha=(exp(1)).^a0;
Beta=a1;
text1=sprintf(‘parabola-cockraches rate: cockraches= %.2fx^2+%.2fx+%.2f’,p);
%c
exponential_curve= alpha.*exp(1).^(Beta.*days);
text2=sprintf(‘exponential-cockraches rate: cockraches= %.2fe^%.2fxn’,alpha, Beta);
figure
plot(days,cockraches,’b.’);
hold on
plot(days,polyval(p,days),’r-‘,’LineWidth’,3);
plot(days,exponential_curve,’g-‘,’LineWidth’,3)
title(‘numbers of cockraches vs times(days)’);
xlabel(‘cockraches’);
ylabel(‘days’);
legend(‘unlinearised’,text1,text2) exponential curve, nonlinear, linear MATLAB Answers — New Questions
How to filter and display a one-month calendar from the academic calendar template?
Hi, so there are two excel sheets, one being the “Calender” which has all 12 months, and the other being the “Current Month” which displays the current month. Is it possible to display and update any data from the “Calender” to the “Current Month” and vise versa. Thank you.
Hi, so there are two excel sheets, one being the “Calender” which has all 12 months, and the other being the “Current Month” which displays the current month. Is it possible to display and update any data from the “Calender” to the “Current Month” and vise versa. Thank you. Read More
Removing duplicates from Access query
I have an Access database to catalog a collection. In the table “Sets”, there is a column that “Material Type” that links to another table (Materials.ID). Material Type allows multi-selection to support cases where a set is made of two or more materials. The problem is that when an item has multiple Material Types, the item shows up multiple times in reports.
For example:
In the table Sets, item 292 has two Material Types (Metal and Recycled)When querying, item 292 shows up twice. This would make some sense if each result row shows a separate Material Type field (Metal in one, an Recycled in the other), but each result shows both values.Then, when I have a form based on the query, I get two duplicate items of 292:
So, my question is: How do I get rid of the duplicate rows in the query? If the query only had one row, the form would only have one row. I’ve never been able to find any help or support articles that address this issue.
Thanks for any assistance you can offer.
Phil Garding
I have an Access database to catalog a collection. In the table “Sets”, there is a column that “Material Type” that links to another table (Materials.ID). Material Type allows multi-selection to support cases where a set is made of two or more materials. The problem is that when an item has multiple Material Types, the item shows up multiple times in reports. For example:In the table Sets, item 292 has two Material Types (Metal and Recycled)When querying, item 292 shows up twice. This would make some sense if each result row shows a separate Material Type field (Metal in one, an Recycled in the other), but each result shows both values.Then, when I have a form based on the query, I get two duplicate items of 292:So, my question is: How do I get rid of the duplicate rows in the query? If the query only had one row, the form would only have one row. I’ve never been able to find any help or support articles that address this issue. Thanks for any assistance you can offer. Phil Garding Read More
Get properties from Aspen Plus
Hello Matlab community,
I want to use material properties from Aspen Properties V9 to calculate some dimensionless numbers. For example I want to get out the heat capacity, thermal heat conductivity, etc. of water at different temperatures and pressures. Is this possible?
Thank you for helping an inexperienced user.Hello Matlab community,
I want to use material properties from Aspen Properties V9 to calculate some dimensionless numbers. For example I want to get out the heat capacity, thermal heat conductivity, etc. of water at different temperatures and pressures. Is this possible?
Thank you for helping an inexperienced user. Hello Matlab community,
I want to use material properties from Aspen Properties V9 to calculate some dimensionless numbers. For example I want to get out the heat capacity, thermal heat conductivity, etc. of water at different temperatures and pressures. Is this possible?
Thank you for helping an inexperienced user. aspen plus, properties MATLAB Answers — New Questions
This is face morphing. Now I want to save and convert to a gif image format.
close all
iter=10;
A=im2double(imread(‘1.JPG’));
B=im2double(imread(‘2.JPG’));
A=imresize(A, [512 512]);
B=imresize(B, [512 512]);
D=B-A;
D=D./iter;
for i=1:iter
A=A+D;
imshow(A);
pause (0.1);
endclose all
iter=10;
A=im2double(imread(‘1.JPG’));
B=im2double(imread(‘2.JPG’));
A=imresize(A, [512 512]);
B=imresize(B, [512 512]);
D=B-A;
D=D./iter;
for i=1:iter
A=A+D;
imshow(A);
pause (0.1);
end close all
iter=10;
A=im2double(imread(‘1.JPG’));
B=im2double(imread(‘2.JPG’));
A=imresize(A, [512 512]);
B=imresize(B, [512 512]);
D=B-A;
D=D./iter;
for i=1:iter
A=A+D;
imshow(A);
pause (0.1);
end image processing, morphing, morph images MATLAB Answers — New Questions
I need help validating my forward kinematic using Simulink and the Robotic Systems Toolbox for a surgical robot.
Hi all,
I am a student and I am working on a surgical eye robot which utilises a remote centre of motion mechanism (RCM). I have found the forward kinematics for it using the DH method and another method. I have also found the Jacobian velocity matrix for it. However, my Jacobian seems a bit off and I am looking to validate it and the forward kinematic using RST. I have exported the CAD model as XML and created an slx file for it. The robot composes of multiple joints. However, in reality, only 4 joints are actuation joints, the rest are closed loop joints that reduce the robots DOF to 1 or 2 DOF (pitch and translation).
I have set up the robots and actuated it fine using a constant block connected a degree to radians block which is then connected to the robot, which is connected to a MATLAB function script which is then connected to a display to show me the homogenous matrix.
I am now at the stage where I am looking to connect a GetTransform block in order to retrieve the forward kinematic. Below is the way I am connecting the blocks. My apologies since I am using a different computer and can’t screenshot my layout.
3 Sine blocks and a constant block connected to the robots (I have made the robots connection and blocks a subsystem). From the robot subsystem, it’s connected to a mux that takes 4 inputs. The mux is connected to the GetTransform block. The GetTransform block is connected to a Coordinate Transformation Conversion block which is then connected to a scope.
All of my setup seems fine. However, I am getting an error that says the input is a vector of 4 whereas the outputs requires 11. I know this is due to the joints block where I have set up 4 of them to sense the postion and computed the torque automatically and I have 11 joints in total. When I add an additional Simulink to PS and PS to simulink to another joint, I get an error like this: "The input is a vector of 5 whereas the outputs requires 11". As mentioned, only 4 of the joints are actuating joints and joints that I need to find the forward kinematic for. How can I fix this issue without adding more joints to sense the position?
My second question is rather simple. I am using 3R1P configuration. I know I can get a constant block connected to a degrees to radians block to control the revolute arm of the robot. What is a similar setup I can use to move the prismatic joints?
Thank you so much for the help in advance!Hi all,
I am a student and I am working on a surgical eye robot which utilises a remote centre of motion mechanism (RCM). I have found the forward kinematics for it using the DH method and another method. I have also found the Jacobian velocity matrix for it. However, my Jacobian seems a bit off and I am looking to validate it and the forward kinematic using RST. I have exported the CAD model as XML and created an slx file for it. The robot composes of multiple joints. However, in reality, only 4 joints are actuation joints, the rest are closed loop joints that reduce the robots DOF to 1 or 2 DOF (pitch and translation).
I have set up the robots and actuated it fine using a constant block connected a degree to radians block which is then connected to the robot, which is connected to a MATLAB function script which is then connected to a display to show me the homogenous matrix.
I am now at the stage where I am looking to connect a GetTransform block in order to retrieve the forward kinematic. Below is the way I am connecting the blocks. My apologies since I am using a different computer and can’t screenshot my layout.
3 Sine blocks and a constant block connected to the robots (I have made the robots connection and blocks a subsystem). From the robot subsystem, it’s connected to a mux that takes 4 inputs. The mux is connected to the GetTransform block. The GetTransform block is connected to a Coordinate Transformation Conversion block which is then connected to a scope.
All of my setup seems fine. However, I am getting an error that says the input is a vector of 4 whereas the outputs requires 11. I know this is due to the joints block where I have set up 4 of them to sense the postion and computed the torque automatically and I have 11 joints in total. When I add an additional Simulink to PS and PS to simulink to another joint, I get an error like this: "The input is a vector of 5 whereas the outputs requires 11". As mentioned, only 4 of the joints are actuating joints and joints that I need to find the forward kinematic for. How can I fix this issue without adding more joints to sense the position?
My second question is rather simple. I am using 3R1P configuration. I know I can get a constant block connected to a degrees to radians block to control the revolute arm of the robot. What is a similar setup I can use to move the prismatic joints?
Thank you so much for the help in advance! Hi all,
I am a student and I am working on a surgical eye robot which utilises a remote centre of motion mechanism (RCM). I have found the forward kinematics for it using the DH method and another method. I have also found the Jacobian velocity matrix for it. However, my Jacobian seems a bit off and I am looking to validate it and the forward kinematic using RST. I have exported the CAD model as XML and created an slx file for it. The robot composes of multiple joints. However, in reality, only 4 joints are actuation joints, the rest are closed loop joints that reduce the robots DOF to 1 or 2 DOF (pitch and translation).
I have set up the robots and actuated it fine using a constant block connected a degree to radians block which is then connected to the robot, which is connected to a MATLAB function script which is then connected to a display to show me the homogenous matrix.
I am now at the stage where I am looking to connect a GetTransform block in order to retrieve the forward kinematic. Below is the way I am connecting the blocks. My apologies since I am using a different computer and can’t screenshot my layout.
3 Sine blocks and a constant block connected to the robots (I have made the robots connection and blocks a subsystem). From the robot subsystem, it’s connected to a mux that takes 4 inputs. The mux is connected to the GetTransform block. The GetTransform block is connected to a Coordinate Transformation Conversion block which is then connected to a scope.
All of my setup seems fine. However, I am getting an error that says the input is a vector of 4 whereas the outputs requires 11. I know this is due to the joints block where I have set up 4 of them to sense the postion and computed the torque automatically and I have 11 joints in total. When I add an additional Simulink to PS and PS to simulink to another joint, I get an error like this: "The input is a vector of 5 whereas the outputs requires 11". As mentioned, only 4 of the joints are actuating joints and joints that I need to find the forward kinematic for. How can I fix this issue without adding more joints to sense the position?
My second question is rather simple. I am using 3R1P configuration. I know I can get a constant block connected to a degrees to radians block to control the revolute arm of the robot. What is a similar setup I can use to move the prismatic joints?
Thank you so much for the help in advance! robotic, robotic system toolbox, matlab, forward kinematic, jacobian, simulink, simscape, setup MATLAB Answers — New Questions
%I encountered the following problem in the calculation: 1. The calculated H is negative, %and I am unsure if the calculation is correct. Some formulas cannot be simplified and still %exist in the form of 5000/51166. 3. Poor overall code fluency clea
clear all
close
%% 参数定义parameter definition
P = 42;
c = 800;
E = 15000000;
K = 1.8;
P_ya = 18000;
F = 2;
y = 26.8;
R = 20; % radius
syms H B
%H=100;
% 计算破裂角 a Calculate the rupture angle
if K <= 0.5
a = 90;
elseif K <= 1
a = -90 * K + 135;
elseif K <= 3
a = -22.5 * K + 67.5;
else
a = 0;
end
% 显示计算得到的 a 的值
disp([‘当 K = ‘, num2str(K), ‘ 时,破裂角 a = ‘, num2str(a), ‘°’]);
%% 求解初始破裂角相关量 Solving the initial rupture angle related quantities
L = H + R * (1 – sind(a));
G_1 = (y * L^2) / (2 * tand(B)); % 三角形块体的自重
p = atan2(tand(P), F); % 折减后的内摩擦角
p = rad2deg(p); % 将结果转换为度,便于后面统一计算
C = c * L; % 竖直面上粘聚力合力
C_s = c * L / (F * sind(B)); % 破裂面上粘聚力合力
G_0 = 2 * y * H * cosd(a);
z = 0.9 * P; % 按照围岩等级取值,三级围岩取0.9
%% 定义目标函数 E(B) Define the objective function E (B)
%E_func = @(B) (y ./ (2 .* tand(B))) .* sind(B + p) ./ cosd(B + p – z);
E_func=@(B) (cosd(B+p).*sind(B)).*cosd(B).*cosd(B+p-z)+sind(B+p).*sind(B).*(sind(B+p-z).*cosd(B)+cosd(B+p-z).*sind(B));
%% 数值求导函数 Numerical derivative function
% 使用中心差分法计算导数
dE_func = @(B) (E_func(B + 1e-6) – E_func(B – 1e-6)) / (2e-6);
%% 数值寻找导数为零的 B 值
% 只寻找一个接近的 B 值
B_range = [0, 90]; % B 的取值范围
B_init = 45; % 初始猜测值,设置为 45 度
% 使用 fzero 寻找导数为零的 B 值
try
B_zero = fzero(dE_func, B_init);
% 检查找到的 B 值是否满足条件
if abs(dE_func(B_zero)) < 1e-6
disp([‘找到满足条件的 B 值为:’, num2str(B_zero)]);
else
disp(‘没有找到导数接近零的 B 值’);
end
catch
disp(‘fzero 计算失败,未找到满足条件的 B 值’);
end
B=B_zero
%% 计算埋深 Calculate burial depth
f1 = ((G_1 – C) .* sind(p + B_zero) + C_s .* cosd(p)) ./ cosd(B_zero + p – z);
f2 = (P_ya – G_0 – 2 .* C) / (2 * sind(z));
% 定义控制方程,解出 H
eqn = f1 – f2 == 0;
% 使用 solve 反解出 H
sol_H_sym = solve(eqn, H);
% 将符号解转换为具体的数值
sol_H_num = double(subs(sol_H_sym));
% 显示结果
disp([‘解出的 H 的值为:’, num2str(sol_H_num)]);clear all
close
%% 参数定义parameter definition
P = 42;
c = 800;
E = 15000000;
K = 1.8;
P_ya = 18000;
F = 2;
y = 26.8;
R = 20; % radius
syms H B
%H=100;
% 计算破裂角 a Calculate the rupture angle
if K <= 0.5
a = 90;
elseif K <= 1
a = -90 * K + 135;
elseif K <= 3
a = -22.5 * K + 67.5;
else
a = 0;
end
% 显示计算得到的 a 的值
disp([‘当 K = ‘, num2str(K), ‘ 时,破裂角 a = ‘, num2str(a), ‘°’]);
%% 求解初始破裂角相关量 Solving the initial rupture angle related quantities
L = H + R * (1 – sind(a));
G_1 = (y * L^2) / (2 * tand(B)); % 三角形块体的自重
p = atan2(tand(P), F); % 折减后的内摩擦角
p = rad2deg(p); % 将结果转换为度,便于后面统一计算
C = c * L; % 竖直面上粘聚力合力
C_s = c * L / (F * sind(B)); % 破裂面上粘聚力合力
G_0 = 2 * y * H * cosd(a);
z = 0.9 * P; % 按照围岩等级取值,三级围岩取0.9
%% 定义目标函数 E(B) Define the objective function E (B)
%E_func = @(B) (y ./ (2 .* tand(B))) .* sind(B + p) ./ cosd(B + p – z);
E_func=@(B) (cosd(B+p).*sind(B)).*cosd(B).*cosd(B+p-z)+sind(B+p).*sind(B).*(sind(B+p-z).*cosd(B)+cosd(B+p-z).*sind(B));
%% 数值求导函数 Numerical derivative function
% 使用中心差分法计算导数
dE_func = @(B) (E_func(B + 1e-6) – E_func(B – 1e-6)) / (2e-6);
%% 数值寻找导数为零的 B 值
% 只寻找一个接近的 B 值
B_range = [0, 90]; % B 的取值范围
B_init = 45; % 初始猜测值,设置为 45 度
% 使用 fzero 寻找导数为零的 B 值
try
B_zero = fzero(dE_func, B_init);
% 检查找到的 B 值是否满足条件
if abs(dE_func(B_zero)) < 1e-6
disp([‘找到满足条件的 B 值为:’, num2str(B_zero)]);
else
disp(‘没有找到导数接近零的 B 值’);
end
catch
disp(‘fzero 计算失败,未找到满足条件的 B 值’);
end
B=B_zero
%% 计算埋深 Calculate burial depth
f1 = ((G_1 – C) .* sind(p + B_zero) + C_s .* cosd(p)) ./ cosd(B_zero + p – z);
f2 = (P_ya – G_0 – 2 .* C) / (2 * sind(z));
% 定义控制方程,解出 H
eqn = f1 – f2 == 0;
% 使用 solve 反解出 H
sol_H_sym = solve(eqn, H);
% 将符号解转换为具体的数值
sol_H_num = double(subs(sol_H_sym));
% 显示结果
disp([‘解出的 H 的值为:’, num2str(sol_H_num)]); clear all
close
%% 参数定义parameter definition
P = 42;
c = 800;
E = 15000000;
K = 1.8;
P_ya = 18000;
F = 2;
y = 26.8;
R = 20; % radius
syms H B
%H=100;
% 计算破裂角 a Calculate the rupture angle
if K <= 0.5
a = 90;
elseif K <= 1
a = -90 * K + 135;
elseif K <= 3
a = -22.5 * K + 67.5;
else
a = 0;
end
% 显示计算得到的 a 的值
disp([‘当 K = ‘, num2str(K), ‘ 时,破裂角 a = ‘, num2str(a), ‘°’]);
%% 求解初始破裂角相关量 Solving the initial rupture angle related quantities
L = H + R * (1 – sind(a));
G_1 = (y * L^2) / (2 * tand(B)); % 三角形块体的自重
p = atan2(tand(P), F); % 折减后的内摩擦角
p = rad2deg(p); % 将结果转换为度,便于后面统一计算
C = c * L; % 竖直面上粘聚力合力
C_s = c * L / (F * sind(B)); % 破裂面上粘聚力合力
G_0 = 2 * y * H * cosd(a);
z = 0.9 * P; % 按照围岩等级取值,三级围岩取0.9
%% 定义目标函数 E(B) Define the objective function E (B)
%E_func = @(B) (y ./ (2 .* tand(B))) .* sind(B + p) ./ cosd(B + p – z);
E_func=@(B) (cosd(B+p).*sind(B)).*cosd(B).*cosd(B+p-z)+sind(B+p).*sind(B).*(sind(B+p-z).*cosd(B)+cosd(B+p-z).*sind(B));
%% 数值求导函数 Numerical derivative function
% 使用中心差分法计算导数
dE_func = @(B) (E_func(B + 1e-6) – E_func(B – 1e-6)) / (2e-6);
%% 数值寻找导数为零的 B 值
% 只寻找一个接近的 B 值
B_range = [0, 90]; % B 的取值范围
B_init = 45; % 初始猜测值,设置为 45 度
% 使用 fzero 寻找导数为零的 B 值
try
B_zero = fzero(dE_func, B_init);
% 检查找到的 B 值是否满足条件
if abs(dE_func(B_zero)) < 1e-6
disp([‘找到满足条件的 B 值为:’, num2str(B_zero)]);
else
disp(‘没有找到导数接近零的 B 值’);
end
catch
disp(‘fzero 计算失败,未找到满足条件的 B 值’);
end
B=B_zero
%% 计算埋深 Calculate burial depth
f1 = ((G_1 – C) .* sind(p + B_zero) + C_s .* cosd(p)) ./ cosd(B_zero + p – z);
f2 = (P_ya – G_0 – 2 .* C) / (2 * sind(z));
% 定义控制方程,解出 H
eqn = f1 – f2 == 0;
% 使用 solve 反解出 H
sol_H_sym = solve(eqn, H);
% 将符号解转换为具体的数值
sol_H_num = double(subs(sol_H_sym));
% 显示结果
disp([‘解出的 H 的值为:’, num2str(sol_H_num)]); transferred, syms, symbolic MATLAB Answers — New Questions
How do I extract audio from a video for free on Windows 11 PC?
I am currently working on a project and need to extract audio from video as background music. I’ve tried using the free Movie Maker app but unable to find the extract function. In addition, I also use the ffmpeeg command line but unable to execute the commands.
I am stuck and I’m open to exploring other methods or tools that might work better for this task. Are there any free software options available for extracting audio from video, or should I consider purchasing a dedicated tool? Any advice on the process would be greatly appreciated!
Thank you
I am currently working on a project and need to extract audio from video as background music. I’ve tried using the free Movie Maker app but unable to find the extract function. In addition, I also use the ffmpeeg command line but unable to execute the commands. I am stuck and I’m open to exploring other methods or tools that might work better for this task. Are there any free software options available for extracting audio from video, or should I consider purchasing a dedicated tool? Any advice on the process would be greatly appreciated! Thank you Read More
MATLAB/Simulink FPGA-In-The-Loop (FIL) Connection Issue with Zybo Z7 20
I encountered an issue when attempting to send a bitstream file to program my Zybo Z7 board using Vivado 2020.1 for an FPGA-in-loop with Simulink. Below is the error message I received:
I am aware that the Zybo board is not yet supported by MATLAB. What steps should I take to resolve this issue? Additionally, if I purchase the Arty A7-100T board (https://digilent.com/shop/arty-a7-100t-artix-7-fpga-development-board/?srsltid=AfmBOoqSJZFmnN32QqiorkfpDJpZGWHxxwa_fzSc0o1MpIyNG6jYYAag), will I encounter the same error?"I encountered an issue when attempting to send a bitstream file to program my Zybo Z7 board using Vivado 2020.1 for an FPGA-in-loop with Simulink. Below is the error message I received:
I am aware that the Zybo board is not yet supported by MATLAB. What steps should I take to resolve this issue? Additionally, if I purchase the Arty A7-100T board (https://digilent.com/shop/arty-a7-100t-artix-7-fpga-development-board/?srsltid=AfmBOoqSJZFmnN32QqiorkfpDJpZGWHxxwa_fzSc0o1MpIyNG6jYYAag), will I encounter the same error?" I encountered an issue when attempting to send a bitstream file to program my Zybo Z7 board using Vivado 2020.1 for an FPGA-in-loop with Simulink. Below is the error message I received:
I am aware that the Zybo board is not yet supported by MATLAB. What steps should I take to resolve this issue? Additionally, if I purchase the Arty A7-100T board (https://digilent.com/shop/arty-a7-100t-artix-7-fpga-development-board/?srsltid=AfmBOoqSJZFmnN32QqiorkfpDJpZGWHxxwa_fzSc0o1MpIyNG6jYYAag), will I encounter the same error?" zybo, fil MATLAB Answers — New Questions
Exchange Mailtips for Emails Containing Attachments and Directed to External Recipient
Hello Everyone!
I’m trying to setup a global MailTip or alert which would notify a user when they are sending an e-mail containing attachments to an external recipient.
I’m trying to weigh all the possibilities available and so far I’ve seen options with exchange MailTips and Purview DLP policies. I have played a little bit with MailTips and turned on the “-MailTipsExternalRecipientsEnabled” option with PowerShell. This works great but only addresses half of my want list. Is there a way to modify this MailTip rule to apply only when the email contains an attachment? Not seeing too much on the official MS documentation, unless I’m not looking in the right place.
If not doable via MailTips, does anyone have any other suggestion to do this?
Hello Everyone! I’m trying to setup a global MailTip or alert which would notify a user when they are sending an e-mail containing attachments to an external recipient.I’m trying to weigh all the possibilities available and so far I’ve seen options with exchange MailTips and Purview DLP policies. I have played a little bit with MailTips and turned on the “-MailTipsExternalRecipientsEnabled” option with PowerShell. This works great but only addresses half of my want list. Is there a way to modify this MailTip rule to apply only when the email contains an attachment? Not seeing too much on the official MS documentation, unless I’m not looking in the right place. If not doable via MailTips, does anyone have any other suggestion to do this? Read More
Condtional Statements
Dear Experts,
Greetings!
I have a data like below(A1:E17), In Column “F” , I need an output like this:-
Tried with IF, but too lengthy.. could you please share some other formula to achieve this..
Something like FILTER, INDEX MATCH etc..
Thanks in Advance,
Br,
Anupam
Dear Experts, Greetings! I have a data like below(A1:E17), In Column “F” , I need an output like this:-Tried with IF, but too lengthy.. could you please share some other formula to achieve this.. Something like FILTER, INDEX MATCH etc.. Thanks in Advance,Br,Anupam Read More
Show correct %-Allocation in Resource Usage for a specific project when using Resource Pool
I would like to get Percent Allocation in Resource Usage, by a specific project when I have a pool of resources and a master project using two simple projects (testP1, testP2) like the following to illustrate the point. I have the following:
And I would like to visualize the monthly percent allocation in the Resource Usage view. Considering Sept,2025 which has 168 working hours.
I created the following custom group: Group by Projects as follows, to group by project, so I can have the information I am looking for:
Note: I followed the answer from Ignacio Marin for this question: MS Project Resource Pool Usage. Then I followed the instructions from this post: View resource workloads and availability in Project desktop to add Percent Allocation in the Detail column of the Resource Usage view.
Now using this custom group I would like to get the calculation for %-Allocation for project testP1, so I filter the Project column to select just this project. I am getting the following results:
As you can see the result is as expected for Work, but not for % Allocation. For example for Res1 is working 80 hours, so its allocation should be: 80/168=48%, but the allocation cell is empty for Res1. If it is a single task, as it is for Res2, then the %-Allocation is correct: 40/168=24%. Why it is not possible to calculate the %-Allocation for Res1?
What I am doing wrong here? Is there a way to get the %-Allocation per project when using a pool of resources?
I would like to get Percent Allocation in Resource Usage, by a specific project when I have a pool of resources and a master project using two simple projects (testP1, testP2) like the following to illustrate the point. I have the following: And I would like to visualize the monthly percent allocation in the Resource Usage view. Considering Sept,2025 which has 168 working hours. I created the following custom group: Group by Projects as follows, to group by project, so I can have the information I am looking for:Note: I followed the answer from Ignacio Marin for this question: MS Project Resource Pool Usage. Then I followed the instructions from this post: View resource workloads and availability in Project desktop to add Percent Allocation in the Detail column of the Resource Usage view. Now using this custom group I would like to get the calculation for %-Allocation for project testP1, so I filter the Project column to select just this project. I am getting the following results: As you can see the result is as expected for Work, but not for % Allocation. For example for Res1 is working 80 hours, so its allocation should be: 80/168=48%, but the allocation cell is empty for Res1. If it is a single task, as it is for Res2, then the %-Allocation is correct: 40/168=24%. Why it is not possible to calculate the %-Allocation for Res1? What I am doing wrong here? Is there a way to get the %-Allocation per project when using a pool of resources? Read More
how to sort dlarrays
How to sort dlarrays like in
sort(a)
, where a is a numeric array? Is there a way of sorting next(mbq) by specifying some options in the following code?
mbq = minibatchqueue(ads,MiniBatchSize=miniBatchSize,MiniBatchFormat="BC");
next(mbq)How to sort dlarrays like in
sort(a)
, where a is a numeric array? Is there a way of sorting next(mbq) by specifying some options in the following code?
mbq = minibatchqueue(ads,MiniBatchSize=miniBatchSize,MiniBatchFormat="BC");
next(mbq) How to sort dlarrays like in
sort(a)
, where a is a numeric array? Is there a way of sorting next(mbq) by specifying some options in the following code?
mbq = minibatchqueue(ads,MiniBatchSize=miniBatchSize,MiniBatchFormat="BC");
next(mbq) deep learning MATLAB Answers — New Questions
What can I do to make the output characteristic of the network is two value, that is the implement multivariate input and multivariable output
I want to change the network structure to achieve that the predicted value of the output is two features. the net work is as follows link, but i can’t realize my idea. please help me, thank you very much. hope you have a nice day!
CNN-LSTM 时间序列预测 Matlab 单变量时间系列 – 文件交换 – MATLAB Central (mathworks.cn)I want to change the network structure to achieve that the predicted value of the output is two features. the net work is as follows link, but i can’t realize my idea. please help me, thank you very much. hope you have a nice day!
CNN-LSTM 时间序列预测 Matlab 单变量时间系列 – 文件交换 – MATLAB Central (mathworks.cn) I want to change the network structure to achieve that the predicted value of the output is two features. the net work is as follows link, but i can’t realize my idea. please help me, thank you very much. hope you have a nice day!
CNN-LSTM 时间序列预测 Matlab 单变量时间系列 – 文件交换 – MATLAB Central (mathworks.cn) neural network, cnn, lstm, signal predict, predict MATLAB Answers — New Questions
Spectrogram output versus figure
When using spectrogram to calculate power spectral density for a large dataset, the plot produced by directly running the command with no output arguments is slightly different from what I get when I run it with an output argument and plot that output myself.
For example, the following plots spectrograms for a subset of my data and compares the direct result of spectrogram with the output raster:
load(‘exampledata.mat’)
window = 10000;
noverlap = round(0.1*window);
fs = 10000;
figure(1);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
% Plot spectrogram directly from spectrogram function
s(1) = nexttile;
spectrogram(exampledata,window,noverlap,window,fs);
title(‘Original spectrogram plot (real data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
% Calculate power spectral density and plot as decibels
[~,F,T,PSD] = spectrogram(exampledata,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (real data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
% Calculate ratio of the two approaches above and plot that
PSDdiff = PSDdB_orig./PSDdB;
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
From the figures above, it looks like they produce nearly the same result, except at high frequencies (the middle figure looks more different than the first mostly due to the different color scales).
Comparing the ranges and plotting a cross-section (example spectra at a single time) from each one shows that the difference seems to be that spectrogram’s direct plotting method is cutting off local minima:
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
% Plot example spectra from each approach
figure(2);clf
subplot(2,1,1);
plot(F./1000,PSDdB(10,:),F./1000,PSDdB_orig(10,:),’–‘);
legend(‘Spectrogram output raster’,’Original spectrogram’)
title(‘Example spectra’)
xlabel(‘Frequency (kHz)’)
ylabel(‘Power/frequency (dB/Hz)’)
% zoom in on high frequency range where values differ
subplot(2,1,2,copyobj(gca,gcf))
xlim([4.75 4.85])
title(‘high frequency close-up’)
But weirdly, I can’t reproduce this with randomly generated synthetic data:
x = randn(length(exampledata),1);
figure(3);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
s(1) = nexttile;
spectrogram(x,window,noverlap,window,fs);
title(‘Original spectrogram plot (synthetic data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
[~,F,T,PSD] = spectrogram(x,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
PSDdiff = PSDdB_orig./PSDdB;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (synthetic data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
I do notice that the minimum PSD value for my data (-196 dB) is significantly lower than the minimum of the synthetic data. Is there a lower limit where spectrogram starts to censor spectra (say, around -156.5351 dB)? Or is something else going on here? Any help would be much appreciated!! Thanks!When using spectrogram to calculate power spectral density for a large dataset, the plot produced by directly running the command with no output arguments is slightly different from what I get when I run it with an output argument and plot that output myself.
For example, the following plots spectrograms for a subset of my data and compares the direct result of spectrogram with the output raster:
load(‘exampledata.mat’)
window = 10000;
noverlap = round(0.1*window);
fs = 10000;
figure(1);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
% Plot spectrogram directly from spectrogram function
s(1) = nexttile;
spectrogram(exampledata,window,noverlap,window,fs);
title(‘Original spectrogram plot (real data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
% Calculate power spectral density and plot as decibels
[~,F,T,PSD] = spectrogram(exampledata,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (real data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
% Calculate ratio of the two approaches above and plot that
PSDdiff = PSDdB_orig./PSDdB;
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
From the figures above, it looks like they produce nearly the same result, except at high frequencies (the middle figure looks more different than the first mostly due to the different color scales).
Comparing the ranges and plotting a cross-section (example spectra at a single time) from each one shows that the difference seems to be that spectrogram’s direct plotting method is cutting off local minima:
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
% Plot example spectra from each approach
figure(2);clf
subplot(2,1,1);
plot(F./1000,PSDdB(10,:),F./1000,PSDdB_orig(10,:),’–‘);
legend(‘Spectrogram output raster’,’Original spectrogram’)
title(‘Example spectra’)
xlabel(‘Frequency (kHz)’)
ylabel(‘Power/frequency (dB/Hz)’)
% zoom in on high frequency range where values differ
subplot(2,1,2,copyobj(gca,gcf))
xlim([4.75 4.85])
title(‘high frequency close-up’)
But weirdly, I can’t reproduce this with randomly generated synthetic data:
x = randn(length(exampledata),1);
figure(3);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
s(1) = nexttile;
spectrogram(x,window,noverlap,window,fs);
title(‘Original spectrogram plot (synthetic data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
[~,F,T,PSD] = spectrogram(x,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
PSDdiff = PSDdB_orig./PSDdB;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (synthetic data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
I do notice that the minimum PSD value for my data (-196 dB) is significantly lower than the minimum of the synthetic data. Is there a lower limit where spectrogram starts to censor spectra (say, around -156.5351 dB)? Or is something else going on here? Any help would be much appreciated!! Thanks! When using spectrogram to calculate power spectral density for a large dataset, the plot produced by directly running the command with no output arguments is slightly different from what I get when I run it with an output argument and plot that output myself.
For example, the following plots spectrograms for a subset of my data and compares the direct result of spectrogram with the output raster:
load(‘exampledata.mat’)
window = 10000;
noverlap = round(0.1*window);
fs = 10000;
figure(1);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
% Plot spectrogram directly from spectrogram function
s(1) = nexttile;
spectrogram(exampledata,window,noverlap,window,fs);
title(‘Original spectrogram plot (real data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
% Calculate power spectral density and plot as decibels
[~,F,T,PSD] = spectrogram(exampledata,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (real data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
% Calculate ratio of the two approaches above and plot that
PSDdiff = PSDdB_orig./PSDdB;
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
From the figures above, it looks like they produce nearly the same result, except at high frequencies (the middle figure looks more different than the first mostly due to the different color scales).
Comparing the ranges and plotting a cross-section (example spectra at a single time) from each one shows that the difference seems to be that spectrogram’s direct plotting method is cutting off local minima:
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
% Plot example spectra from each approach
figure(2);clf
subplot(2,1,1);
plot(F./1000,PSDdB(10,:),F./1000,PSDdB_orig(10,:),’–‘);
legend(‘Spectrogram output raster’,’Original spectrogram’)
title(‘Example spectra’)
xlabel(‘Frequency (kHz)’)
ylabel(‘Power/frequency (dB/Hz)’)
% zoom in on high frequency range where values differ
subplot(2,1,2,copyobj(gca,gcf))
xlim([4.75 4.85])
title(‘high frequency close-up’)
But weirdly, I can’t reproduce this with randomly generated synthetic data:
x = randn(length(exampledata),1);
figure(3);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
s(1) = nexttile;
spectrogram(x,window,noverlap,window,fs);
title(‘Original spectrogram plot (synthetic data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
[~,F,T,PSD] = spectrogram(x,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
PSDdiff = PSDdB_orig./PSDdB;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (synthetic data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
I do notice that the minimum PSD value for my data (-196 dB) is significantly lower than the minimum of the synthetic data. Is there a lower limit where spectrogram starts to censor spectra (say, around -156.5351 dB)? Or is something else going on here? Any help would be much appreciated!! Thanks! spectrogram, spectral analysis, signal processing MATLAB Answers — New Questions