Category: Matlab
Category Archives: Matlab
How do I set the threshold value on the action potential on the upward and downward slope to define width?
Hi,
I am doing action potential analysis and at the moment I am defining my threshold value manually using ginput for analysing width, however I would like to set identical y values for analysis of width of the curve. Right now, I zoom into the figure to try and set the x and y points to get the width of the AP.
My code for producing the figure and setting ginput values manually for the defined variables:
% Roksana’s script to plot .smr AP data
% 20210127
% For troubleshooting analysis – cleans the workspace
clear
close all
%Import data
load(‘C:xyz.mat’)
%Define channel to plot
data = xyz;
vm = data.values;
%scale x-axis by interval
t = linspace(0, length(vm)*data.interval,length(vm));
plot(t,vm)
xlabel(‘Time (s)’)
ylabel(‘Voltage (mV)’)
title(‘Membrane potential’)
%find max Vm value between 2 points selected on the figure
[x, y] = ginput(2);
%Report values towards AP width
xfirst = x(1,1)
xsecond = x(2,1)
%Round values for calculations of parameters
xpt1 = round(x(1));
xpt2 = round(x(2));
ypt1 = round(y(1));
ypt2 = round(y(2));
%Find a point between the first and second points on x-axis
isin = (t >= xpt1 & t <= xpt2);
%Identify the peak between the two points on the x-axis
%peak = max(vm(isin))
peak = max(vm)
%Display trough (mV); from baseline
APtrough = min(vm(isin))
%%Display AP amplitude (mV)
APamp = (peak + (ypt1*(-1)))
%%Display half-amplitude(mV)
APhalfamp = ((peak-APtrough)*0.5)
%%%Area under the curve and width values from threshold value – require zoom%%%
%pause script until button press for zooming in
zoom on;
pause ();
zoom off;
%find max Vm value between 2 points selected on the figure
[a, b] = ginput(2);
%Report values towards AP width
thresholdt1 = a(1,1)
thresholdt2 = a(2,1)
thresholdValue1 = b(1)
thresholdValue2 = b(2)
%%Display width(ms)
width = (thresholdt2 – thresholdt1)*1000 %%%%needs to be defined by threshold
%%Display half-width(ms)
APhalfwidth = (width/2)Hi,
I am doing action potential analysis and at the moment I am defining my threshold value manually using ginput for analysing width, however I would like to set identical y values for analysis of width of the curve. Right now, I zoom into the figure to try and set the x and y points to get the width of the AP.
My code for producing the figure and setting ginput values manually for the defined variables:
% Roksana’s script to plot .smr AP data
% 20210127
% For troubleshooting analysis – cleans the workspace
clear
close all
%Import data
load(‘C:xyz.mat’)
%Define channel to plot
data = xyz;
vm = data.values;
%scale x-axis by interval
t = linspace(0, length(vm)*data.interval,length(vm));
plot(t,vm)
xlabel(‘Time (s)’)
ylabel(‘Voltage (mV)’)
title(‘Membrane potential’)
%find max Vm value between 2 points selected on the figure
[x, y] = ginput(2);
%Report values towards AP width
xfirst = x(1,1)
xsecond = x(2,1)
%Round values for calculations of parameters
xpt1 = round(x(1));
xpt2 = round(x(2));
ypt1 = round(y(1));
ypt2 = round(y(2));
%Find a point between the first and second points on x-axis
isin = (t >= xpt1 & t <= xpt2);
%Identify the peak between the two points on the x-axis
%peak = max(vm(isin))
peak = max(vm)
%Display trough (mV); from baseline
APtrough = min(vm(isin))
%%Display AP amplitude (mV)
APamp = (peak + (ypt1*(-1)))
%%Display half-amplitude(mV)
APhalfamp = ((peak-APtrough)*0.5)
%%%Area under the curve and width values from threshold value – require zoom%%%
%pause script until button press for zooming in
zoom on;
pause ();
zoom off;
%find max Vm value between 2 points selected on the figure
[a, b] = ginput(2);
%Report values towards AP width
thresholdt1 = a(1,1)
thresholdt2 = a(2,1)
thresholdValue1 = b(1)
thresholdValue2 = b(2)
%%Display width(ms)
width = (thresholdt2 – thresholdt1)*1000 %%%%needs to be defined by threshold
%%Display half-width(ms)
APhalfwidth = (width/2) Hi,
I am doing action potential analysis and at the moment I am defining my threshold value manually using ginput for analysing width, however I would like to set identical y values for analysis of width of the curve. Right now, I zoom into the figure to try and set the x and y points to get the width of the AP.
My code for producing the figure and setting ginput values manually for the defined variables:
% Roksana’s script to plot .smr AP data
% 20210127
% For troubleshooting analysis – cleans the workspace
clear
close all
%Import data
load(‘C:xyz.mat’)
%Define channel to plot
data = xyz;
vm = data.values;
%scale x-axis by interval
t = linspace(0, length(vm)*data.interval,length(vm));
plot(t,vm)
xlabel(‘Time (s)’)
ylabel(‘Voltage (mV)’)
title(‘Membrane potential’)
%find max Vm value between 2 points selected on the figure
[x, y] = ginput(2);
%Report values towards AP width
xfirst = x(1,1)
xsecond = x(2,1)
%Round values for calculations of parameters
xpt1 = round(x(1));
xpt2 = round(x(2));
ypt1 = round(y(1));
ypt2 = round(y(2));
%Find a point between the first and second points on x-axis
isin = (t >= xpt1 & t <= xpt2);
%Identify the peak between the two points on the x-axis
%peak = max(vm(isin))
peak = max(vm)
%Display trough (mV); from baseline
APtrough = min(vm(isin))
%%Display AP amplitude (mV)
APamp = (peak + (ypt1*(-1)))
%%Display half-amplitude(mV)
APhalfamp = ((peak-APtrough)*0.5)
%%%Area under the curve and width values from threshold value – require zoom%%%
%pause script until button press for zooming in
zoom on;
pause ();
zoom off;
%find max Vm value between 2 points selected on the figure
[a, b] = ginput(2);
%Report values towards AP width
thresholdt1 = a(1,1)
thresholdt2 = a(2,1)
thresholdValue1 = b(1)
thresholdValue2 = b(2)
%%Display width(ms)
width = (thresholdt2 – thresholdt1)*1000 %%%%needs to be defined by threshold
%%Display half-width(ms)
APhalfwidth = (width/2) action potential analysis, threshold value MATLAB Answers — New Questions
Enabling bus sorting by name in the Simulink Type Editor
How to enable bus sorting by name in the Simulink Type Editor?How to enable bus sorting by name in the Simulink Type Editor? How to enable bus sorting by name in the Simulink Type Editor? type editor, bus, gui, bus sorting MATLAB Answers — New Questions
how to change size of simscape models
When I change Stewart platform to 10 times of the default size(such as 28cm to 280 cm) and run the model, the model fell apart and became inffective. So I’d like to know is there any parameter that I need to change to make sure this model works well when its size changes.The default size is so tiny that I can use this model directly.
I’ll appreciate it if anyone could answer my little question!
Sincerely,When I change Stewart platform to 10 times of the default size(such as 28cm to 280 cm) and run the model, the model fell apart and became inffective. So I’d like to know is there any parameter that I need to change to make sure this model works well when its size changes.The default size is so tiny that I can use this model directly.
I’ll appreciate it if anyone could answer my little question!
Sincerely, When I change Stewart platform to 10 times of the default size(such as 28cm to 280 cm) and run the model, the model fell apart and became inffective. So I’d like to know is there any parameter that I need to change to make sure this model works well when its size changes.The default size is so tiny that I can use this model directly.
I’ll appreciate it if anyone could answer my little question!
Sincerely, simscape, stewart platform, simscape multibody MATLAB Answers — New Questions
FMU Export – Model Exchange & Co-Simulation
Dear Sir or Madam,
I have recently seen that FMU exportation under Model Exchange option has been included in MATLAB R2024b release.
I am trying to export a Simulink model as FMU – Model Exchange using the command:
exportToFMU(SimulinkModelName, ‘FMIVersion’, ‘2.0’, ‘FMUType’, ‘ME’)
However, I get the following error:
The make command returned an error of 2
Build Summary
Top model targets:
Model Build Reason Status
====================================================================================================================
SimulinkModelName Information cache folder or artifacts were missing. Failed to build. For more information, see build log.
0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 27.437s
Error using exportFMU_ME (line 36)
Error(s) encountered while building "SimulinkModelName"
I had successfully exported this same model as FMU – CoSimulation.
exportToFMU2CS(SimulinkModelName)
Why is it possible to export the model under the CoSimulation option and not under the Model Exchange option?
Thank you very much in advance.
Best regards,
Víctor Sánchez Suárez
Norvento Enerxía S.L.Dear Sir or Madam,
I have recently seen that FMU exportation under Model Exchange option has been included in MATLAB R2024b release.
I am trying to export a Simulink model as FMU – Model Exchange using the command:
exportToFMU(SimulinkModelName, ‘FMIVersion’, ‘2.0’, ‘FMUType’, ‘ME’)
However, I get the following error:
The make command returned an error of 2
Build Summary
Top model targets:
Model Build Reason Status
====================================================================================================================
SimulinkModelName Information cache folder or artifacts were missing. Failed to build. For more information, see build log.
0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 27.437s
Error using exportFMU_ME (line 36)
Error(s) encountered while building "SimulinkModelName"
I had successfully exported this same model as FMU – CoSimulation.
exportToFMU2CS(SimulinkModelName)
Why is it possible to export the model under the CoSimulation option and not under the Model Exchange option?
Thank you very much in advance.
Best regards,
Víctor Sánchez Suárez
Norvento Enerxía S.L. Dear Sir or Madam,
I have recently seen that FMU exportation under Model Exchange option has been included in MATLAB R2024b release.
I am trying to export a Simulink model as FMU – Model Exchange using the command:
exportToFMU(SimulinkModelName, ‘FMIVersion’, ‘2.0’, ‘FMUType’, ‘ME’)
However, I get the following error:
The make command returned an error of 2
Build Summary
Top model targets:
Model Build Reason Status
====================================================================================================================
SimulinkModelName Information cache folder or artifacts were missing. Failed to build. For more information, see build log.
0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 27.437s
Error using exportFMU_ME (line 36)
Error(s) encountered while building "SimulinkModelName"
I had successfully exported this same model as FMU – CoSimulation.
exportToFMU2CS(SimulinkModelName)
Why is it possible to export the model under the CoSimulation option and not under the Model Exchange option?
Thank you very much in advance.
Best regards,
Víctor Sánchez Suárez
Norvento Enerxía S.L. fmu, cosimulation, model exchange, fmi MATLAB Answers — New Questions
Accessing Version Details Programmatically, App designer
Hello, In appdesigner there is an option to keep track of the version number for sharing. Is there away to access this programatically. I want to include it in the startup function and display it in the figure name
app.UIFigure.FigureName= ……
ThanksHello, In appdesigner there is an option to keep track of the version number for sharing. Is there away to access this programatically. I want to include it in the startup function and display it in the figure name
app.UIFigure.FigureName= ……
Thanks Hello, In appdesigner there is an option to keep track of the version number for sharing. Is there away to access this programatically. I want to include it in the startup function and display it in the figure name
app.UIFigure.FigureName= ……
Thanks version, startup MATLAB Answers — New Questions
Every time I log in, I get an error message dialog: Error starting MATLAB Connector: One or more services failed to start
I’m running Windows 10, and MATLAB R2023b, although I’ve seen this problem through several prior versions.
Every time I log in, a dialog box pops up with the error message:
Error starting MATLAB Connector: One or more services failed to start
I’ve uninstalled and reinstalled MATLAB Connector multiple times. The Connector itself seems to work when I start MATLAB, but this error message is kind of a pain. What’s going wrong and how can I fix it?I’m running Windows 10, and MATLAB R2023b, although I’ve seen this problem through several prior versions.
Every time I log in, a dialog box pops up with the error message:
Error starting MATLAB Connector: One or more services failed to start
I’ve uninstalled and reinstalled MATLAB Connector multiple times. The Connector itself seems to work when I start MATLAB, but this error message is kind of a pain. What’s going wrong and how can I fix it? I’m running Windows 10, and MATLAB R2023b, although I’ve seen this problem through several prior versions.
Every time I log in, a dialog box pops up with the error message:
Error starting MATLAB Connector: One or more services failed to start
I’ve uninstalled and reinstalled MATLAB Connector multiple times. The Connector itself seems to work when I start MATLAB, but this error message is kind of a pain. What’s going wrong and how can I fix it? connector, error, login MATLAB Answers — New Questions
How does scatteredinterpolant interpolate points on convex hull?
Hello,
i want to know how scatteredinterpolant calculates query points that lie on the convex hull of the sample points.
I need to know this specifically for natural neighbor interpolation. To my understanding points on the convex hull produce unbounded voronoi cells with an infinite area, which means that all weights used for the interpolation should be zero (since the weights are defined as overlapping area devided by the area of the new voronoi cell), which in return means no interpolation is possible.
The interpolation is tested with the following code. The value of qv is returned as 0.5484.
Points=[-1.5 3.2; 1.8 3.2; -3.7 1.5; -1.5 1.3;
0.8 1.2; 3.3 1.5; -4.0 -1.0; -2.3 -0.7;
0 -0.5; 2.0 -1.5; 3.7 -0.8; -3.5 -2.9;
-0.9 -3.9; 2.0 -3.5; 3.5 -2.25];
z=Points(:,2).*sin(Points(:,1)) – Points(:,1).*cos(Points(:,2));
qP=[0.3 3.2];
F = scatteredInterpolant(Points(:,1),Points(:,2),z);
F.Method = ‘natural’;
qv=F(qP);
figure(1)
voronoi(Points(:,1),Points(:,2));
figure(2)
AllPoints=[Points; qP];
voronoi(AllPoints(:,1),AllPoints(:,2));Hello,
i want to know how scatteredinterpolant calculates query points that lie on the convex hull of the sample points.
I need to know this specifically for natural neighbor interpolation. To my understanding points on the convex hull produce unbounded voronoi cells with an infinite area, which means that all weights used for the interpolation should be zero (since the weights are defined as overlapping area devided by the area of the new voronoi cell), which in return means no interpolation is possible.
The interpolation is tested with the following code. The value of qv is returned as 0.5484.
Points=[-1.5 3.2; 1.8 3.2; -3.7 1.5; -1.5 1.3;
0.8 1.2; 3.3 1.5; -4.0 -1.0; -2.3 -0.7;
0 -0.5; 2.0 -1.5; 3.7 -0.8; -3.5 -2.9;
-0.9 -3.9; 2.0 -3.5; 3.5 -2.25];
z=Points(:,2).*sin(Points(:,1)) – Points(:,1).*cos(Points(:,2));
qP=[0.3 3.2];
F = scatteredInterpolant(Points(:,1),Points(:,2),z);
F.Method = ‘natural’;
qv=F(qP);
figure(1)
voronoi(Points(:,1),Points(:,2));
figure(2)
AllPoints=[Points; qP];
voronoi(AllPoints(:,1),AllPoints(:,2)); Hello,
i want to know how scatteredinterpolant calculates query points that lie on the convex hull of the sample points.
I need to know this specifically for natural neighbor interpolation. To my understanding points on the convex hull produce unbounded voronoi cells with an infinite area, which means that all weights used for the interpolation should be zero (since the weights are defined as overlapping area devided by the area of the new voronoi cell), which in return means no interpolation is possible.
The interpolation is tested with the following code. The value of qv is returned as 0.5484.
Points=[-1.5 3.2; 1.8 3.2; -3.7 1.5; -1.5 1.3;
0.8 1.2; 3.3 1.5; -4.0 -1.0; -2.3 -0.7;
0 -0.5; 2.0 -1.5; 3.7 -0.8; -3.5 -2.9;
-0.9 -3.9; 2.0 -3.5; 3.5 -2.25];
z=Points(:,2).*sin(Points(:,1)) – Points(:,1).*cos(Points(:,2));
qP=[0.3 3.2];
F = scatteredInterpolant(Points(:,1),Points(:,2),z);
F.Method = ‘natural’;
qv=F(qP);
figure(1)
voronoi(Points(:,1),Points(:,2));
figure(2)
AllPoints=[Points; qP];
voronoi(AllPoints(:,1),AllPoints(:,2)); interpolation, scatteredinterpolant, convex hull, voronoi, natural neighbor interpolation MATLAB Answers — New Questions
Error using wavedec Expected X to be finite. Error in wavedec (line 34) validateattributes(x,{‘numeric’},{‘vector’,’finite’,’real’},’wavedec’,’X’);
I am using wavedec to discritize my signal using ‘db4’ wavelet.
my X = acceleration vector(9000 x 1)
My X is finite. But I am getting a error that ‘ Error using wavedec Expected X to be finite’
My code :
[a,l] = wavedec(acc,3,’db4′);
approx = appcoef(a,l,’db4′);
[acd1,acd2,acd3] = detcoef(a,l,[1 2 3]);
figure
subplot(4,1,1)
plot(approx)
title(‘Approximation Coefficients’)
subplot(4,1,2)
plot(acd3)
title(‘Level 3 Detail Coefficients’)
subplot(4,1,3)
plot(acd2)
title(‘Level 2 Detail Coefficients’)
subplot(4,1,4)
plot(acd1)
title(‘Level 1 Detail Coefficients’)
please help me. Where I am wrong. I am unable to solve this problem.I am using wavedec to discritize my signal using ‘db4’ wavelet.
my X = acceleration vector(9000 x 1)
My X is finite. But I am getting a error that ‘ Error using wavedec Expected X to be finite’
My code :
[a,l] = wavedec(acc,3,’db4′);
approx = appcoef(a,l,’db4′);
[acd1,acd2,acd3] = detcoef(a,l,[1 2 3]);
figure
subplot(4,1,1)
plot(approx)
title(‘Approximation Coefficients’)
subplot(4,1,2)
plot(acd3)
title(‘Level 3 Detail Coefficients’)
subplot(4,1,3)
plot(acd2)
title(‘Level 2 Detail Coefficients’)
subplot(4,1,4)
plot(acd1)
title(‘Level 1 Detail Coefficients’)
please help me. Where I am wrong. I am unable to solve this problem. I am using wavedec to discritize my signal using ‘db4’ wavelet.
my X = acceleration vector(9000 x 1)
My X is finite. But I am getting a error that ‘ Error using wavedec Expected X to be finite’
My code :
[a,l] = wavedec(acc,3,’db4′);
approx = appcoef(a,l,’db4′);
[acd1,acd2,acd3] = detcoef(a,l,[1 2 3]);
figure
subplot(4,1,1)
plot(approx)
title(‘Approximation Coefficients’)
subplot(4,1,2)
plot(acd3)
title(‘Level 3 Detail Coefficients’)
subplot(4,1,3)
plot(acd2)
title(‘Level 2 Detail Coefficients’)
subplot(4,1,4)
plot(acd1)
title(‘Level 1 Detail Coefficients’)
please help me. Where I am wrong. I am unable to solve this problem. wavelet, discrete wavelet transform MATLAB Answers — New Questions
analysis using wavelet coherence
i want to perfom rossby wave detection using the wavelet coherence, but when i running the code there is always an error that says "error in wt.m time must be constant". when i change the year in the first clumn to numbers, the code runs. but when I include the first column as the years, the error massage appears. My data consists of 20 years,is there something wrong with my data?i want to perfom rossby wave detection using the wavelet coherence, but when i running the code there is always an error that says "error in wt.m time must be constant". when i change the year in the first clumn to numbers, the code runs. but when I include the first column as the years, the error massage appears. My data consists of 20 years,is there something wrong with my data? i want to perfom rossby wave detection using the wavelet coherence, but when i running the code there is always an error that says "error in wt.m time must be constant". when i change the year in the first clumn to numbers, the code runs. but when I include the first column as the years, the error massage appears. My data consists of 20 years,is there something wrong with my data? wavelet, digital signal processing MATLAB Answers — New Questions
why the Files AMSimulink.mdl and Aspentech-Matlab not available
C:Program FilesMATLABbin…..? after Matlab 2024a installationC:Program FilesMATLABbin…..? after Matlab 2024a installation C:Program FilesMATLABbin…..? after Matlab 2024a installation amsimulink.mdl MATLAB Answers — New Questions
what is this type “sfix16_Sp1_Bn25”
What is
"sfix16_Sp1_Bn25" this type mean for?What is
"sfix16_Sp1_Bn25" this type mean for? What is
"sfix16_Sp1_Bn25" this type mean for? type MATLAB Answers — New Questions
muti input cnn in matalb how to do that and how to feed the data in the model?
I want to train a muti input cnn in matalb how to do that and how to feed the data in the model?
like in python we do this:
history=final_model.fit(x=[X_insp_tr, X_exp_tr], y=y_tr,
epochs=100, batch_size=32,
validation_data=([X_insp_val, X_exp_val], y_val))I want to train a muti input cnn in matalb how to do that and how to feed the data in the model?
like in python we do this:
history=final_model.fit(x=[X_insp_tr, X_exp_tr], y=y_tr,
epochs=100, batch_size=32,
validation_data=([X_insp_val, X_exp_val], y_val)) I want to train a muti input cnn in matalb how to do that and how to feed the data in the model?
like in python we do this:
history=final_model.fit(x=[X_insp_tr, X_exp_tr], y=y_tr,
epochs=100, batch_size=32,
validation_data=([X_insp_val, X_exp_val], y_val)) deep learning, cnn, multi-input-cnn, multi-scale cnn MATLAB Answers — New Questions
Simscape Isothermal Fluids – Pressure sensor
This is a system of a gear pump connected to a load. The angular velocity is to be maintained constant. The Pressure sensor reads only 1.12bar, it does not reflect the pressure due to the conneted load. Am I missing something here?. There is a load of about 300kgs which needs to rotated, so there should be pressure built up due to the load.This is a system of a gear pump connected to a load. The angular velocity is to be maintained constant. The Pressure sensor reads only 1.12bar, it does not reflect the pressure due to the conneted load. Am I missing something here?. There is a load of about 300kgs which needs to rotated, so there should be pressure built up due to the load. This is a system of a gear pump connected to a load. The angular velocity is to be maintained constant. The Pressure sensor reads only 1.12bar, it does not reflect the pressure due to the conneted load. Am I missing something here?. There is a load of about 300kgs which needs to rotated, so there should be pressure built up due to the load. pressure sensor il MATLAB Answers — New Questions
Can I download installation files for the Embedded Coder® Support Package for AUTOSAR Standard?
I would like to download the Embedded Coder® Support Package for AUTOSAR Standard now when I have internet access but install it later when I do not have internet access.I would like to download the Embedded Coder® Support Package for AUTOSAR Standard now when I have internet access but install it later when I do not have internet access. I would like to download the Embedded Coder® Support Package for AUTOSAR Standard now when I have internet access but install it later when I do not have internet access. autosar, software components, runnable, automotive, control design MATLAB Answers — New Questions
Without entering incident angle signal collection by phased.collector
Hey,
I want to send signal from source then will i be able to collect from antennas that are ula, without entering incident angle into collector function.
ex.
rxsig = collector(signal, inc_angle);
Collect all signals and finding angle using phase difference between linear antennasHey,
I want to send signal from source then will i be able to collect from antennas that are ula, without entering incident angle into collector function.
ex.
rxsig = collector(signal, inc_angle);
Collect all signals and finding angle using phase difference between linear antennas Hey,
I want to send signal from source then will i be able to collect from antennas that are ula, without entering incident angle into collector function.
ex.
rxsig = collector(signal, inc_angle);
Collect all signals and finding angle using phase difference between linear antennas phased array, collector MATLAB Answers — New Questions
Unable to assign Input Data in the Parameter Estimation tool
Hello everyone. I am trying to learn the parameter estimation tool in Simulink. However, I cannot figure out how to import the Input data. Output data is the only section that appears on screen. Every tutorial I encountered, like here: Estimate Parameters from Measured Data – MATLAB & Simulink – MathWorks Benelux , there is a distinct Input tab. Am I doing something wrong? I cannot find anyone else who had the same issue. Thx!Hello everyone. I am trying to learn the parameter estimation tool in Simulink. However, I cannot figure out how to import the Input data. Output data is the only section that appears on screen. Every tutorial I encountered, like here: Estimate Parameters from Measured Data – MATLAB & Simulink – MathWorks Benelux , there is a distinct Input tab. Am I doing something wrong? I cannot find anyone else who had the same issue. Thx! Hello everyone. I am trying to learn the parameter estimation tool in Simulink. However, I cannot figure out how to import the Input data. Output data is the only section that appears on screen. Every tutorial I encountered, like here: Estimate Parameters from Measured Data – MATLAB & Simulink – MathWorks Benelux , there is a distinct Input tab. Am I doing something wrong? I cannot find anyone else who had the same issue. Thx! simulink, parameter estimation MATLAB Answers — New Questions
Matalb 2021a uses 100% CPU and is running very slowly
Hello,
I haven’t used Matlab in the few months on my Mac OS ver 10.14.6, and not sure what happened but Matlab R2021a runs very slowly and uses 100% CPU. I’ve already updated R2021a with the update patch. Made sure Editor doesn’t start with the start of MATLAB. There are no viruses, as far as I know. Starting it up using Terminal does not solve the problem.Hello,
I haven’t used Matlab in the few months on my Mac OS ver 10.14.6, and not sure what happened but Matlab R2021a runs very slowly and uses 100% CPU. I’ve already updated R2021a with the update patch. Made sure Editor doesn’t start with the start of MATLAB. There are no viruses, as far as I know. Starting it up using Terminal does not solve the problem. Hello,
I haven’t used Matlab in the few months on my Mac OS ver 10.14.6, and not sure what happened but Matlab R2021a runs very slowly and uses 100% CPU. I’ve already updated R2021a with the update patch. Made sure Editor doesn’t start with the start of MATLAB. There are no viruses, as far as I know. Starting it up using Terminal does not solve the problem. r2021a slow, 100% cpu, crashes MATLAB Answers — New Questions
How to call the embedded code using user defined function blocks in matlab
I have some stm32 codes and i need to integrate that in matlab environment using s function/ c function / c caller blocks. And that particular code have one main header and source and also other librray files that is associated with the stm board. Can someone help me with intergrating that particular code with simulink environment and test that functions.
And if I have to use s function block for above problem how to do that?I have some stm32 codes and i need to integrate that in matlab environment using s function/ c function / c caller blocks. And that particular code have one main header and source and also other librray files that is associated with the stm board. Can someone help me with intergrating that particular code with simulink environment and test that functions.
And if I have to use s function block for above problem how to do that? I have some stm32 codes and i need to integrate that in matlab environment using s function/ c function / c caller blocks. And that particular code have one main header and source and also other librray files that is associated with the stm board. Can someone help me with intergrating that particular code with simulink environment and test that functions.
And if I have to use s function block for above problem how to do that? c caller, s-function, c function, embedded MATLAB Answers — New Questions
Real-Time DAC with DSP tool box
I am having trouble implementing a real time DAC in my code. I am working with an NI USB-6356 and I have succesfully implemented in my Matlab Code an ADC than reads the real time signal and process it. I am trying to implement a DAC with the DSP tool box (as I did with the ADC) but for some reason it doesn’t work. There aren’t any apparent errors so it is being difficult to solve the problem. Can someone tell me what’s happening?
dev = ‘Dev1’;
channels = {‘ai0’, ‘ai1’};
ao = ‘ao0’; % DAC output channel
fs = 1000; % Sampling Frequency
fc = 10; % Carrier Frequency
fsub = 10; % Subcarrier Frequency
D = 1; % Decimation factor
bits = 16; % DAC Resolution
Kc = 0.01; % Proportional control gain
% Create TimeScope for visualization
scope = timescope(‘NumInputPorts’, 3, ‘TimeSpan’, 2, ‘SampleRate’, fs, …
‘ShowLegend’, true, ‘YLimits’, [-5 5], …
‘Title’, ‘Real-time Signal and Processed Signal’, …
‘ChannelNames’, {‘DAC Output’, ‘Input Signal’, ‘Modulated Signal’});
%% Data Acquisition Setup
daqSession = daq.createSession(‘ni’);
for i = 1:length(channels)
addAnalogInputChannel(daqSession, dev, channels{i}, ‘Voltage’);
end
daqSession.Rate = fs;
daqSession.IsContinuous = true;
addAnalogOutputChannel(daqSession, dev, ao, ‘Voltage’);
% Initialize NCO phase accumulator
nco_phase = 0;
lh = addlistener(daqSession, ‘DataAvailable’, …
@(src, event) processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D));
% Create an initial buffer to queue for DAC output
initialDACData = zeros(fs, 1); % Buffer of zeros to start with (length depends on initial session requirements)
queueOutputData(daqSession, initialDACData);
startBackground(daqSession);
disp(‘Press any key to stop’);
pause;
stop(daqSession);
delete(lh);
release(scope);
disp(‘Stopping data acquisition…’);
%% Function to process the signal and update DAC output
function OUT_signal = processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D)
% Input signal from ADC
signal = event.Data;
input_signal = signal(:, 2); % Input signal (from ai1)
dac_signal = signal(:, 1); % Read back the DAC signal (from ai0)
%===MANUAL NUMERICALLY CONTROLLED OSCILLATOR===
t = event.TimeStamps; % Time vector
% Set the control to adjust fc every second
onesec = 0;
tic;
persistent elapsed_time
if isempty(elapsed_time)
elapsed_time = 0;
end
% Update elapsed time
elapsed_time = elapsed_time + t(end) – t(1); % Time since last callback
% When elapsed time exceeds 1 second, update carrier frequency
if elapsed_time >= 1
% Save the current carrier frequency
% Calculate new fc using your control law: fc = fc + Kc * atan(Ik1/Qk1)
fc = fc + Kc * atan(Ik1/Qk1);
% Reset elapsed time
elapsed_time = 0;
onesec = toc;
end
% Generate DAC output
OUT_Signal = 0.5*sin(2*pi*(fc/fs)*t); % Using filtered AM as DAC signal
% Write to DAC (update Analog Output Channel)
src.queueOutputData(OUT_signal);
% Visualization
scope(input_signal, dac_signal, OUT_Signal);
endI am having trouble implementing a real time DAC in my code. I am working with an NI USB-6356 and I have succesfully implemented in my Matlab Code an ADC than reads the real time signal and process it. I am trying to implement a DAC with the DSP tool box (as I did with the ADC) but for some reason it doesn’t work. There aren’t any apparent errors so it is being difficult to solve the problem. Can someone tell me what’s happening?
dev = ‘Dev1’;
channels = {‘ai0’, ‘ai1’};
ao = ‘ao0’; % DAC output channel
fs = 1000; % Sampling Frequency
fc = 10; % Carrier Frequency
fsub = 10; % Subcarrier Frequency
D = 1; % Decimation factor
bits = 16; % DAC Resolution
Kc = 0.01; % Proportional control gain
% Create TimeScope for visualization
scope = timescope(‘NumInputPorts’, 3, ‘TimeSpan’, 2, ‘SampleRate’, fs, …
‘ShowLegend’, true, ‘YLimits’, [-5 5], …
‘Title’, ‘Real-time Signal and Processed Signal’, …
‘ChannelNames’, {‘DAC Output’, ‘Input Signal’, ‘Modulated Signal’});
%% Data Acquisition Setup
daqSession = daq.createSession(‘ni’);
for i = 1:length(channels)
addAnalogInputChannel(daqSession, dev, channels{i}, ‘Voltage’);
end
daqSession.Rate = fs;
daqSession.IsContinuous = true;
addAnalogOutputChannel(daqSession, dev, ao, ‘Voltage’);
% Initialize NCO phase accumulator
nco_phase = 0;
lh = addlistener(daqSession, ‘DataAvailable’, …
@(src, event) processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D));
% Create an initial buffer to queue for DAC output
initialDACData = zeros(fs, 1); % Buffer of zeros to start with (length depends on initial session requirements)
queueOutputData(daqSession, initialDACData);
startBackground(daqSession);
disp(‘Press any key to stop’);
pause;
stop(daqSession);
delete(lh);
release(scope);
disp(‘Stopping data acquisition…’);
%% Function to process the signal and update DAC output
function OUT_signal = processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D)
% Input signal from ADC
signal = event.Data;
input_signal = signal(:, 2); % Input signal (from ai1)
dac_signal = signal(:, 1); % Read back the DAC signal (from ai0)
%===MANUAL NUMERICALLY CONTROLLED OSCILLATOR===
t = event.TimeStamps; % Time vector
% Set the control to adjust fc every second
onesec = 0;
tic;
persistent elapsed_time
if isempty(elapsed_time)
elapsed_time = 0;
end
% Update elapsed time
elapsed_time = elapsed_time + t(end) – t(1); % Time since last callback
% When elapsed time exceeds 1 second, update carrier frequency
if elapsed_time >= 1
% Save the current carrier frequency
% Calculate new fc using your control law: fc = fc + Kc * atan(Ik1/Qk1)
fc = fc + Kc * atan(Ik1/Qk1);
% Reset elapsed time
elapsed_time = 0;
onesec = toc;
end
% Generate DAC output
OUT_Signal = 0.5*sin(2*pi*(fc/fs)*t); % Using filtered AM as DAC signal
% Write to DAC (update Analog Output Channel)
src.queueOutputData(OUT_signal);
% Visualization
scope(input_signal, dac_signal, OUT_Signal);
end I am having trouble implementing a real time DAC in my code. I am working with an NI USB-6356 and I have succesfully implemented in my Matlab Code an ADC than reads the real time signal and process it. I am trying to implement a DAC with the DSP tool box (as I did with the ADC) but for some reason it doesn’t work. There aren’t any apparent errors so it is being difficult to solve the problem. Can someone tell me what’s happening?
dev = ‘Dev1’;
channels = {‘ai0’, ‘ai1’};
ao = ‘ao0’; % DAC output channel
fs = 1000; % Sampling Frequency
fc = 10; % Carrier Frequency
fsub = 10; % Subcarrier Frequency
D = 1; % Decimation factor
bits = 16; % DAC Resolution
Kc = 0.01; % Proportional control gain
% Create TimeScope for visualization
scope = timescope(‘NumInputPorts’, 3, ‘TimeSpan’, 2, ‘SampleRate’, fs, …
‘ShowLegend’, true, ‘YLimits’, [-5 5], …
‘Title’, ‘Real-time Signal and Processed Signal’, …
‘ChannelNames’, {‘DAC Output’, ‘Input Signal’, ‘Modulated Signal’});
%% Data Acquisition Setup
daqSession = daq.createSession(‘ni’);
for i = 1:length(channels)
addAnalogInputChannel(daqSession, dev, channels{i}, ‘Voltage’);
end
daqSession.Rate = fs;
daqSession.IsContinuous = true;
addAnalogOutputChannel(daqSession, dev, ao, ‘Voltage’);
% Initialize NCO phase accumulator
nco_phase = 0;
lh = addlistener(daqSession, ‘DataAvailable’, …
@(src, event) processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D));
% Create an initial buffer to queue for DAC output
initialDACData = zeros(fs, 1); % Buffer of zeros to start with (length depends on initial session requirements)
queueOutputData(daqSession, initialDACData);
startBackground(daqSession);
disp(‘Press any key to stop’);
pause;
stop(daqSession);
delete(lh);
release(scope);
disp(‘Stopping data acquisition…’);
%% Function to process the signal and update DAC output
function OUT_signal = processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D)
% Input signal from ADC
signal = event.Data;
input_signal = signal(:, 2); % Input signal (from ai1)
dac_signal = signal(:, 1); % Read back the DAC signal (from ai0)
%===MANUAL NUMERICALLY CONTROLLED OSCILLATOR===
t = event.TimeStamps; % Time vector
% Set the control to adjust fc every second
onesec = 0;
tic;
persistent elapsed_time
if isempty(elapsed_time)
elapsed_time = 0;
end
% Update elapsed time
elapsed_time = elapsed_time + t(end) – t(1); % Time since last callback
% When elapsed time exceeds 1 second, update carrier frequency
if elapsed_time >= 1
% Save the current carrier frequency
% Calculate new fc using your control law: fc = fc + Kc * atan(Ik1/Qk1)
fc = fc + Kc * atan(Ik1/Qk1);
% Reset elapsed time
elapsed_time = 0;
onesec = toc;
end
% Generate DAC output
OUT_Signal = 0.5*sin(2*pi*(fc/fs)*t); % Using filtered AM as DAC signal
% Write to DAC (update Analog Output Channel)
src.queueOutputData(OUT_signal);
% Visualization
scope(input_signal, dac_signal, OUT_Signal);
end dsp, signal processing, daq, dac MATLAB Answers — New Questions
Discretize in two dimension
I have data points or data co-ordinates in 2D. Let’s say random trajectory for 10000 time steps
x= randn(10000,1);
y= randn(10000,1);
I want to discretize the trajectory in 2D phase space X and Y of equal grids sizes. And then try to calculate the probability fluxes between each grid i.e transition between boxes with time. The transition can be in and out in x or y direction in 2D space.
Any help is appreciated.I have data points or data co-ordinates in 2D. Let’s say random trajectory for 10000 time steps
x= randn(10000,1);
y= randn(10000,1);
I want to discretize the trajectory in 2D phase space X and Y of equal grids sizes. And then try to calculate the probability fluxes between each grid i.e transition between boxes with time. The transition can be in and out in x or y direction in 2D space.
Any help is appreciated. I have data points or data co-ordinates in 2D. Let’s say random trajectory for 10000 time steps
x= randn(10000,1);
y= randn(10000,1);
I want to discretize the trajectory in 2D phase space X and Y of equal grids sizes. And then try to calculate the probability fluxes between each grid i.e transition between boxes with time. The transition can be in and out in x or y direction in 2D space.
Any help is appreciated. matrix, discretize MATLAB Answers — New Questions