Month: January 2025
How to find volume of a curve [f(x)] which is rotated along y-axis?
We have a input function y = f(x) and we have to find the volume along x-axis and y-axis. (solid of revolution) The minimum and maximum values of x are given
I am getting the volume along x-axis but I am getting an error while finding the volume along the y-axis.
The values of f(x) and domain is : –
x^(1/2), 0<=x<=4
3*cos(0.4*x+pi), -5<=x<=5
sin(x)+3, -5<=x<=5
x^3, 0<=x<=3
Here is my code
%Volume along x-axis
clc
clear all
syms x y
%fx = input(‘Enter the function : ‘)
xmin = input(‘Enter minimum value of x : ‘)
xmax = input(‘Enter maximum value of x : ‘)
intfx = int((fx)^2,xmin,xmax)
vx = pi*(intfx)
vx = double(vx)
sprintf(‘The volume along x-axis is %d’,vx)
%Volume along y-axis
y_fx_equation_wrt_x = y == fx
x_fy_equation_wrt_y = solve(y_fx_equation_wrt_x, x)
fy = x_fy_equation_wrt_y
ymin = subs(fx,x,xmin)
ymax = subs(fx,x,xmax)
intfy = abs(int(fy^2,ymin,ymax))
vy = pi*(intfy)
vyy = double(vy)
sprintf(‘The volume along y-axis is %d’,vyy)
In output 1 I get an error but on output 2 I don’t.
What am I doing wrong?
Output 1
y = 3*cos(0.4*x+pi)
3*cos(0.4*x+pi)
fx =
-3*cos((2*x)/5)
Enter minimum value of x :
-5
xmin =
-5
Enter maximum value of x :
5
xmax =
5
intfx =
(45*sin(4))/4 + 45
vx =
pi*((45*sin(4))/4 + 45)
vx =
114.6241
ans =
‘The volume along x-axis is 1.146241e+02’
y_fx_equation_wrt_x =
y == -3*cos((2*x)/5)
x_fy_equation_wrt_y =
(5*pi)/2 – (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
fy =
(5*pi)/2 – (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
ymin =
-3*cos(2)
ymax =
-3*cos(2)
Error using ^ (line 442)
Matrix must be square.
Error in Week6classwork1_2 (line 35)
intfy = abs(int(fy^2,ymin,ymax))
Output 2
y = x^(0.5)
Enter the function :
x^(0.5)
fx =
x^(1/2)
Enter minimum value of x :
0
xmin =
0
Enter maximum value of x :
4
xmax =
4
intfx =
8
vx =
8*pi
vx =
25.1327
ans =
‘The volume along x-axis is 2.513274e+01’
y_fx_equation_wrt_x =
y == x^(1/2)
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the ‘ReturnConditions’ value as ‘true’.
x_fy_equation_wrt_y =
y^2
fy =
y^2
ymin =
0
ymax =
2
intfy =
32/5
vy =
(32*pi)/5
vyy =
20.1062
ans =
‘The volume along y-axis is 2.010619e+01’We have a input function y = f(x) and we have to find the volume along x-axis and y-axis. (solid of revolution) The minimum and maximum values of x are given
I am getting the volume along x-axis but I am getting an error while finding the volume along the y-axis.
The values of f(x) and domain is : –
x^(1/2), 0<=x<=4
3*cos(0.4*x+pi), -5<=x<=5
sin(x)+3, -5<=x<=5
x^3, 0<=x<=3
Here is my code
%Volume along x-axis
clc
clear all
syms x y
%fx = input(‘Enter the function : ‘)
xmin = input(‘Enter minimum value of x : ‘)
xmax = input(‘Enter maximum value of x : ‘)
intfx = int((fx)^2,xmin,xmax)
vx = pi*(intfx)
vx = double(vx)
sprintf(‘The volume along x-axis is %d’,vx)
%Volume along y-axis
y_fx_equation_wrt_x = y == fx
x_fy_equation_wrt_y = solve(y_fx_equation_wrt_x, x)
fy = x_fy_equation_wrt_y
ymin = subs(fx,x,xmin)
ymax = subs(fx,x,xmax)
intfy = abs(int(fy^2,ymin,ymax))
vy = pi*(intfy)
vyy = double(vy)
sprintf(‘The volume along y-axis is %d’,vyy)
In output 1 I get an error but on output 2 I don’t.
What am I doing wrong?
Output 1
y = 3*cos(0.4*x+pi)
3*cos(0.4*x+pi)
fx =
-3*cos((2*x)/5)
Enter minimum value of x :
-5
xmin =
-5
Enter maximum value of x :
5
xmax =
5
intfx =
(45*sin(4))/4 + 45
vx =
pi*((45*sin(4))/4 + 45)
vx =
114.6241
ans =
‘The volume along x-axis is 1.146241e+02’
y_fx_equation_wrt_x =
y == -3*cos((2*x)/5)
x_fy_equation_wrt_y =
(5*pi)/2 – (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
fy =
(5*pi)/2 – (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
ymin =
-3*cos(2)
ymax =
-3*cos(2)
Error using ^ (line 442)
Matrix must be square.
Error in Week6classwork1_2 (line 35)
intfy = abs(int(fy^2,ymin,ymax))
Output 2
y = x^(0.5)
Enter the function :
x^(0.5)
fx =
x^(1/2)
Enter minimum value of x :
0
xmin =
0
Enter maximum value of x :
4
xmax =
4
intfx =
8
vx =
8*pi
vx =
25.1327
ans =
‘The volume along x-axis is 2.513274e+01’
y_fx_equation_wrt_x =
y == x^(1/2)
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the ‘ReturnConditions’ value as ‘true’.
x_fy_equation_wrt_y =
y^2
fy =
y^2
ymin =
0
ymax =
2
intfy =
32/5
vy =
(32*pi)/5
vyy =
20.1062
ans =
‘The volume along y-axis is 2.010619e+01’ We have a input function y = f(x) and we have to find the volume along x-axis and y-axis. (solid of revolution) The minimum and maximum values of x are given
I am getting the volume along x-axis but I am getting an error while finding the volume along the y-axis.
The values of f(x) and domain is : –
x^(1/2), 0<=x<=4
3*cos(0.4*x+pi), -5<=x<=5
sin(x)+3, -5<=x<=5
x^3, 0<=x<=3
Here is my code
%Volume along x-axis
clc
clear all
syms x y
%fx = input(‘Enter the function : ‘)
xmin = input(‘Enter minimum value of x : ‘)
xmax = input(‘Enter maximum value of x : ‘)
intfx = int((fx)^2,xmin,xmax)
vx = pi*(intfx)
vx = double(vx)
sprintf(‘The volume along x-axis is %d’,vx)
%Volume along y-axis
y_fx_equation_wrt_x = y == fx
x_fy_equation_wrt_y = solve(y_fx_equation_wrt_x, x)
fy = x_fy_equation_wrt_y
ymin = subs(fx,x,xmin)
ymax = subs(fx,x,xmax)
intfy = abs(int(fy^2,ymin,ymax))
vy = pi*(intfy)
vyy = double(vy)
sprintf(‘The volume along y-axis is %d’,vyy)
In output 1 I get an error but on output 2 I don’t.
What am I doing wrong?
Output 1
y = 3*cos(0.4*x+pi)
3*cos(0.4*x+pi)
fx =
-3*cos((2*x)/5)
Enter minimum value of x :
-5
xmin =
-5
Enter maximum value of x :
5
xmax =
5
intfx =
(45*sin(4))/4 + 45
vx =
pi*((45*sin(4))/4 + 45)
vx =
114.6241
ans =
‘The volume along x-axis is 1.146241e+02’
y_fx_equation_wrt_x =
y == -3*cos((2*x)/5)
x_fy_equation_wrt_y =
(5*pi)/2 – (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
fy =
(5*pi)/2 – (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
ymin =
-3*cos(2)
ymax =
-3*cos(2)
Error using ^ (line 442)
Matrix must be square.
Error in Week6classwork1_2 (line 35)
intfy = abs(int(fy^2,ymin,ymax))
Output 2
y = x^(0.5)
Enter the function :
x^(0.5)
fx =
x^(1/2)
Enter minimum value of x :
0
xmin =
0
Enter maximum value of x :
4
xmax =
4
intfx =
8
vx =
8*pi
vx =
25.1327
ans =
‘The volume along x-axis is 2.513274e+01’
y_fx_equation_wrt_x =
y == x^(1/2)
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the ‘ReturnConditions’ value as ‘true’.
x_fy_equation_wrt_y =
y^2
fy =
y^2
ymin =
0
ymax =
2
intfy =
32/5
vy =
(32*pi)/5
vyy =
20.1062
ans =
‘The volume along y-axis is 2.010619e+01’ solid of revolution, volume along y-axis, volume, how MATLAB Answers — New Questions
BER of OFDM QPSK modulated
Hello every one.
AS i have seen in this website. the BER code of OFDM 16-QAM and OFDM BPSK are there
can anyone provide me a link of BER of OFDM QPSK ..Hello every one.
AS i have seen in this website. the BER code of OFDM 16-QAM and OFDM BPSK are there
can anyone provide me a link of BER of OFDM QPSK .. Hello every one.
AS i have seen in this website. the BER code of OFDM 16-QAM and OFDM BPSK are there
can anyone provide me a link of BER of OFDM QPSK .. ber, ofdm, qpsk MATLAB Answers — New Questions
How to create white noise and pink noise ?
I would like to know how to make pink noise and white noise.
I would also like to know how to put the created noise on the acquired tunnel current z.
I own DSP System Toolbox and Signal Processing Toolbox.
%Parameter Setting
pixel_image = 256; %Input the number of pixels in the image obtained by raster scanning (input 2^n)
dr = 1/(2*sqrt(3)); %Enter dither circle radius [grid].
a_fast_grid = 10; %fast axis scanning range [grid]
a_slow_grid = 10; %Slow axis scanning range [grid]
fm=5000; %Dither circle modulation frequency [Hz]
fs= fm * 240 ; %Sampling frequency [Hz]
f_fast = 10.2; %Input scanning frequency [Hz] (1 line scanning count in 1[s])
start_point_x = 0; %Input x-coordinate of scanning start point (input 1 if you want to move by 1[grid])
start_point_y = 0; %Input y-coordinate of scanning start point (input 1 if you want to move by 1[grid])
%Parameter setting for fast-axis triangular wave
amplitude_fast = a_fast_grid/2; %fast axis amplitude
%Parameter setting for slow-axis triangular wave
amplitude_slow = a_slow_grid/2; %slow axis amplitude
f_slow = (f_fast)/(2*pixel_image); %Slow axis triangular wave frequency
% Generation of time vectors
total_time=256/f_fast; %Total Scan Time
t = linspace(0, total_time, fs * total_time);
x_raster = start_point_x + amplitude_fast*(2/pi)*acos(cos(2*pi*f_fast*t));
y_raster = start_point_y + amplitude_slow*(2/pi)*acos(cos(2*pi*f_slow*t));
x_dither = dr*cos(2*pi*fm*t);
y_dither = dr*sin(2*pi*fm*t);
x = x_raster + x_dither;
y = y_raster + y_dither;
z1 = cos(2*pi*((x-y)/(sqrt(3))));
z2 = cos(2*pi*(2*y/(sqrt(3))));
z3 = cos(2*pi*((x+y)/(sqrt(3))));
z = (z1 + z2 + z3);I would like to know how to make pink noise and white noise.
I would also like to know how to put the created noise on the acquired tunnel current z.
I own DSP System Toolbox and Signal Processing Toolbox.
%Parameter Setting
pixel_image = 256; %Input the number of pixels in the image obtained by raster scanning (input 2^n)
dr = 1/(2*sqrt(3)); %Enter dither circle radius [grid].
a_fast_grid = 10; %fast axis scanning range [grid]
a_slow_grid = 10; %Slow axis scanning range [grid]
fm=5000; %Dither circle modulation frequency [Hz]
fs= fm * 240 ; %Sampling frequency [Hz]
f_fast = 10.2; %Input scanning frequency [Hz] (1 line scanning count in 1[s])
start_point_x = 0; %Input x-coordinate of scanning start point (input 1 if you want to move by 1[grid])
start_point_y = 0; %Input y-coordinate of scanning start point (input 1 if you want to move by 1[grid])
%Parameter setting for fast-axis triangular wave
amplitude_fast = a_fast_grid/2; %fast axis amplitude
%Parameter setting for slow-axis triangular wave
amplitude_slow = a_slow_grid/2; %slow axis amplitude
f_slow = (f_fast)/(2*pixel_image); %Slow axis triangular wave frequency
% Generation of time vectors
total_time=256/f_fast; %Total Scan Time
t = linspace(0, total_time, fs * total_time);
x_raster = start_point_x + amplitude_fast*(2/pi)*acos(cos(2*pi*f_fast*t));
y_raster = start_point_y + amplitude_slow*(2/pi)*acos(cos(2*pi*f_slow*t));
x_dither = dr*cos(2*pi*fm*t);
y_dither = dr*sin(2*pi*fm*t);
x = x_raster + x_dither;
y = y_raster + y_dither;
z1 = cos(2*pi*((x-y)/(sqrt(3))));
z2 = cos(2*pi*(2*y/(sqrt(3))));
z3 = cos(2*pi*((x+y)/(sqrt(3))));
z = (z1 + z2 + z3); I would like to know how to make pink noise and white noise.
I would also like to know how to put the created noise on the acquired tunnel current z.
I own DSP System Toolbox and Signal Processing Toolbox.
%Parameter Setting
pixel_image = 256; %Input the number of pixels in the image obtained by raster scanning (input 2^n)
dr = 1/(2*sqrt(3)); %Enter dither circle radius [grid].
a_fast_grid = 10; %fast axis scanning range [grid]
a_slow_grid = 10; %Slow axis scanning range [grid]
fm=5000; %Dither circle modulation frequency [Hz]
fs= fm * 240 ; %Sampling frequency [Hz]
f_fast = 10.2; %Input scanning frequency [Hz] (1 line scanning count in 1[s])
start_point_x = 0; %Input x-coordinate of scanning start point (input 1 if you want to move by 1[grid])
start_point_y = 0; %Input y-coordinate of scanning start point (input 1 if you want to move by 1[grid])
%Parameter setting for fast-axis triangular wave
amplitude_fast = a_fast_grid/2; %fast axis amplitude
%Parameter setting for slow-axis triangular wave
amplitude_slow = a_slow_grid/2; %slow axis amplitude
f_slow = (f_fast)/(2*pixel_image); %Slow axis triangular wave frequency
% Generation of time vectors
total_time=256/f_fast; %Total Scan Time
t = linspace(0, total_time, fs * total_time);
x_raster = start_point_x + amplitude_fast*(2/pi)*acos(cos(2*pi*f_fast*t));
y_raster = start_point_y + amplitude_slow*(2/pi)*acos(cos(2*pi*f_slow*t));
x_dither = dr*cos(2*pi*fm*t);
y_dither = dr*sin(2*pi*fm*t);
x = x_raster + x_dither;
y = y_raster + y_dither;
z1 = cos(2*pi*((x-y)/(sqrt(3))));
z2 = cos(2*pi*(2*y/(sqrt(3))));
z3 = cos(2*pi*((x+y)/(sqrt(3))));
z = (z1 + z2 + z3); pink noise, white noise, signal processing, matlab, noise, dsp system toolbox, signal processing toolbox MATLAB Answers — New Questions
Are there alternatives to Simulink Real-Time byte packing/unpacking blocks for MacOS?
Hello,
I am working on a project where I need Simulink Real-Time byte packing and unpacking blocks to enable real-time communication via Ethernet with a microcontroller. Unfortunately, this library is not available for macOS.
Does anyone know of any alternative solutions or approaches that could work on macOS?
Thank you in advance for your valuable help!Hello,
I am working on a project where I need Simulink Real-Time byte packing and unpacking blocks to enable real-time communication via Ethernet with a microcontroller. Unfortunately, this library is not available for macOS.
Does anyone know of any alternative solutions or approaches that could work on macOS?
Thank you in advance for your valuable help! Hello,
I am working on a project where I need Simulink Real-Time byte packing and unpacking blocks to enable real-time communication via Ethernet with a microcontroller. Unfortunately, this library is not available for macOS.
Does anyone know of any alternative solutions or approaches that could work on macOS?
Thank you in advance for your valuable help! simulink, byte packing, mac MATLAB Answers — New Questions
How do I know, what simplifying steps MATLAB had taken?
I know that using "simplify" command I can simplify my trignometric matrices. But, can we take output on each simplification step that MATLAB takes to simplify the given expression?
I am trying to simplify this:
if true
% clc
clear all
syms o l1 l2 l0;
A=[ cos(o) -sin(o) 1;
cos(o-(2*pi/3)) -sin(o-(2*pi/3)) 1;
cos(o-(4*pi/3)) -sin(o-(4*pi/3)) 1;]
invA= (2/3)*[cos(o) cos(o-2*pi/3) cos(o-4*pi/3);
-sin(o) -sin(o-2*pi/3) -sin(o-4*pi/3);
0.5 0.5 0.5]
Lss = [l0 + ((l2)*cos(2*o)) (-0.5*l1)+((l2)*cos((2*o)-2*pi/3)) (-0.5*l1)+((l2)*cos((2*o)+2*pi/3));
(-0.5*l1)+((l2)*cos((2*o)-2*pi/3)) l0 + ((l2)*cos(2*(o-2*pi/3))) (-0.5*l1)+((l2)*cos(2*o))
(-0.5*l1)+((l2)*cos((2*o)+2*pi/3)) (-0.5*l1)+((l2)*cos((2*o))) l0 + ((l2)*cos(2*(o-4*pi/3)))]
X=(invA)*(Lss)*(A)
W=simplify(X)
end
and the answer comes to be:
if true
% W =[ l0 + l1/2 + (3*l2)/2, 0, 0]
[ 0, l0 + l1/2 – (3*l2)/2, 0]
[ 0, 0, l0 – l1]
end
which is true. But how do MATLAB got there??I know that using "simplify" command I can simplify my trignometric matrices. But, can we take output on each simplification step that MATLAB takes to simplify the given expression?
I am trying to simplify this:
if true
% clc
clear all
syms o l1 l2 l0;
A=[ cos(o) -sin(o) 1;
cos(o-(2*pi/3)) -sin(o-(2*pi/3)) 1;
cos(o-(4*pi/3)) -sin(o-(4*pi/3)) 1;]
invA= (2/3)*[cos(o) cos(o-2*pi/3) cos(o-4*pi/3);
-sin(o) -sin(o-2*pi/3) -sin(o-4*pi/3);
0.5 0.5 0.5]
Lss = [l0 + ((l2)*cos(2*o)) (-0.5*l1)+((l2)*cos((2*o)-2*pi/3)) (-0.5*l1)+((l2)*cos((2*o)+2*pi/3));
(-0.5*l1)+((l2)*cos((2*o)-2*pi/3)) l0 + ((l2)*cos(2*(o-2*pi/3))) (-0.5*l1)+((l2)*cos(2*o))
(-0.5*l1)+((l2)*cos((2*o)+2*pi/3)) (-0.5*l1)+((l2)*cos((2*o))) l0 + ((l2)*cos(2*(o-4*pi/3)))]
X=(invA)*(Lss)*(A)
W=simplify(X)
end
and the answer comes to be:
if true
% W =[ l0 + l1/2 + (3*l2)/2, 0, 0]
[ 0, l0 + l1/2 – (3*l2)/2, 0]
[ 0, 0, l0 – l1]
end
which is true. But how do MATLAB got there?? I know that using "simplify" command I can simplify my trignometric matrices. But, can we take output on each simplification step that MATLAB takes to simplify the given expression?
I am trying to simplify this:
if true
% clc
clear all
syms o l1 l2 l0;
A=[ cos(o) -sin(o) 1;
cos(o-(2*pi/3)) -sin(o-(2*pi/3)) 1;
cos(o-(4*pi/3)) -sin(o-(4*pi/3)) 1;]
invA= (2/3)*[cos(o) cos(o-2*pi/3) cos(o-4*pi/3);
-sin(o) -sin(o-2*pi/3) -sin(o-4*pi/3);
0.5 0.5 0.5]
Lss = [l0 + ((l2)*cos(2*o)) (-0.5*l1)+((l2)*cos((2*o)-2*pi/3)) (-0.5*l1)+((l2)*cos((2*o)+2*pi/3));
(-0.5*l1)+((l2)*cos((2*o)-2*pi/3)) l0 + ((l2)*cos(2*(o-2*pi/3))) (-0.5*l1)+((l2)*cos(2*o))
(-0.5*l1)+((l2)*cos((2*o)+2*pi/3)) (-0.5*l1)+((l2)*cos((2*o))) l0 + ((l2)*cos(2*(o-4*pi/3)))]
X=(invA)*(Lss)*(A)
W=simplify(X)
end
and the answer comes to be:
if true
% W =[ l0 + l1/2 + (3*l2)/2, 0, 0]
[ 0, l0 + l1/2 – (3*l2)/2, 0]
[ 0, 0, l0 – l1]
end
which is true. But how do MATLAB got there?? simplify, steps, taken, what, how MATLAB Answers — New Questions
Simulink Test: mapping problems when using matrix
hello fellow users,
I request help on the toolbox simulink test, i am using a test harness on a simulink model and one of my entries is a matrix that i want to improt from an Excel however the mapping of the matrix to his root inport is stuck on "Failed to map inputs. Make sure the input port data types match with signal data types specified in the input file. Click here for more information on external input mapping."hello fellow users,
I request help on the toolbox simulink test, i am using a test harness on a simulink model and one of my entries is a matrix that i want to improt from an Excel however the mapping of the matrix to his root inport is stuck on "Failed to map inputs. Make sure the input port data types match with signal data types specified in the input file. Click here for more information on external input mapping." hello fellow users,
I request help on the toolbox simulink test, i am using a test harness on a simulink model and one of my entries is a matrix that i want to improt from an Excel however the mapping of the matrix to his root inport is stuck on "Failed to map inputs. Make sure the input port data types match with signal data types specified in the input file. Click here for more information on external input mapping." simulink test MATLAB Answers — New Questions
How to run a fitlm regression for day of the week dummy variables for financial return data
Hi, I am struggling with how to set up my data to run the fitlm function for day of the week dummy variables.
My data that I have set up in a (2500,6) matrix where C1 is the returns data and C2:C6 are column vectors of zeros and ones where C2 – 1 is for Monday C3 – 1 represents tuesday and so on.
My reults are as follows:
Fitlm:
-1.31153554169770 0.953057779050930 -1.37613434413573 0.169037651868845
-0.131905728387301 0.0695763306138066 -1.89584197993226 0.0582218112735167
0.0843907252336952 0.0872037277677016 0.967742175638410 0.333368798643977
0 0 NaN NaN
-0.0247423867293685 0.0984537148158696 -0.251309834023453 0.801617743803277
0.169341528221423 0.0952957370120605 1.77701053091169 0.0758206160733013
0.460051465197619 0.0967773549107878 4.75370984897974 2.23973346792996e-06
How do i correct my input to replace this row of Nan values?Hi, I am struggling with how to set up my data to run the fitlm function for day of the week dummy variables.
My data that I have set up in a (2500,6) matrix where C1 is the returns data and C2:C6 are column vectors of zeros and ones where C2 – 1 is for Monday C3 – 1 represents tuesday and so on.
My reults are as follows:
Fitlm:
-1.31153554169770 0.953057779050930 -1.37613434413573 0.169037651868845
-0.131905728387301 0.0695763306138066 -1.89584197993226 0.0582218112735167
0.0843907252336952 0.0872037277677016 0.967742175638410 0.333368798643977
0 0 NaN NaN
-0.0247423867293685 0.0984537148158696 -0.251309834023453 0.801617743803277
0.169341528221423 0.0952957370120605 1.77701053091169 0.0758206160733013
0.460051465197619 0.0967773549107878 4.75370984897974 2.23973346792996e-06
How do i correct my input to replace this row of Nan values? Hi, I am struggling with how to set up my data to run the fitlm function for day of the week dummy variables.
My data that I have set up in a (2500,6) matrix where C1 is the returns data and C2:C6 are column vectors of zeros and ones where C2 – 1 is for Monday C3 – 1 represents tuesday and so on.
My reults are as follows:
Fitlm:
-1.31153554169770 0.953057779050930 -1.37613434413573 0.169037651868845
-0.131905728387301 0.0695763306138066 -1.89584197993226 0.0582218112735167
0.0843907252336952 0.0872037277677016 0.967742175638410 0.333368798643977
0 0 NaN NaN
-0.0247423867293685 0.0984537148158696 -0.251309834023453 0.801617743803277
0.169341528221423 0.0952957370120605 1.77701053091169 0.0758206160733013
0.460051465197619 0.0967773549107878 4.75370984897974 2.23973346792996e-06
How do i correct my input to replace this row of Nan values? fitlm, regress, dummy variables, dummyvar, regression, nan, financial returns, financial time series, stocks, stock returns MATLAB Answers — New Questions
‘m_map’ Conversion of longitude and latitude coordinates to xy coordinates.
the range of longitude[110 130] latitude[35 42.2]
How to correspond to xy coordinates.x[1 300] y[1 300]
I want to assign values to each coordinate point, so please help me.the range of longitude[110 130] latitude[35 42.2]
How to correspond to xy coordinates.x[1 300] y[1 300]
I want to assign values to each coordinate point, so please help me. the range of longitude[110 130] latitude[35 42.2]
How to correspond to xy coordinates.x[1 300] y[1 300]
I want to assign values to each coordinate point, so please help me. m_map MATLAB Answers — New Questions
How to find GNSS satellite elevation angle from .obs and .nav data?
Trying to find GNSS/ NavIC satellite elevation angle from obs and nav dataTrying to find GNSS/ NavIC satellite elevation angle from obs and nav data Trying to find GNSS/ NavIC satellite elevation angle from obs and nav data gnss, elevation angle, calculation, .obs, .nav MATLAB Answers — New Questions
How can I use fitdist function
Hello,
I tried to use the function fitdist. The only result is an error:
Undefined function ‘fitdist’ for input arguments of type ‘double’.
Error in FitaNormalDistributiontoDataExample (line 13)
pd = fitdist(x,’Normal’)
This was the result of running the code from help file: C:Users…DocumentsMATLABExamplesFitaNormalDistributiontoDataExampleFitaNormalDistributiontoDataExample.m
%% Fit a Normal Distribution to Data
% Copyright 2015 The MathWorks, Inc.
%%
% Load the sample data. Create a vector containing the patients’ weight data.
load hospital
x = hospital.Weight;
%%
% Create a normal distribution object by fitting it to the data.
pd = fitdist(x,’Normal’)
%%
% Plot the pdf of the distribution.
x_values = 50:1:250;
y = pdf(pd,x_values);
plot(x_values,y,’LineWidth’,2)
What is wrong here?Hello,
I tried to use the function fitdist. The only result is an error:
Undefined function ‘fitdist’ for input arguments of type ‘double’.
Error in FitaNormalDistributiontoDataExample (line 13)
pd = fitdist(x,’Normal’)
This was the result of running the code from help file: C:Users…DocumentsMATLABExamplesFitaNormalDistributiontoDataExampleFitaNormalDistributiontoDataExample.m
%% Fit a Normal Distribution to Data
% Copyright 2015 The MathWorks, Inc.
%%
% Load the sample data. Create a vector containing the patients’ weight data.
load hospital
x = hospital.Weight;
%%
% Create a normal distribution object by fitting it to the data.
pd = fitdist(x,’Normal’)
%%
% Plot the pdf of the distribution.
x_values = 50:1:250;
y = pdf(pd,x_values);
plot(x_values,y,’LineWidth’,2)
What is wrong here? Hello,
I tried to use the function fitdist. The only result is an error:
Undefined function ‘fitdist’ for input arguments of type ‘double’.
Error in FitaNormalDistributiontoDataExample (line 13)
pd = fitdist(x,’Normal’)
This was the result of running the code from help file: C:Users…DocumentsMATLABExamplesFitaNormalDistributiontoDataExampleFitaNormalDistributiontoDataExample.m
%% Fit a Normal Distribution to Data
% Copyright 2015 The MathWorks, Inc.
%%
% Load the sample data. Create a vector containing the patients’ weight data.
load hospital
x = hospital.Weight;
%%
% Create a normal distribution object by fitting it to the data.
pd = fitdist(x,’Normal’)
%%
% Plot the pdf of the distribution.
x_values = 50:1:250;
y = pdf(pd,x_values);
plot(x_values,y,’LineWidth’,2)
What is wrong here? fitdist error MATLAB Answers — New Questions
Problem Saving UIFigures when running in parallel
Attempts to save UIFigure inside a parfor loop using getframe or exportgraphics dont seem to work. Returning the error that these functions cant be used in nodisplay mode. I rely on a 3rd party function ft_topoplot_er to plot certain topographs on my UIFigure and save the resulting video, but these calls take some time done sequentially, so I wished to parallelise them using parfor yet I’m unable to do so.Attempts to save UIFigure inside a parfor loop using getframe or exportgraphics dont seem to work. Returning the error that these functions cant be used in nodisplay mode. I rely on a 3rd party function ft_topoplot_er to plot certain topographs on my UIFigure and save the resulting video, but these calls take some time done sequentially, so I wished to parallelise them using parfor yet I’m unable to do so. Attempts to save UIFigure inside a parfor loop using getframe or exportgraphics dont seem to work. Returning the error that these functions cant be used in nodisplay mode. I rely on a 3rd party function ft_topoplot_er to plot certain topographs on my UIFigure and save the resulting video, but these calls take some time done sequentially, so I wished to parallelise them using parfor yet I’m unable to do so. parfor, uifigure, videowriter MATLAB Answers — New Questions
How many colors with their name present in the image.
I am looking for a way to find the number and name of certain colors present in the image so that I can use them to count for each pixel. I am doing it but actually some other colors or can say mixed colors are also present in the image which when I count are left in the counting and it counts less and as I increase the size of image pixels the uncounted number increase. I am giving the color ranges for the visible 13 colors in the image but their are some other colors present too which I am missing. How can I find them? Thanks in advane for the help, I am stuck with the problem since long time. My image isI am looking for a way to find the number and name of certain colors present in the image so that I can use them to count for each pixel. I am doing it but actually some other colors or can say mixed colors are also present in the image which when I count are left in the counting and it counts less and as I increase the size of image pixels the uncounted number increase. I am giving the color ranges for the visible 13 colors in the image but their are some other colors present too which I am missing. How can I find them? Thanks in advane for the help, I am stuck with the problem since long time. My image is I am looking for a way to find the number and name of certain colors present in the image so that I can use them to count for each pixel. I am doing it but actually some other colors or can say mixed colors are also present in the image which when I count are left in the counting and it counts less and as I increase the size of image pixels the uncounted number increase. I am giving the color ranges for the visible 13 colors in the image but their are some other colors present too which I am missing. How can I find them? Thanks in advane for the help, I am stuck with the problem since long time. My image is all colors number and name, color detection, all unique colors name and count in the image MATLAB Answers — New Questions
How do i connect matlab ui with simulink
i created matlab gui and the simulink model i want it to be combine how can i do those thinki created matlab gui and the simulink model i want it to be combine how can i do those think i created matlab gui and the simulink model i want it to be combine how can i do those think matlab ui, simulink MATLAB Answers — New Questions
Slow initialization at startup during the “Ready” step
I have installed Matlab R2024b on a Kubuntu 24.10 system. I installed only Matlab without an Add-ons and had no trouble during installation. Starting the program results in a long initialization time. I tracked the initialization process with the -timing flag. This results in the following output:
MATLAB Startup Performance Metrics (In Seconds)
total item gap description
=========================================================
0.47 0.47 0.00 MATLAB script
0.66 0.20 -0.00 main
0.71 0.05 0.00 Session Initialize
1.99 0.01 1.27 Toolbox cache load Start
1.99 0.44 0.84 Session Initialize
2.33 0.34 1.99 cachepath
2.50 0.11 2.38 LM Startup
2.60 0.10 0.00 splash
3.03 0.20 0.23 Constant Initialization
3.33 0.73 0.00 Engine Startup
3.52 0.20 0.00 InitSunVM
5.01 1.43 0.06 PostVMInit
5.01 1.68 0.00 mljInit
5.72 0.71 0.00 StartDesktop
5.72 2.39 0.00 Java initialization
5.72 0.00 0.00 psParser
5.72 0.00 0.00 Toolbox cache join
5.74 0.01 0.00 Package Registry initialization
6.17 0.21 0.22 matlabpath
7.08 0.19 0.72 matlabrc
7.09 0.00 0.00 Startup File
9.27 3.55 5.72 Init Desktop
217.84 212.12 5.72 Ready
=========================================================
Items shown account for 99.8% of total startup time
As visible, the last step consumes most of the time. Running the program bare with the -nojvm flag results in a quick start (3.92 s) . I already tried to increase the Java Memory heap space, as suggested in https://de.mathworks.com/matlabcentral/answers/1956139-slow-java-initialization-during-startup and tried several solutions from https://de.mathworks.com/matlabcentral/answers/92566-why-does-matlab-get-stuck-in-the-initializing-or-busy-state-or-take-a-long-time-to-start without improving the starting time.
Thanks in advance for any ideas how to resolve this issue.I have installed Matlab R2024b on a Kubuntu 24.10 system. I installed only Matlab without an Add-ons and had no trouble during installation. Starting the program results in a long initialization time. I tracked the initialization process with the -timing flag. This results in the following output:
MATLAB Startup Performance Metrics (In Seconds)
total item gap description
=========================================================
0.47 0.47 0.00 MATLAB script
0.66 0.20 -0.00 main
0.71 0.05 0.00 Session Initialize
1.99 0.01 1.27 Toolbox cache load Start
1.99 0.44 0.84 Session Initialize
2.33 0.34 1.99 cachepath
2.50 0.11 2.38 LM Startup
2.60 0.10 0.00 splash
3.03 0.20 0.23 Constant Initialization
3.33 0.73 0.00 Engine Startup
3.52 0.20 0.00 InitSunVM
5.01 1.43 0.06 PostVMInit
5.01 1.68 0.00 mljInit
5.72 0.71 0.00 StartDesktop
5.72 2.39 0.00 Java initialization
5.72 0.00 0.00 psParser
5.72 0.00 0.00 Toolbox cache join
5.74 0.01 0.00 Package Registry initialization
6.17 0.21 0.22 matlabpath
7.08 0.19 0.72 matlabrc
7.09 0.00 0.00 Startup File
9.27 3.55 5.72 Init Desktop
217.84 212.12 5.72 Ready
=========================================================
Items shown account for 99.8% of total startup time
As visible, the last step consumes most of the time. Running the program bare with the -nojvm flag results in a quick start (3.92 s) . I already tried to increase the Java Memory heap space, as suggested in https://de.mathworks.com/matlabcentral/answers/1956139-slow-java-initialization-during-startup and tried several solutions from https://de.mathworks.com/matlabcentral/answers/92566-why-does-matlab-get-stuck-in-the-initializing-or-busy-state-or-take-a-long-time-to-start without improving the starting time.
Thanks in advance for any ideas how to resolve this issue. I have installed Matlab R2024b on a Kubuntu 24.10 system. I installed only Matlab without an Add-ons and had no trouble during installation. Starting the program results in a long initialization time. I tracked the initialization process with the -timing flag. This results in the following output:
MATLAB Startup Performance Metrics (In Seconds)
total item gap description
=========================================================
0.47 0.47 0.00 MATLAB script
0.66 0.20 -0.00 main
0.71 0.05 0.00 Session Initialize
1.99 0.01 1.27 Toolbox cache load Start
1.99 0.44 0.84 Session Initialize
2.33 0.34 1.99 cachepath
2.50 0.11 2.38 LM Startup
2.60 0.10 0.00 splash
3.03 0.20 0.23 Constant Initialization
3.33 0.73 0.00 Engine Startup
3.52 0.20 0.00 InitSunVM
5.01 1.43 0.06 PostVMInit
5.01 1.68 0.00 mljInit
5.72 0.71 0.00 StartDesktop
5.72 2.39 0.00 Java initialization
5.72 0.00 0.00 psParser
5.72 0.00 0.00 Toolbox cache join
5.74 0.01 0.00 Package Registry initialization
6.17 0.21 0.22 matlabpath
7.08 0.19 0.72 matlabrc
7.09 0.00 0.00 Startup File
9.27 3.55 5.72 Init Desktop
217.84 212.12 5.72 Ready
=========================================================
Items shown account for 99.8% of total startup time
As visible, the last step consumes most of the time. Running the program bare with the -nojvm flag results in a quick start (3.92 s) . I already tried to increase the Java Memory heap space, as suggested in https://de.mathworks.com/matlabcentral/answers/1956139-slow-java-initialization-during-startup and tried several solutions from https://de.mathworks.com/matlabcentral/answers/92566-why-does-matlab-get-stuck-in-the-initializing-or-busy-state-or-take-a-long-time-to-start without improving the starting time.
Thanks in advance for any ideas how to resolve this issue. initializing, installation, linux, startup time MATLAB Answers — New Questions
Primer: Running Audit Searches and Sending Email from Azure Automation
Use Azure Automation for Audit Searches
In the past, I published articles covering the basics of using Azure Automation to process Microsoft 365 data. The articles cover the basics of using an automation account to execute runbooks (PowerShell scripts based on the Microsoft Graph PowerShell SDK), how to output results to a SharePoint Online list, and how to attach runbooks to automation schedules to make sure that processes execute automatically and reliably.
This article covers how to execute Microsoft 365 audit searches in runbooks and how to send the results extracted from the audit searches via email. I’m going to use the scenario discussed on 24 January about a flaw found in Entra ID that allowed users to change their user principal names. Microsoft has since addressed the problem, but the fact still remains that changes to user principal names can have consequences for services other than authentication. Any change like this deserves oversight. The purpose is to explore the principles rather than the details of a solution, and the techniques used here can be applied to any audit log search.
Basic Outline to Create a Runbook for a Microsoft 365 Audit Search
Two methods are available to search the unified audit log.
- Synchronous searches performed by the Search-UnifiedAuditLog cmdlet from the Exchange Online module.
- Asynchronous searches performed by the AuditLogQuery Graph API. The API is in still in beta but it’s how the Purview Audit search solution works. SDK cmdlets are also available for the API.
Opting for the Graph API makes sense for an Azure Automation job. Asynchronous searches take longer but that doesn’t matter when the job executes in the background, especially if it’s a scheduled run. In terms of the code, Microsoft has temporarily withdrawn the Get-MgBetaSecurityAuditLogQuery cmdlet and the Get-MgBetaSecurityAuditLogQueryRecord sometimes doesn’t work, so we use Graph API requests in this example. I used V2.25 of the Graph SDK and the cmdlets might have returned by the time you read this text.
The basic processing steps are:
- Construct the parameters for the audit log search. The Update User operation captures changes made to user accounts, so that’s what the search looks for over the last seven days.
- Submit the search and monitor its progress until completion.
- Retrieve the audit records.
- Process the audit records to check if any are for changes to the userPrincipalName property and capture details of these events.
- Create a HTML fragment containing the events and use it to create the HTML content for a message.
- Run the Send-MgUserMail cmdlet to send the message to a predetermined recipient. This can be any valid email address. In production, it’s likely that the recipient would be a distribution list, but it could be a Microsoft 365 group, or even a Teams channel.
Testing the Runbook for a Microsoft 365 Audit Search
As always, it’s wise to test the runbook code by running it interactively in a Microsoft Graph PowerShell SDK session. The automation account must have the AuditLogsQuery.Read.All application permission to access audit logs and Mail.Send to be able to send email. See my earlier post for how to assign Graph permissions to automation accounts. In production scenarios, you should use RBAC for Applications to restrict access for the automation account to specific mailboxes.
To mimic what happens when Azure Automation executes the runbook, use an app-only session by signing in with an app identifier, tenant identifier, and a certificate uploaded to the app. The app must have consent to use the two permissions listed above. Once everything works interactively, copy the code and create a new Azure Automation runbook and test that the code runs in that environment (Figure 1).

When everything checks out, you can register the runbook with an automation schedule. This check is a good example of something that should be done bi-weekly. Of course, what the recipients do when they receive the message (Figure 2) is up to them.

Better than Microsoft 365 Audit Policies?
Similar functionality in terms of sending email notifications for events found by Microsoft 365 audit searches available through Microsoft 365 audit policies. The reason why a DIY version might be preferable is that you have full control over the content presented in messages and the advice given to recipients, plus any associated processing you might want to do. For instance, you could log the highlighted audit events in a SharePoint Online list and require administrators to attest that they checked each event to make sure that it’s appropriate. That might be too much, but it’s possible.
The code I used for testing can be downloaded from the Office 365 for IT Pros GitHub repository.
Insight like this doesn’t come easily. You’ve got to know the technology and understand how to look behind the scenes. Benefit from the knowledge and experience of the Office 365 for IT Pros team by subscribing to the best eBook covering Office 365 and the wider Microsoft 365 ecosystem.
Hardware Setup for C2000″ – Unable to Proceed After Selecting Process Family
Hey!
I am encountering an issue while performing the hardware setup for C2000 in MATLAB. Below are the details of the problem:
Setup Step:I am at the step where I need to select the process family for C2000 hardware setup.
Observed Issue: *After selecting the process family (e.g., C2000), the setup page is maximized, and I cannot proceed further. *The "Next" or "Proceed" button is either not visible or unresponsive.
Expected Behavior:After selecting the process family, I should be able to click "Next" or "Proceed" to move to the next step.
Steps Tried:
Resized the window manually.
Tried restarting MATLAB and redoing the hardware setup.
Checked for updates or patches related to MATLAB or C2000.
Can anyone guide me on how to resolve this issue? Any suggestions or troubleshooting steps would be greatly appreciated.
Thank you.Hey!
I am encountering an issue while performing the hardware setup for C2000 in MATLAB. Below are the details of the problem:
Setup Step:I am at the step where I need to select the process family for C2000 hardware setup.
Observed Issue: *After selecting the process family (e.g., C2000), the setup page is maximized, and I cannot proceed further. *The "Next" or "Proceed" button is either not visible or unresponsive.
Expected Behavior:After selecting the process family, I should be able to click "Next" or "Proceed" to move to the next step.
Steps Tried:
Resized the window manually.
Tried restarting MATLAB and redoing the hardware setup.
Checked for updates or patches related to MATLAB or C2000.
Can anyone guide me on how to resolve this issue? Any suggestions or troubleshooting steps would be greatly appreciated.
Thank you. Hey!
I am encountering an issue while performing the hardware setup for C2000 in MATLAB. Below are the details of the problem:
Setup Step:I am at the step where I need to select the process family for C2000 hardware setup.
Observed Issue: *After selecting the process family (e.g., C2000), the setup page is maximized, and I cannot proceed further. *The "Next" or "Proceed" button is either not visible or unresponsive.
Expected Behavior:After selecting the process family, I should be able to click "Next" or "Proceed" to move to the next step.
Steps Tried:
Resized the window manually.
Tried restarting MATLAB and redoing the hardware setup.
Checked for updates or patches related to MATLAB or C2000.
Can anyone guide me on how to resolve this issue? Any suggestions or troubleshooting steps would be greatly appreciated.
Thank you. c2000, hardware setup, f28p55x, microcontroller MATLAB Answers — New Questions
How to retain a program that has be trained by Radial Basis Function?
Hello every one
i made and trained a program using the nntool, i used the Radial Basis Function as a training algorithim. the results were good but i want them with better accuracy, is there any way to change the settings of the fucntion to give better answers, also can i get some details of the trained program such as: no. of iterations, error plot and etc.
thank youHello every one
i made and trained a program using the nntool, i used the Radial Basis Function as a training algorithim. the results were good but i want them with better accuracy, is there any way to change the settings of the fucntion to give better answers, also can i get some details of the trained program such as: no. of iterations, error plot and etc.
thank you Hello every one
i made and trained a program using the nntool, i used the Radial Basis Function as a training algorithim. the results were good but i want them with better accuracy, is there any way to change the settings of the fucntion to give better answers, also can i get some details of the trained program such as: no. of iterations, error plot and etc.
thank you radial basis function, ann MATLAB Answers — New Questions
Trying to use audiorecorder for impulse response testing in a for loop
Hi everyone,
I’m trying to test the impulse response of a microphone that i have attached to a rotary device connected to an arduino board. Basically trying to automate getting the impulse response at different angles. Thing is, I can’t get the audiorecorder function to work properly within the for loop. It only gives me the impulse response for the final iteration. The rest has no values.
Goal is to play a white noise, record the data from mic using audiorecorder, do my ffts and iffts for impulse response, rotate by a certain angle and repeat the process.
My code is below. Any help would be greatly appreciated because I’m at a complete standstill on what to do here.
close all
clear all
% Parameters
fs = 44100; % Sampling frequency
dur = 30; % Duration of recording in seconds
dt = 1/fs; % Time step
% Create time vector for plotting
time = 0:dt:dur-dt;
% Generate white noise for the entire duration
noise=randn(dur*fs,1);
ramp_up = 0:0.01:1;
ramp_up=ramp_up’;
ramp_down= 1:-0.01:0;
ramp_down=ramp_down’;
noise(1:length(ramp_up))=noise(1:length(ramp_up)).*ramp_up;
noise(end-length(ramp_down)+1:end)=noise(end-length(ramp_down)+1:end).*ramp_down;
noise=noise./max(noise);
recObj = audiorecorder(fs, 24, 2, 2);
%Arduino Setup
clear dcm sm shield a;
a = arduino(‘COM5′,’Uno’,’Libraries’,’AdafruitMotorShieldV2′);
shield = addon(a,’AdafruitMotorShieldV2′);
addrs = scanI2CBus(a,0);
sm = stepper(shield,2,200);
sm.RPM = 3;
Angle = 45; %Rotation Angle
n_rot = 180 / Angle; %Number of Rotations
IM_L=1000; % Truncated impulse response length in number of data points
LS_IR=zeros(n_rot,IM_L);
nfft = 96000; % FFT size
df = fs / nfft; % Frequency resolution
faxis = df:df:nfft*df; % Frequency axis
nFreq=length(faxis);
%Initializing data storage
nSamples = fs * dur;
allData_mic = zeros(nSamples, n_rot);
allData_spk = zeros(nSamples,n_rot);
allIR = zeros(nFreq, n_rot);
allIR_trunc=zeros(IM_L, n_rot);
allfrf=zeros(nFreq/2,n_rot);
allfrf_trunc=zeros(IM_L,n_rot);
%for i = 1:1
for i = 1:n_rot+1
%recording
sound(noise, fs);
% Record two-channel microphone input (24-bit, 2 channels)
recordblocking(recObj, dur); % Record for specified duration
% Get recorded data (two channels)
recordedData = getaudiodata(recObj);
spkinput = recordedData(:, 1); % First channel: Speaker
microphoneInput = recordedData(:, 2); % Second channel: Microphone
microphoneInput = microphoneInput./0.0462;%Left Ear (Fixed)
%microphoneInput = microphoneInput./0.0630;%Right Ear
%% FFT
nav = floor(length(spkinput) / nfft) * 2 – 1; % Number of averages
% Initialize accumulators for power spectral densities and cross-spectral density
G1 = zeros(nfft, 1); % Power Spectral Density of Speaker
G2 = zeros(nfft, 1); % Power Spectral Density of Microphone
G12 = zeros(nfft, 1); % Cross-Spectral Density between Microphone 1 and Microphone 2
G21 = zeros(nfft, 1);
% Loop through the signal with 50% overlap and apply FFT
for i = 1:nav
p1 = 1 + nfft * (i – 1) * 0.5; % Start index for the current block
p2 = p1 + nfft-1; % End index for the current block
% Apply Hann window to the blocks
win=hann(length(spkinput(p1:p2))); % Create a Hann window for the current segment
% Applying windows to blocks
spk_win = win.*spkinput(p1:p2); % Mic1 input
mic_win = win.*microphoneInput(p1:p2); % Mic2 input
% FFT of the windowed blocks
Xf = fft(spk_win, nfft); % FFT of Mic1
Yf = fft(mic_win, nfft); % FFT of Mic2
G1 = G1 + Xf .* conj(Xf); % PSD of Speaker input
G2 = G2 + Yf .* conj(Yf); % PSD of Microphone recording
G12 = G12 + Xf .* conj(Yf); % CSD between Microphone and Speaker
G21=G21 + Yf.*conj(Xf);
end
G1 = 2*G1(1:nfft/2)./(nfft*nfft*nav);
G2 = 2*G2(1:nfft/2)./(nfft*nfft*nav);
G12 = 2*G12(1:nfft/2)./(nfft*nfft*nav);
G21 = 2*G21(1:nfft/2)./(nfft*nfft*nav);
% Compute Coherence Function
coherence = abs(G21).^2 ./ (G1 .* G2);
% Compute Frequency Response Function (FRF)
frf = G2./G12; % FRF
magdB=20*log10(abs(frf));
%% Impulse Response
IR = ifft(frf,nfft);
IR_trunc=IR(1:IM_L);
%impulse_time = (0:nfft-1) * dt;
% n_samp=length(frf);
% impulse_time= 0:dt:(length(microphoneInput1)-1)*dt;
%store everything to the two vectors made above
allData_spk(:, i) = spkinput;
allData_mic(:, i) = microphoneInput;
allIR (:,i) = IR;
allIR_trunc (:,i)= IR_trunc;
allfrf (:,i) = frf;
filenameOut = sprintf(‘HeadTesting_Baseline_27Jan_%ddeg.mat’, ((i-1)*5));
%Movement———–
% – moves it to the left (counterclockwise) (standing behind it)
% + moves it to the right (clockwise) (stangind behind it)
if i~=n_rot+1
move(sm, +50*Angle);
end
end
clear dcm sm shield a;Hi everyone,
I’m trying to test the impulse response of a microphone that i have attached to a rotary device connected to an arduino board. Basically trying to automate getting the impulse response at different angles. Thing is, I can’t get the audiorecorder function to work properly within the for loop. It only gives me the impulse response for the final iteration. The rest has no values.
Goal is to play a white noise, record the data from mic using audiorecorder, do my ffts and iffts for impulse response, rotate by a certain angle and repeat the process.
My code is below. Any help would be greatly appreciated because I’m at a complete standstill on what to do here.
close all
clear all
% Parameters
fs = 44100; % Sampling frequency
dur = 30; % Duration of recording in seconds
dt = 1/fs; % Time step
% Create time vector for plotting
time = 0:dt:dur-dt;
% Generate white noise for the entire duration
noise=randn(dur*fs,1);
ramp_up = 0:0.01:1;
ramp_up=ramp_up’;
ramp_down= 1:-0.01:0;
ramp_down=ramp_down’;
noise(1:length(ramp_up))=noise(1:length(ramp_up)).*ramp_up;
noise(end-length(ramp_down)+1:end)=noise(end-length(ramp_down)+1:end).*ramp_down;
noise=noise./max(noise);
recObj = audiorecorder(fs, 24, 2, 2);
%Arduino Setup
clear dcm sm shield a;
a = arduino(‘COM5′,’Uno’,’Libraries’,’AdafruitMotorShieldV2′);
shield = addon(a,’AdafruitMotorShieldV2′);
addrs = scanI2CBus(a,0);
sm = stepper(shield,2,200);
sm.RPM = 3;
Angle = 45; %Rotation Angle
n_rot = 180 / Angle; %Number of Rotations
IM_L=1000; % Truncated impulse response length in number of data points
LS_IR=zeros(n_rot,IM_L);
nfft = 96000; % FFT size
df = fs / nfft; % Frequency resolution
faxis = df:df:nfft*df; % Frequency axis
nFreq=length(faxis);
%Initializing data storage
nSamples = fs * dur;
allData_mic = zeros(nSamples, n_rot);
allData_spk = zeros(nSamples,n_rot);
allIR = zeros(nFreq, n_rot);
allIR_trunc=zeros(IM_L, n_rot);
allfrf=zeros(nFreq/2,n_rot);
allfrf_trunc=zeros(IM_L,n_rot);
%for i = 1:1
for i = 1:n_rot+1
%recording
sound(noise, fs);
% Record two-channel microphone input (24-bit, 2 channels)
recordblocking(recObj, dur); % Record for specified duration
% Get recorded data (two channels)
recordedData = getaudiodata(recObj);
spkinput = recordedData(:, 1); % First channel: Speaker
microphoneInput = recordedData(:, 2); % Second channel: Microphone
microphoneInput = microphoneInput./0.0462;%Left Ear (Fixed)
%microphoneInput = microphoneInput./0.0630;%Right Ear
%% FFT
nav = floor(length(spkinput) / nfft) * 2 – 1; % Number of averages
% Initialize accumulators for power spectral densities and cross-spectral density
G1 = zeros(nfft, 1); % Power Spectral Density of Speaker
G2 = zeros(nfft, 1); % Power Spectral Density of Microphone
G12 = zeros(nfft, 1); % Cross-Spectral Density between Microphone 1 and Microphone 2
G21 = zeros(nfft, 1);
% Loop through the signal with 50% overlap and apply FFT
for i = 1:nav
p1 = 1 + nfft * (i – 1) * 0.5; % Start index for the current block
p2 = p1 + nfft-1; % End index for the current block
% Apply Hann window to the blocks
win=hann(length(spkinput(p1:p2))); % Create a Hann window for the current segment
% Applying windows to blocks
spk_win = win.*spkinput(p1:p2); % Mic1 input
mic_win = win.*microphoneInput(p1:p2); % Mic2 input
% FFT of the windowed blocks
Xf = fft(spk_win, nfft); % FFT of Mic1
Yf = fft(mic_win, nfft); % FFT of Mic2
G1 = G1 + Xf .* conj(Xf); % PSD of Speaker input
G2 = G2 + Yf .* conj(Yf); % PSD of Microphone recording
G12 = G12 + Xf .* conj(Yf); % CSD between Microphone and Speaker
G21=G21 + Yf.*conj(Xf);
end
G1 = 2*G1(1:nfft/2)./(nfft*nfft*nav);
G2 = 2*G2(1:nfft/2)./(nfft*nfft*nav);
G12 = 2*G12(1:nfft/2)./(nfft*nfft*nav);
G21 = 2*G21(1:nfft/2)./(nfft*nfft*nav);
% Compute Coherence Function
coherence = abs(G21).^2 ./ (G1 .* G2);
% Compute Frequency Response Function (FRF)
frf = G2./G12; % FRF
magdB=20*log10(abs(frf));
%% Impulse Response
IR = ifft(frf,nfft);
IR_trunc=IR(1:IM_L);
%impulse_time = (0:nfft-1) * dt;
% n_samp=length(frf);
% impulse_time= 0:dt:(length(microphoneInput1)-1)*dt;
%store everything to the two vectors made above
allData_spk(:, i) = spkinput;
allData_mic(:, i) = microphoneInput;
allIR (:,i) = IR;
allIR_trunc (:,i)= IR_trunc;
allfrf (:,i) = frf;
filenameOut = sprintf(‘HeadTesting_Baseline_27Jan_%ddeg.mat’, ((i-1)*5));
%Movement———–
% – moves it to the left (counterclockwise) (standing behind it)
% + moves it to the right (clockwise) (stangind behind it)
if i~=n_rot+1
move(sm, +50*Angle);
end
end
clear dcm sm shield a; Hi everyone,
I’m trying to test the impulse response of a microphone that i have attached to a rotary device connected to an arduino board. Basically trying to automate getting the impulse response at different angles. Thing is, I can’t get the audiorecorder function to work properly within the for loop. It only gives me the impulse response for the final iteration. The rest has no values.
Goal is to play a white noise, record the data from mic using audiorecorder, do my ffts and iffts for impulse response, rotate by a certain angle and repeat the process.
My code is below. Any help would be greatly appreciated because I’m at a complete standstill on what to do here.
close all
clear all
% Parameters
fs = 44100; % Sampling frequency
dur = 30; % Duration of recording in seconds
dt = 1/fs; % Time step
% Create time vector for plotting
time = 0:dt:dur-dt;
% Generate white noise for the entire duration
noise=randn(dur*fs,1);
ramp_up = 0:0.01:1;
ramp_up=ramp_up’;
ramp_down= 1:-0.01:0;
ramp_down=ramp_down’;
noise(1:length(ramp_up))=noise(1:length(ramp_up)).*ramp_up;
noise(end-length(ramp_down)+1:end)=noise(end-length(ramp_down)+1:end).*ramp_down;
noise=noise./max(noise);
recObj = audiorecorder(fs, 24, 2, 2);
%Arduino Setup
clear dcm sm shield a;
a = arduino(‘COM5′,’Uno’,’Libraries’,’AdafruitMotorShieldV2′);
shield = addon(a,’AdafruitMotorShieldV2′);
addrs = scanI2CBus(a,0);
sm = stepper(shield,2,200);
sm.RPM = 3;
Angle = 45; %Rotation Angle
n_rot = 180 / Angle; %Number of Rotations
IM_L=1000; % Truncated impulse response length in number of data points
LS_IR=zeros(n_rot,IM_L);
nfft = 96000; % FFT size
df = fs / nfft; % Frequency resolution
faxis = df:df:nfft*df; % Frequency axis
nFreq=length(faxis);
%Initializing data storage
nSamples = fs * dur;
allData_mic = zeros(nSamples, n_rot);
allData_spk = zeros(nSamples,n_rot);
allIR = zeros(nFreq, n_rot);
allIR_trunc=zeros(IM_L, n_rot);
allfrf=zeros(nFreq/2,n_rot);
allfrf_trunc=zeros(IM_L,n_rot);
%for i = 1:1
for i = 1:n_rot+1
%recording
sound(noise, fs);
% Record two-channel microphone input (24-bit, 2 channels)
recordblocking(recObj, dur); % Record for specified duration
% Get recorded data (two channels)
recordedData = getaudiodata(recObj);
spkinput = recordedData(:, 1); % First channel: Speaker
microphoneInput = recordedData(:, 2); % Second channel: Microphone
microphoneInput = microphoneInput./0.0462;%Left Ear (Fixed)
%microphoneInput = microphoneInput./0.0630;%Right Ear
%% FFT
nav = floor(length(spkinput) / nfft) * 2 – 1; % Number of averages
% Initialize accumulators for power spectral densities and cross-spectral density
G1 = zeros(nfft, 1); % Power Spectral Density of Speaker
G2 = zeros(nfft, 1); % Power Spectral Density of Microphone
G12 = zeros(nfft, 1); % Cross-Spectral Density between Microphone 1 and Microphone 2
G21 = zeros(nfft, 1);
% Loop through the signal with 50% overlap and apply FFT
for i = 1:nav
p1 = 1 + nfft * (i – 1) * 0.5; % Start index for the current block
p2 = p1 + nfft-1; % End index for the current block
% Apply Hann window to the blocks
win=hann(length(spkinput(p1:p2))); % Create a Hann window for the current segment
% Applying windows to blocks
spk_win = win.*spkinput(p1:p2); % Mic1 input
mic_win = win.*microphoneInput(p1:p2); % Mic2 input
% FFT of the windowed blocks
Xf = fft(spk_win, nfft); % FFT of Mic1
Yf = fft(mic_win, nfft); % FFT of Mic2
G1 = G1 + Xf .* conj(Xf); % PSD of Speaker input
G2 = G2 + Yf .* conj(Yf); % PSD of Microphone recording
G12 = G12 + Xf .* conj(Yf); % CSD between Microphone and Speaker
G21=G21 + Yf.*conj(Xf);
end
G1 = 2*G1(1:nfft/2)./(nfft*nfft*nav);
G2 = 2*G2(1:nfft/2)./(nfft*nfft*nav);
G12 = 2*G12(1:nfft/2)./(nfft*nfft*nav);
G21 = 2*G21(1:nfft/2)./(nfft*nfft*nav);
% Compute Coherence Function
coherence = abs(G21).^2 ./ (G1 .* G2);
% Compute Frequency Response Function (FRF)
frf = G2./G12; % FRF
magdB=20*log10(abs(frf));
%% Impulse Response
IR = ifft(frf,nfft);
IR_trunc=IR(1:IM_L);
%impulse_time = (0:nfft-1) * dt;
% n_samp=length(frf);
% impulse_time= 0:dt:(length(microphoneInput1)-1)*dt;
%store everything to the two vectors made above
allData_spk(:, i) = spkinput;
allData_mic(:, i) = microphoneInput;
allIR (:,i) = IR;
allIR_trunc (:,i)= IR_trunc;
allfrf (:,i) = frf;
filenameOut = sprintf(‘HeadTesting_Baseline_27Jan_%ddeg.mat’, ((i-1)*5));
%Movement———–
% – moves it to the left (counterclockwise) (standing behind it)
% + moves it to the right (clockwise) (stangind behind it)
if i~=n_rot+1
move(sm, +50*Angle);
end
end
clear dcm sm shield a; audiorecorder, signal processing, audio, arduino, for loop MATLAB Answers — New Questions
MATLAB GRADER VIEW LEARNER ANSWERS BY LEARNER ID
Dear All,
I am currently marking students’ assignments in MATLAB Grader. The assignments involve several questions for learners to answer. One good feature of MATLAB Grader is the ability to search for answers using the solution ID.
However, it would be helpful to have a search option using the learner ID, which would bring up all their answers for the respective assignment. I’m not sure if this feature already exists.
Any help would be appreciated.
Regards,
FaisalDear All,
I am currently marking students’ assignments in MATLAB Grader. The assignments involve several questions for learners to answer. One good feature of MATLAB Grader is the ability to search for answers using the solution ID.
However, it would be helpful to have a search option using the learner ID, which would bring up all their answers for the respective assignment. I’m not sure if this feature already exists.
Any help would be appreciated.
Regards,
Faisal Dear All,
I am currently marking students’ assignments in MATLAB Grader. The assignments involve several questions for learners to answer. One good feature of MATLAB Grader is the ability to search for answers using the solution ID.
However, it would be helpful to have a search option using the learner ID, which would bring up all their answers for the respective assignment. I’m not sure if this feature already exists.
Any help would be appreciated.
Regards,
Faisal matlab grader, search, userid MATLAB Answers — New Questions
Removing comas from the text file
I have a text file containing some numbers separated with coma.How can I remove those comas.
Example:
data.txt={1,2,3,4………}.Is there any method to remove those comas?
My text file when loaded to matlab is 2517×1001 matrix.
Kindly respondI have a text file containing some numbers separated with coma.How can I remove those comas.
Example:
data.txt={1,2,3,4………}.Is there any method to remove those comas?
My text file when loaded to matlab is 2517×1001 matrix.
Kindly respond I have a text file containing some numbers separated with coma.How can I remove those comas.
Example:
data.txt={1,2,3,4………}.Is there any method to remove those comas?
My text file when loaded to matlab is 2517×1001 matrix.
Kindly respond removing comas MATLAB Answers — New Questions