Tag Archives: matlab
Using Hardware Interrupt with STM32 Nucleo F767ZI board
I want to use a hardware interrupt, in particular, the TXE flag on Simulink, however I have found that there does not appear to be a hardware interrupt block in the simulink support package for stm32 nucleo boards.
The hardware interrupt blocks for STM32F4 Discovery and the ARM Cortex-Mx don’t give any errors but I cannot imagine that using them would be correct.
Is there a way to get the TXE flag for the STM32 Nucleo F767ZI on simulink or should I just restart my project on the STM32CubeIDE instead.I want to use a hardware interrupt, in particular, the TXE flag on Simulink, however I have found that there does not appear to be a hardware interrupt block in the simulink support package for stm32 nucleo boards.
The hardware interrupt blocks for STM32F4 Discovery and the ARM Cortex-Mx don’t give any errors but I cannot imagine that using them would be correct.
Is there a way to get the TXE flag for the STM32 Nucleo F767ZI on simulink or should I just restart my project on the STM32CubeIDE instead. I want to use a hardware interrupt, in particular, the TXE flag on Simulink, however I have found that there does not appear to be a hardware interrupt block in the simulink support package for stm32 nucleo boards.
The hardware interrupt blocks for STM32F4 Discovery and the ARM Cortex-Mx don’t give any errors but I cannot imagine that using them would be correct.
Is there a way to get the TXE flag for the STM32 Nucleo F767ZI on simulink or should I just restart my project on the STM32CubeIDE instead. simulink, embedded coder MATLAB Answers — New Questions
Help to plot a Surface plot of: z = y sin x – x cos y
Require help on plotting this suface plot for the fuction:
z = y sin x – x cos y
using a grid of:
-5<x<5 in steps of 0.2
-5<y<5 in steps of 0.2
Any guidance would be much appreciated
ThanksRequire help on plotting this suface plot for the fuction:
z = y sin x – x cos y
using a grid of:
-5<x<5 in steps of 0.2
-5<y<5 in steps of 0.2
Any guidance would be much appreciated
Thanks Require help on plotting this suface plot for the fuction:
z = y sin x – x cos y
using a grid of:
-5<x<5 in steps of 0.2
-5<y<5 in steps of 0.2
Any guidance would be much appreciated
Thanks surface plot, grid, matlab function, equation, homework MATLAB Answers — New Questions
Best way to plot a surface whose matrix has values of +/- infinity
Hi there! What is the best way to plot a 3D surface whose matrix C = A/B contains values of +/- infinity (whenever entries in B are zero)? Currently I am using surf( ), which results in weird vertical cross sections. I looked into the fillMissing( ) and scatteredInterpolant( ) functions. Is there a best / recommended way to proceed, to plot a smooth surface? Thanks in advance,Hi there! What is the best way to plot a 3D surface whose matrix C = A/B contains values of +/- infinity (whenever entries in B are zero)? Currently I am using surf( ), which results in weird vertical cross sections. I looked into the fillMissing( ) and scatteredInterpolant( ) functions. Is there a best / recommended way to proceed, to plot a smooth surface? Thanks in advance, Hi there! What is the best way to plot a 3D surface whose matrix C = A/B contains values of +/- infinity (whenever entries in B are zero)? Currently I am using surf( ), which results in weird vertical cross sections. I looked into the fillMissing( ) and scatteredInterpolant( ) functions. Is there a best / recommended way to proceed, to plot a smooth surface? Thanks in advance, matlab surface plot singularities MATLAB Answers — New Questions
Working with Real-Time signals in matlab
I am trying to work with a real time signal witht the DSP Tool box but I am finding difficult to acomplish. I have seen the demos and read the documents related with the DSP Tool box but it doesn’t really seem Matlab can work/process real time signals. My objective was to do a DAC to create a signal, an ADC to read this same signal, process it, and then do another DAC to see the processed signal. I have been able to work out an ADC and a DAC but none of the options available (at least for the 2022a version) are actually real time but trying to simulate it.
I will share the code in case anyone has curiostity, but not only it fails when approaching the frequency too nyquist’s but also seems to have a hard time when the processing is just multiplying by two, can’t imagine what would happen if I modulated the signal…
%============================================================%
%============== Continuous Real Time DAC & ADC===============%
%============================================================%
%========= Processes Data and Displays it Real Time =========%
%========= DisplaySignalV5: More advanced processes ========%
%============================================================%
% REQUIRED: Signal Processing Toolbox & DSP System Toolbox (NI Extension)
clear;
close all;
clc;
% === DAC and ADC === %
% Create DataAcquisition object for NI device
dq = daq("ni");
% Add Analog Output Channels to generate the signal on "ao0" and "ao1"
addoutput(dq, "Dev1", "ao0", "Voltage");
addoutput(dq, "Dev1", "ao1", "Voltage");
ch_out = dq.Channels(1:2);
ch_out(1).Name = "ao0_out";
ch_out(2).Name = "ao1_out";
% Add an Analog Input Channel to acquire the signal on "ai1"
addinput(dq, "Dev1", "ai1", "Voltage");
ch_in = dq.Channels(3);
ch_in.Name = "ai1_in";
% Set the sample rate
rate = 10000; % Hz
dq.Rate = rate;
% Specify the output signal – A square wave with a DC offset
f = 50; % Frequency of 10 Hz
t = (0:rate-1)/rate; % Time vector for 1 second
output = 1.25 + 0.25*square(2*pi*f*t); % Generate square wave with DC offset
% Create timescope to visualize the signals in real time
scope = timescope(‘SampleRate’, rate, ‘TimeSpanSource’, ‘Property’, ‘TimeSpan’, 0.1, …
‘YLimits’, [-2 2], ‘Title’, ‘Output vs Input Signals’, …
‘ShowLegend’, true, ‘ChannelNames’, {‘Inintal Signal DAC_1’, ‘Processed Signal DAC_2’});
% Set the callback function to execute when data is available
batchSize = rate; % Read data for 1 second at a time for more frequent updates
dq.ScansAvailableFcnCount = batchSize;
dq.ScansAvailableFcn = @(src, evt) plotAndWriteSignals(src, output, scope, rate);
% Preload the output data for "ao0"
preloadData = [output’, zeros(length(output), 1)]; % Preload output for ao0, set ao1 to zero initially
preload(dq, preloadData);
% Start the output and input simultaneously in continuous mode
start(dq, "repeatoutput");
% Stop the generation and acquisition after key press
disp(‘Press any key to stop the continuous generation and acquisition.’);
pause();
stop(dq);
disp("Generation and acquisition stopped.");
% Callback function to read data, plot input and output using timescope, and write to ao1 in real-time
function plotAndWriteSignals(src, output, scope, rate)
% Read available data in chunks as defined by ScansAvailableFcnCount
[data, ~] = read(src, src.ScansAvailableFcnCount, "OutputFormat", "Matrix");
processedSignal = 2.*data;
% Ensure that both ‘data’ and ‘outputToPlot’ are column vectors and have the same length
len = length(processedSignal);
outputToPlot = output(1:len)’;
if isrow(processedSignal)
processedSignal = processedSignal’;
end
% Update the timescope with the output and input signals
% The input data and output data must have consistent row sizes
scope([outputToPlot, processedSignal]);
% Write the acquired input data to the output channel "ao1"
% Create a matrix where each row contains values for both output channels
outputData = [outputToPlot, processedSignal]; % First column for ao0, second column for ao1
write(src, outputData);
endI am trying to work with a real time signal witht the DSP Tool box but I am finding difficult to acomplish. I have seen the demos and read the documents related with the DSP Tool box but it doesn’t really seem Matlab can work/process real time signals. My objective was to do a DAC to create a signal, an ADC to read this same signal, process it, and then do another DAC to see the processed signal. I have been able to work out an ADC and a DAC but none of the options available (at least for the 2022a version) are actually real time but trying to simulate it.
I will share the code in case anyone has curiostity, but not only it fails when approaching the frequency too nyquist’s but also seems to have a hard time when the processing is just multiplying by two, can’t imagine what would happen if I modulated the signal…
%============================================================%
%============== Continuous Real Time DAC & ADC===============%
%============================================================%
%========= Processes Data and Displays it Real Time =========%
%========= DisplaySignalV5: More advanced processes ========%
%============================================================%
% REQUIRED: Signal Processing Toolbox & DSP System Toolbox (NI Extension)
clear;
close all;
clc;
% === DAC and ADC === %
% Create DataAcquisition object for NI device
dq = daq("ni");
% Add Analog Output Channels to generate the signal on "ao0" and "ao1"
addoutput(dq, "Dev1", "ao0", "Voltage");
addoutput(dq, "Dev1", "ao1", "Voltage");
ch_out = dq.Channels(1:2);
ch_out(1).Name = "ao0_out";
ch_out(2).Name = "ao1_out";
% Add an Analog Input Channel to acquire the signal on "ai1"
addinput(dq, "Dev1", "ai1", "Voltage");
ch_in = dq.Channels(3);
ch_in.Name = "ai1_in";
% Set the sample rate
rate = 10000; % Hz
dq.Rate = rate;
% Specify the output signal – A square wave with a DC offset
f = 50; % Frequency of 10 Hz
t = (0:rate-1)/rate; % Time vector for 1 second
output = 1.25 + 0.25*square(2*pi*f*t); % Generate square wave with DC offset
% Create timescope to visualize the signals in real time
scope = timescope(‘SampleRate’, rate, ‘TimeSpanSource’, ‘Property’, ‘TimeSpan’, 0.1, …
‘YLimits’, [-2 2], ‘Title’, ‘Output vs Input Signals’, …
‘ShowLegend’, true, ‘ChannelNames’, {‘Inintal Signal DAC_1’, ‘Processed Signal DAC_2’});
% Set the callback function to execute when data is available
batchSize = rate; % Read data for 1 second at a time for more frequent updates
dq.ScansAvailableFcnCount = batchSize;
dq.ScansAvailableFcn = @(src, evt) plotAndWriteSignals(src, output, scope, rate);
% Preload the output data for "ao0"
preloadData = [output’, zeros(length(output), 1)]; % Preload output for ao0, set ao1 to zero initially
preload(dq, preloadData);
% Start the output and input simultaneously in continuous mode
start(dq, "repeatoutput");
% Stop the generation and acquisition after key press
disp(‘Press any key to stop the continuous generation and acquisition.’);
pause();
stop(dq);
disp("Generation and acquisition stopped.");
% Callback function to read data, plot input and output using timescope, and write to ao1 in real-time
function plotAndWriteSignals(src, output, scope, rate)
% Read available data in chunks as defined by ScansAvailableFcnCount
[data, ~] = read(src, src.ScansAvailableFcnCount, "OutputFormat", "Matrix");
processedSignal = 2.*data;
% Ensure that both ‘data’ and ‘outputToPlot’ are column vectors and have the same length
len = length(processedSignal);
outputToPlot = output(1:len)’;
if isrow(processedSignal)
processedSignal = processedSignal’;
end
% Update the timescope with the output and input signals
% The input data and output data must have consistent row sizes
scope([outputToPlot, processedSignal]);
% Write the acquired input data to the output channel "ao1"
% Create a matrix where each row contains values for both output channels
outputData = [outputToPlot, processedSignal]; % First column for ao0, second column for ao1
write(src, outputData);
end I am trying to work with a real time signal witht the DSP Tool box but I am finding difficult to acomplish. I have seen the demos and read the documents related with the DSP Tool box but it doesn’t really seem Matlab can work/process real time signals. My objective was to do a DAC to create a signal, an ADC to read this same signal, process it, and then do another DAC to see the processed signal. I have been able to work out an ADC and a DAC but none of the options available (at least for the 2022a version) are actually real time but trying to simulate it.
I will share the code in case anyone has curiostity, but not only it fails when approaching the frequency too nyquist’s but also seems to have a hard time when the processing is just multiplying by two, can’t imagine what would happen if I modulated the signal…
%============================================================%
%============== Continuous Real Time DAC & ADC===============%
%============================================================%
%========= Processes Data and Displays it Real Time =========%
%========= DisplaySignalV5: More advanced processes ========%
%============================================================%
% REQUIRED: Signal Processing Toolbox & DSP System Toolbox (NI Extension)
clear;
close all;
clc;
% === DAC and ADC === %
% Create DataAcquisition object for NI device
dq = daq("ni");
% Add Analog Output Channels to generate the signal on "ao0" and "ao1"
addoutput(dq, "Dev1", "ao0", "Voltage");
addoutput(dq, "Dev1", "ao1", "Voltage");
ch_out = dq.Channels(1:2);
ch_out(1).Name = "ao0_out";
ch_out(2).Name = "ao1_out";
% Add an Analog Input Channel to acquire the signal on "ai1"
addinput(dq, "Dev1", "ai1", "Voltage");
ch_in = dq.Channels(3);
ch_in.Name = "ai1_in";
% Set the sample rate
rate = 10000; % Hz
dq.Rate = rate;
% Specify the output signal – A square wave with a DC offset
f = 50; % Frequency of 10 Hz
t = (0:rate-1)/rate; % Time vector for 1 second
output = 1.25 + 0.25*square(2*pi*f*t); % Generate square wave with DC offset
% Create timescope to visualize the signals in real time
scope = timescope(‘SampleRate’, rate, ‘TimeSpanSource’, ‘Property’, ‘TimeSpan’, 0.1, …
‘YLimits’, [-2 2], ‘Title’, ‘Output vs Input Signals’, …
‘ShowLegend’, true, ‘ChannelNames’, {‘Inintal Signal DAC_1’, ‘Processed Signal DAC_2’});
% Set the callback function to execute when data is available
batchSize = rate; % Read data for 1 second at a time for more frequent updates
dq.ScansAvailableFcnCount = batchSize;
dq.ScansAvailableFcn = @(src, evt) plotAndWriteSignals(src, output, scope, rate);
% Preload the output data for "ao0"
preloadData = [output’, zeros(length(output), 1)]; % Preload output for ao0, set ao1 to zero initially
preload(dq, preloadData);
% Start the output and input simultaneously in continuous mode
start(dq, "repeatoutput");
% Stop the generation and acquisition after key press
disp(‘Press any key to stop the continuous generation and acquisition.’);
pause();
stop(dq);
disp("Generation and acquisition stopped.");
% Callback function to read data, plot input and output using timescope, and write to ao1 in real-time
function plotAndWriteSignals(src, output, scope, rate)
% Read available data in chunks as defined by ScansAvailableFcnCount
[data, ~] = read(src, src.ScansAvailableFcnCount, "OutputFormat", "Matrix");
processedSignal = 2.*data;
% Ensure that both ‘data’ and ‘outputToPlot’ are column vectors and have the same length
len = length(processedSignal);
outputToPlot = output(1:len)’;
if isrow(processedSignal)
processedSignal = processedSignal’;
end
% Update the timescope with the output and input signals
% The input data and output data must have consistent row sizes
scope([outputToPlot, processedSignal]);
% Write the acquired input data to the output channel "ao1"
% Create a matrix where each row contains values for both output channels
outputData = [outputToPlot, processedSignal]; % First column for ao0, second column for ao1
write(src, outputData);
end dsp, signal processing, digital signal processing, ni-daq, analog input, analog output MATLAB Answers — New Questions
Comparing Polyspace BF results from different projects
The way my CI is currently setup is that it creates a new project per branch. What I want is to compare the result of two branches using the polyspace-access export command. I tried downloading the result from one project and uploading it to the other but it failed.The way my CI is currently setup is that it creates a new project per branch. What I want is to compare the result of two branches using the polyspace-access export command. I tried downloading the result from one project and uploading it to the other but it failed. The way my CI is currently setup is that it creates a new project per branch. What I want is to compare the result of two branches using the polyspace-access export command. I tried downloading the result from one project and uploading it to the other but it failed. bugfinder, polyspace_access, polyspace_results MATLAB Answers — New Questions
Where i can find complete list of simulink blocks supported for code generation?
Where i can find complete list of simulink blocks supported for code generation? The list in link below is incomplete as it lists only basic Simulink blocks.
https://www.mathworks.com/matlabcentral/answers/101601-how-can-i-find-out-which-simulink-blocks-are-not-supported-for-code-generation-and-what-data-types-t
Going to Simulink -> Help -> Block Data Types & Code Generation Support -> All Tables also does not answer my question as that table only covers 4 toolboxes (Audio System, Communication, Computer Vision, DSP) and I know for sure that there are other blocks in other toolboxes from which code can be generated and they are not on that list.
Example, Online PID Tuner/Control System Toolbox, Fuzzy Logic Controller/Fuzzy Logic ToolboxWhere i can find complete list of simulink blocks supported for code generation? The list in link below is incomplete as it lists only basic Simulink blocks.
https://www.mathworks.com/matlabcentral/answers/101601-how-can-i-find-out-which-simulink-blocks-are-not-supported-for-code-generation-and-what-data-types-t
Going to Simulink -> Help -> Block Data Types & Code Generation Support -> All Tables also does not answer my question as that table only covers 4 toolboxes (Audio System, Communication, Computer Vision, DSP) and I know for sure that there are other blocks in other toolboxes from which code can be generated and they are not on that list.
Example, Online PID Tuner/Control System Toolbox, Fuzzy Logic Controller/Fuzzy Logic Toolbox Where i can find complete list of simulink blocks supported for code generation? The list in link below is incomplete as it lists only basic Simulink blocks.
https://www.mathworks.com/matlabcentral/answers/101601-how-can-i-find-out-which-simulink-blocks-are-not-supported-for-code-generation-and-what-data-types-t
Going to Simulink -> Help -> Block Data Types & Code Generation Support -> All Tables also does not answer my question as that table only covers 4 toolboxes (Audio System, Communication, Computer Vision, DSP) and I know for sure that there are other blocks in other toolboxes from which code can be generated and they are not on that list.
Example, Online PID Tuner/Control System Toolbox, Fuzzy Logic Controller/Fuzzy Logic Toolbox code generation, simulink, support, blocks MATLAB Answers — New Questions
,Understand DTFT and DFT using MATLAB
I wish to understand the DTFT and DFT using MATLAB.
So I want to write a code which does the following:
plot X1[n]=COS(2*pi*201/1024*n) where n=0 to1023
plot X2[n]=rect(N) where N=1024 i.e. X2[n]=1 for n=0 to 1023; else X2[n]=0
plot multiplication of both i.e. X1(n)*X2(n)
plot magnitude plot of Y1(w)=DTFT of X1(n) for -pi<w<pi
plot magnitude plot of Y2(w)=DTFT of X2(n) for -pi<w<pi
plot convolution of Y1 and Y2 i.e. Z1(w)=Y1(w) ⊗ Y2(w)
plot frequency samples Z1[k] that are values of Z1(w) at w[k]=2*pi*k/N where 0<k<(N-1)
Plz help me with the codeI wish to understand the DTFT and DFT using MATLAB.
So I want to write a code which does the following:
plot X1[n]=COS(2*pi*201/1024*n) where n=0 to1023
plot X2[n]=rect(N) where N=1024 i.e. X2[n]=1 for n=0 to 1023; else X2[n]=0
plot multiplication of both i.e. X1(n)*X2(n)
plot magnitude plot of Y1(w)=DTFT of X1(n) for -pi<w<pi
plot magnitude plot of Y2(w)=DTFT of X2(n) for -pi<w<pi
plot convolution of Y1 and Y2 i.e. Z1(w)=Y1(w) ⊗ Y2(w)
plot frequency samples Z1[k] that are values of Z1(w) at w[k]=2*pi*k/N where 0<k<(N-1)
Plz help me with the code I wish to understand the DTFT and DFT using MATLAB.
So I want to write a code which does the following:
plot X1[n]=COS(2*pi*201/1024*n) where n=0 to1023
plot X2[n]=rect(N) where N=1024 i.e. X2[n]=1 for n=0 to 1023; else X2[n]=0
plot multiplication of both i.e. X1(n)*X2(n)
plot magnitude plot of Y1(w)=DTFT of X1(n) for -pi<w<pi
plot magnitude plot of Y2(w)=DTFT of X2(n) for -pi<w<pi
plot convolution of Y1 and Y2 i.e. Z1(w)=Y1(w) ⊗ Y2(w)
plot frequency samples Z1[k] that are values of Z1(w) at w[k]=2*pi*k/N where 0<k<(N-1)
Plz help me with the code dft, dtft, freqz, fft, matlab code MATLAB Answers — New Questions
How can I export a scenario containing a parkingLot to xml format or OPENSCENARIO to save the map?
As far as I know, TMW has introduced parkingLot to drivingScenario since 2021b, but this type “parkingLot” of scenario export to xml format is not yet supported, how can I do third party map delivery?Can it only be used in matlab for simulation only?As far as I know, TMW has introduced parkingLot to drivingScenario since 2021b, but this type “parkingLot” of scenario export to xml format is not yet supported, how can I do third party map delivery?Can it only be used in matlab for simulation only? As far as I know, TMW has introduced parkingLot to drivingScenario since 2021b, but this type “parkingLot” of scenario export to xml format is not yet supported, how can I do third party map delivery?Can it only be used in matlab for simulation only? openscenario, opendrive, drivingscenario, parkinglot MATLAB Answers — New Questions
Difference results from MOM method with ttρiangle basis function and pulse
Hi
i find the scattering field in cylinder and i use the MOM method with the triangle basis and pulse. The |Es
| are the same when then incoming field are Einc= E0*exp(-j*k0*r*cos(φ)) in MOM pulse and Einc= E0*exp(j*k0*r*cos(φ)) in MOM triangle.
This the pulse current
function [Is] = currentMoM()
% Load parameters
[f, N, ra, k0, Z0, lambda] = parameter();
% Constants
gamma_const = 1.781;
dfpm = 2*pi/N;
Phi0 = (0:N-1) * dfpm;
% Precompute pairwise phase differences
deltaPhi = zeros(N, N); % Initialize deltaPhi matrix
for i = 1:N
for j = 1:N
deltaPhi(i, j) = Phi0(i) – Phi0(j); % Calculate pairwise phase differences
end
end
% Compute distance matrix R (N x N matrix)
R = zeros(N, N); % Initialize R matrix
for i = 1:N
for j = 1:N
R(i, j) = ra * sqrt(2 – 2 * cos(deltaPhi(i, j))); % Compute distance matrix R
end
end
% Coefficients
coeif1 = (Z0 * k0 / 4) * ra * dfpm;
coeif2 = (Z0 / 2) * sin(k0 * ra * dfpm/ 2);
coeif3 = (gamma_const * k0 * ra * dfpm) / 4;
% Compute lmn matrix
lmn = zeros(N, N); % Initialize lmn matrix
for i = 1:N
for j = 1:N
if i==j
lmn(i, j) = coeif1 * (1 – 1i * (2 / pi) * (log(coeif3) – 1)); % Diagonal elements
else
lmn(i, j) = coeif2 * besselh(0, 2, k0 * R(i, j)); % Compute each element of lmn
end
end
zmn = lmn;
end
% Handle diagonal elements separately
% Set zmn equal to lmn
% Compute gm vector using a for loop
gm = zeros(N, 1); % Initialize gm vector
for i = 1:N
gm(i) = E_in_z(Phi0(i)); % Calculate each element of gm using E_in_z function
end
% Solve for currents using linsolve
%Is = linsolve(zmn, gm);
Is = zmn gm;
%Is=linsolve(zmn, gm)
end
and the triangke
function [Is] = currentMoM()
% Parameter initialization
[~, N, ra, k0, Z0, ~] = parameter();
gamma_const = 1.781;
Eps = 1e-9;
dftm =2.*pi./N;
% Precompute constants
B = (4./(Z0 * k0));
A = (gamma_const*k0*ra)./2;
% Initialize matrices and vectors
lmn = zeros(N, N); % (N x N) matrix for lmn
gm = zeros(1, N); % (1 x N) vector for gm
zmn = zeros(N, N); % (N x N) matrix for zmn
% Compute lmn and zmn matrices using nested for-loops
for index_i = 1:N
for index_j = 1:N
% Precompute integration bounds
xi1_i = (index_i – 1) * dftm;
xi2_i = xi1_i + dftm;
xj1_j = (index_j – 1) * dftm;
xj2_j = xj1_j + dftm;
%log(A) +log(abs(x – y) +Eps))
if index_i == index_j
% Diagonal elements
funa = @(x, y) triangle_basisn(x, index_i) .* triangle_basisn(y, index_j) .*ra .* (1 – 1i * (2./pi).*(log(A) +log(abs(x – y) +Eps))) ;
lmn(index_i, index_j) = integral2(funa, xi1_i, xi2_i, xj1_j, xj2_j,’RelTol’, 1e-6, ‘AbsTol’, 1e-6,’Method’,’iterated’);
else
% Off-diagonal elements
funb = @(x, y)triangle_basisn(x, index_i) .* triangle_basisn(y, index_j) .*ra .* besselh(0, 2, k0.*ra.*sqrt(abs(2 – 2 * cos(x – y))) );
lmn(index_i, index_j) = integral2(funb, xi1_i, xi2_i, xj1_j, xj2_j, ‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
end
% Assign to zmn
zmn(index_i, index_j) = lmn(index_i, index_j);
end
end
% Compute gm vector using a single for-loop
for index_i = 1:N
xi1 = (index_i – 1) * dftm;
xi2 = xi1 + dftm;
func = @(x)B.* triangle_basisn(x, index_i) .* (E_in_z(x));
gm(index_i) = integral(func, xi1, xi2, ‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
end
% Solve the linear system
epsilon_reg = 1e-10; % Regularization parameter (can be adjusted)
zmn = zmn + epsilon_reg * eye(N); % Add small value to the diagonal
% Solve the linear system
Is = linsolve(zmn, gm’);
end
the scattering field
function z = Escat(r, phi)
% Load parameters
[f, N, ra, k0, Z0, lambda] = parameter();
[Is] = currentMoM(); % Retrieve the current distribution
% Preallocate for final result
FINAL = zeros(size(r)); % Initialize FINAL to the same size as r
dfpulse = 2 * pi / N;
Phi0 = (0:N-1) * dfpulse; % Angle steps (in radians)
coif = (k0 * Z0 / 4); % Coefficient to scale the results
% Create a column vector of Phi0 values
x1 = Phi0(:);
x2 = x1 + dfpulse; % Integration limits (x1, x2)
% Loop to compute the scattered field for each combination of rho and phi
for jj = 1:N
% Ensure phi and r are compatible in size for broadcasting
r_squared = r.^2; % Compute r squared
ra_squared = ra.^2;
% Compute the integrand term
% Define the integrand with the properly dimensioned term
integrand = @(y)besselh(0, 2, k0 * sqrt(r_squared + ra_squared – 2*r.*ra .*cos(phi-y)));
% Perform the numerical integration for each jj
FINAL = FINAL -coif * Is(jj).* ra .* integral(integrand, x1(jj), x2(jj),’ArrayValued’,true);
end
% Return the result
z = FINAL;
end
function z = Escat(r,phi)
[~,N,ra,k0,Z0,~] =parameter();
Is=currentMoM();
%Phi0=zeros(N);
FINAL=0;
A=(k0.*Z0./4);
dftm=2.*pi./N;
%index=1:N
%Phi0=(index-2)*dftm;
Phi0=(0:N-1).*dftm;
x1 = Phi0(:); % Create a column vector of x1 values
x2 = x1 + dftm; % x2 values depend on x1
for jj=1:N
F=@(y)besselh(0,2,k0*sqrt(r.^2 + ra.^2-2.*r.*ra.*cos(phi-y))).* triangle_basisn(y,jj);
% Perform the integral
%pts = optimset(‘TolFun’,1e-6); % Adjust tolerance
%integral_result = integral(integrand, lower_limit, upper_limit, ‘ArrayValued’, true);
integral_result=integral(F,x1(jj),x2(jj),’RelTol’, 1e-6, ‘AbsTol’, 1e-6,’ArrayValued’,false);
% Accumulate the result
FINAL = FINAL-A.*Is(jj).*ra.*integral_result;
end
z=FINAL;
end
function [f,N,ra,k0,Z0,lambda] = parameter()
%UNTITLED Summary of this function goes here
c0=3e8;
Z0=120.*pi;
ra=1;
N=60;
f=300e6;
lambda=c0./f;
k0=2*pi./lambda;
end
and teh triangle basis function
function z = triangle_basisn(phi, k)
% Get number of segments (N) and compute segment width (dftm)
[~, N, ~, ~, ~, ~] = parameter();
df = 2*pi/ N; % Segment width
% Compute the left and right boundaries for the triangle basis
left_bound = (k – 2) * df;
right_bound = (k – 1) * df;
center_bound = k * df;
% Check if phi lies within the support of the triangular basis function
if phi >= left_bound & phi <= right_bound
% Left part of the triangle
z = (phi – left_bound) / df;
elseif phi > right_bound & phi <= center_bound
% Right part of the triangle
z = (center_bound – phi) / df;
else
% Outside the support of the triangle
z = 0;
end
end
function z=E_in_z(phi)
%amplitude
[f,N,ra,k0,Z0] = parameter();
E0=1;
%z=E0.*exp(j.*k0.*ra.*cos(phi)+j.*k0.*ra.*sin(phi));
z=E0.*exp(+j.*k0.*ra.*cos(phi));
end
for the triangle
function z=E_in_z(phi)
%amplitude
[f,N,ra,k0,Z0] = parameter();
E0=1;
%z=E0.*exp(j.*k0.*ra.*cos(phi)+j.*k0.*ra.*sin(phi));
z=E0.*exp(-j.*k0.*ra.*cos(phi));
end
for the pulse
thank you
George
the main script is
clear all
clc
[f,N,ra,k0,Z0,lambda] = parameter();
%ph_i=pi/2;
rho=6*lambda ;
phi=-pi:pi/180:pi;
Es=zeros(size(phi));
phi_d=zeros(size(phi));
%phi=0:pi/200:pi/3
tic
parfor jj=1:length(phi)
Es(jj)=abs(Escat(rho,phi(jj)));
phi_d(jj)=phi(jj).*(180/pi);
end
plot(phi_d,Es,’b–‘,’LineWidth’,2)Hi
i find the scattering field in cylinder and i use the MOM method with the triangle basis and pulse. The |Es
| are the same when then incoming field are Einc= E0*exp(-j*k0*r*cos(φ)) in MOM pulse and Einc= E0*exp(j*k0*r*cos(φ)) in MOM triangle.
This the pulse current
function [Is] = currentMoM()
% Load parameters
[f, N, ra, k0, Z0, lambda] = parameter();
% Constants
gamma_const = 1.781;
dfpm = 2*pi/N;
Phi0 = (0:N-1) * dfpm;
% Precompute pairwise phase differences
deltaPhi = zeros(N, N); % Initialize deltaPhi matrix
for i = 1:N
for j = 1:N
deltaPhi(i, j) = Phi0(i) – Phi0(j); % Calculate pairwise phase differences
end
end
% Compute distance matrix R (N x N matrix)
R = zeros(N, N); % Initialize R matrix
for i = 1:N
for j = 1:N
R(i, j) = ra * sqrt(2 – 2 * cos(deltaPhi(i, j))); % Compute distance matrix R
end
end
% Coefficients
coeif1 = (Z0 * k0 / 4) * ra * dfpm;
coeif2 = (Z0 / 2) * sin(k0 * ra * dfpm/ 2);
coeif3 = (gamma_const * k0 * ra * dfpm) / 4;
% Compute lmn matrix
lmn = zeros(N, N); % Initialize lmn matrix
for i = 1:N
for j = 1:N
if i==j
lmn(i, j) = coeif1 * (1 – 1i * (2 / pi) * (log(coeif3) – 1)); % Diagonal elements
else
lmn(i, j) = coeif2 * besselh(0, 2, k0 * R(i, j)); % Compute each element of lmn
end
end
zmn = lmn;
end
% Handle diagonal elements separately
% Set zmn equal to lmn
% Compute gm vector using a for loop
gm = zeros(N, 1); % Initialize gm vector
for i = 1:N
gm(i) = E_in_z(Phi0(i)); % Calculate each element of gm using E_in_z function
end
% Solve for currents using linsolve
%Is = linsolve(zmn, gm);
Is = zmn gm;
%Is=linsolve(zmn, gm)
end
and the triangke
function [Is] = currentMoM()
% Parameter initialization
[~, N, ra, k0, Z0, ~] = parameter();
gamma_const = 1.781;
Eps = 1e-9;
dftm =2.*pi./N;
% Precompute constants
B = (4./(Z0 * k0));
A = (gamma_const*k0*ra)./2;
% Initialize matrices and vectors
lmn = zeros(N, N); % (N x N) matrix for lmn
gm = zeros(1, N); % (1 x N) vector for gm
zmn = zeros(N, N); % (N x N) matrix for zmn
% Compute lmn and zmn matrices using nested for-loops
for index_i = 1:N
for index_j = 1:N
% Precompute integration bounds
xi1_i = (index_i – 1) * dftm;
xi2_i = xi1_i + dftm;
xj1_j = (index_j – 1) * dftm;
xj2_j = xj1_j + dftm;
%log(A) +log(abs(x – y) +Eps))
if index_i == index_j
% Diagonal elements
funa = @(x, y) triangle_basisn(x, index_i) .* triangle_basisn(y, index_j) .*ra .* (1 – 1i * (2./pi).*(log(A) +log(abs(x – y) +Eps))) ;
lmn(index_i, index_j) = integral2(funa, xi1_i, xi2_i, xj1_j, xj2_j,’RelTol’, 1e-6, ‘AbsTol’, 1e-6,’Method’,’iterated’);
else
% Off-diagonal elements
funb = @(x, y)triangle_basisn(x, index_i) .* triangle_basisn(y, index_j) .*ra .* besselh(0, 2, k0.*ra.*sqrt(abs(2 – 2 * cos(x – y))) );
lmn(index_i, index_j) = integral2(funb, xi1_i, xi2_i, xj1_j, xj2_j, ‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
end
% Assign to zmn
zmn(index_i, index_j) = lmn(index_i, index_j);
end
end
% Compute gm vector using a single for-loop
for index_i = 1:N
xi1 = (index_i – 1) * dftm;
xi2 = xi1 + dftm;
func = @(x)B.* triangle_basisn(x, index_i) .* (E_in_z(x));
gm(index_i) = integral(func, xi1, xi2, ‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
end
% Solve the linear system
epsilon_reg = 1e-10; % Regularization parameter (can be adjusted)
zmn = zmn + epsilon_reg * eye(N); % Add small value to the diagonal
% Solve the linear system
Is = linsolve(zmn, gm’);
end
the scattering field
function z = Escat(r, phi)
% Load parameters
[f, N, ra, k0, Z0, lambda] = parameter();
[Is] = currentMoM(); % Retrieve the current distribution
% Preallocate for final result
FINAL = zeros(size(r)); % Initialize FINAL to the same size as r
dfpulse = 2 * pi / N;
Phi0 = (0:N-1) * dfpulse; % Angle steps (in radians)
coif = (k0 * Z0 / 4); % Coefficient to scale the results
% Create a column vector of Phi0 values
x1 = Phi0(:);
x2 = x1 + dfpulse; % Integration limits (x1, x2)
% Loop to compute the scattered field for each combination of rho and phi
for jj = 1:N
% Ensure phi and r are compatible in size for broadcasting
r_squared = r.^2; % Compute r squared
ra_squared = ra.^2;
% Compute the integrand term
% Define the integrand with the properly dimensioned term
integrand = @(y)besselh(0, 2, k0 * sqrt(r_squared + ra_squared – 2*r.*ra .*cos(phi-y)));
% Perform the numerical integration for each jj
FINAL = FINAL -coif * Is(jj).* ra .* integral(integrand, x1(jj), x2(jj),’ArrayValued’,true);
end
% Return the result
z = FINAL;
end
function z = Escat(r,phi)
[~,N,ra,k0,Z0,~] =parameter();
Is=currentMoM();
%Phi0=zeros(N);
FINAL=0;
A=(k0.*Z0./4);
dftm=2.*pi./N;
%index=1:N
%Phi0=(index-2)*dftm;
Phi0=(0:N-1).*dftm;
x1 = Phi0(:); % Create a column vector of x1 values
x2 = x1 + dftm; % x2 values depend on x1
for jj=1:N
F=@(y)besselh(0,2,k0*sqrt(r.^2 + ra.^2-2.*r.*ra.*cos(phi-y))).* triangle_basisn(y,jj);
% Perform the integral
%pts = optimset(‘TolFun’,1e-6); % Adjust tolerance
%integral_result = integral(integrand, lower_limit, upper_limit, ‘ArrayValued’, true);
integral_result=integral(F,x1(jj),x2(jj),’RelTol’, 1e-6, ‘AbsTol’, 1e-6,’ArrayValued’,false);
% Accumulate the result
FINAL = FINAL-A.*Is(jj).*ra.*integral_result;
end
z=FINAL;
end
function [f,N,ra,k0,Z0,lambda] = parameter()
%UNTITLED Summary of this function goes here
c0=3e8;
Z0=120.*pi;
ra=1;
N=60;
f=300e6;
lambda=c0./f;
k0=2*pi./lambda;
end
and teh triangle basis function
function z = triangle_basisn(phi, k)
% Get number of segments (N) and compute segment width (dftm)
[~, N, ~, ~, ~, ~] = parameter();
df = 2*pi/ N; % Segment width
% Compute the left and right boundaries for the triangle basis
left_bound = (k – 2) * df;
right_bound = (k – 1) * df;
center_bound = k * df;
% Check if phi lies within the support of the triangular basis function
if phi >= left_bound & phi <= right_bound
% Left part of the triangle
z = (phi – left_bound) / df;
elseif phi > right_bound & phi <= center_bound
% Right part of the triangle
z = (center_bound – phi) / df;
else
% Outside the support of the triangle
z = 0;
end
end
function z=E_in_z(phi)
%amplitude
[f,N,ra,k0,Z0] = parameter();
E0=1;
%z=E0.*exp(j.*k0.*ra.*cos(phi)+j.*k0.*ra.*sin(phi));
z=E0.*exp(+j.*k0.*ra.*cos(phi));
end
for the triangle
function z=E_in_z(phi)
%amplitude
[f,N,ra,k0,Z0] = parameter();
E0=1;
%z=E0.*exp(j.*k0.*ra.*cos(phi)+j.*k0.*ra.*sin(phi));
z=E0.*exp(-j.*k0.*ra.*cos(phi));
end
for the pulse
thank you
George
the main script is
clear all
clc
[f,N,ra,k0,Z0,lambda] = parameter();
%ph_i=pi/2;
rho=6*lambda ;
phi=-pi:pi/180:pi;
Es=zeros(size(phi));
phi_d=zeros(size(phi));
%phi=0:pi/200:pi/3
tic
parfor jj=1:length(phi)
Es(jj)=abs(Escat(rho,phi(jj)));
phi_d(jj)=phi(jj).*(180/pi);
end
plot(phi_d,Es,’b–‘,’LineWidth’,2) Hi
i find the scattering field in cylinder and i use the MOM method with the triangle basis and pulse. The |Es
| are the same when then incoming field are Einc= E0*exp(-j*k0*r*cos(φ)) in MOM pulse and Einc= E0*exp(j*k0*r*cos(φ)) in MOM triangle.
This the pulse current
function [Is] = currentMoM()
% Load parameters
[f, N, ra, k0, Z0, lambda] = parameter();
% Constants
gamma_const = 1.781;
dfpm = 2*pi/N;
Phi0 = (0:N-1) * dfpm;
% Precompute pairwise phase differences
deltaPhi = zeros(N, N); % Initialize deltaPhi matrix
for i = 1:N
for j = 1:N
deltaPhi(i, j) = Phi0(i) – Phi0(j); % Calculate pairwise phase differences
end
end
% Compute distance matrix R (N x N matrix)
R = zeros(N, N); % Initialize R matrix
for i = 1:N
for j = 1:N
R(i, j) = ra * sqrt(2 – 2 * cos(deltaPhi(i, j))); % Compute distance matrix R
end
end
% Coefficients
coeif1 = (Z0 * k0 / 4) * ra * dfpm;
coeif2 = (Z0 / 2) * sin(k0 * ra * dfpm/ 2);
coeif3 = (gamma_const * k0 * ra * dfpm) / 4;
% Compute lmn matrix
lmn = zeros(N, N); % Initialize lmn matrix
for i = 1:N
for j = 1:N
if i==j
lmn(i, j) = coeif1 * (1 – 1i * (2 / pi) * (log(coeif3) – 1)); % Diagonal elements
else
lmn(i, j) = coeif2 * besselh(0, 2, k0 * R(i, j)); % Compute each element of lmn
end
end
zmn = lmn;
end
% Handle diagonal elements separately
% Set zmn equal to lmn
% Compute gm vector using a for loop
gm = zeros(N, 1); % Initialize gm vector
for i = 1:N
gm(i) = E_in_z(Phi0(i)); % Calculate each element of gm using E_in_z function
end
% Solve for currents using linsolve
%Is = linsolve(zmn, gm);
Is = zmn gm;
%Is=linsolve(zmn, gm)
end
and the triangke
function [Is] = currentMoM()
% Parameter initialization
[~, N, ra, k0, Z0, ~] = parameter();
gamma_const = 1.781;
Eps = 1e-9;
dftm =2.*pi./N;
% Precompute constants
B = (4./(Z0 * k0));
A = (gamma_const*k0*ra)./2;
% Initialize matrices and vectors
lmn = zeros(N, N); % (N x N) matrix for lmn
gm = zeros(1, N); % (1 x N) vector for gm
zmn = zeros(N, N); % (N x N) matrix for zmn
% Compute lmn and zmn matrices using nested for-loops
for index_i = 1:N
for index_j = 1:N
% Precompute integration bounds
xi1_i = (index_i – 1) * dftm;
xi2_i = xi1_i + dftm;
xj1_j = (index_j – 1) * dftm;
xj2_j = xj1_j + dftm;
%log(A) +log(abs(x – y) +Eps))
if index_i == index_j
% Diagonal elements
funa = @(x, y) triangle_basisn(x, index_i) .* triangle_basisn(y, index_j) .*ra .* (1 – 1i * (2./pi).*(log(A) +log(abs(x – y) +Eps))) ;
lmn(index_i, index_j) = integral2(funa, xi1_i, xi2_i, xj1_j, xj2_j,’RelTol’, 1e-6, ‘AbsTol’, 1e-6,’Method’,’iterated’);
else
% Off-diagonal elements
funb = @(x, y)triangle_basisn(x, index_i) .* triangle_basisn(y, index_j) .*ra .* besselh(0, 2, k0.*ra.*sqrt(abs(2 – 2 * cos(x – y))) );
lmn(index_i, index_j) = integral2(funb, xi1_i, xi2_i, xj1_j, xj2_j, ‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
end
% Assign to zmn
zmn(index_i, index_j) = lmn(index_i, index_j);
end
end
% Compute gm vector using a single for-loop
for index_i = 1:N
xi1 = (index_i – 1) * dftm;
xi2 = xi1 + dftm;
func = @(x)B.* triangle_basisn(x, index_i) .* (E_in_z(x));
gm(index_i) = integral(func, xi1, xi2, ‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
end
% Solve the linear system
epsilon_reg = 1e-10; % Regularization parameter (can be adjusted)
zmn = zmn + epsilon_reg * eye(N); % Add small value to the diagonal
% Solve the linear system
Is = linsolve(zmn, gm’);
end
the scattering field
function z = Escat(r, phi)
% Load parameters
[f, N, ra, k0, Z0, lambda] = parameter();
[Is] = currentMoM(); % Retrieve the current distribution
% Preallocate for final result
FINAL = zeros(size(r)); % Initialize FINAL to the same size as r
dfpulse = 2 * pi / N;
Phi0 = (0:N-1) * dfpulse; % Angle steps (in radians)
coif = (k0 * Z0 / 4); % Coefficient to scale the results
% Create a column vector of Phi0 values
x1 = Phi0(:);
x2 = x1 + dfpulse; % Integration limits (x1, x2)
% Loop to compute the scattered field for each combination of rho and phi
for jj = 1:N
% Ensure phi and r are compatible in size for broadcasting
r_squared = r.^2; % Compute r squared
ra_squared = ra.^2;
% Compute the integrand term
% Define the integrand with the properly dimensioned term
integrand = @(y)besselh(0, 2, k0 * sqrt(r_squared + ra_squared – 2*r.*ra .*cos(phi-y)));
% Perform the numerical integration for each jj
FINAL = FINAL -coif * Is(jj).* ra .* integral(integrand, x1(jj), x2(jj),’ArrayValued’,true);
end
% Return the result
z = FINAL;
end
function z = Escat(r,phi)
[~,N,ra,k0,Z0,~] =parameter();
Is=currentMoM();
%Phi0=zeros(N);
FINAL=0;
A=(k0.*Z0./4);
dftm=2.*pi./N;
%index=1:N
%Phi0=(index-2)*dftm;
Phi0=(0:N-1).*dftm;
x1 = Phi0(:); % Create a column vector of x1 values
x2 = x1 + dftm; % x2 values depend on x1
for jj=1:N
F=@(y)besselh(0,2,k0*sqrt(r.^2 + ra.^2-2.*r.*ra.*cos(phi-y))).* triangle_basisn(y,jj);
% Perform the integral
%pts = optimset(‘TolFun’,1e-6); % Adjust tolerance
%integral_result = integral(integrand, lower_limit, upper_limit, ‘ArrayValued’, true);
integral_result=integral(F,x1(jj),x2(jj),’RelTol’, 1e-6, ‘AbsTol’, 1e-6,’ArrayValued’,false);
% Accumulate the result
FINAL = FINAL-A.*Is(jj).*ra.*integral_result;
end
z=FINAL;
end
function [f,N,ra,k0,Z0,lambda] = parameter()
%UNTITLED Summary of this function goes here
c0=3e8;
Z0=120.*pi;
ra=1;
N=60;
f=300e6;
lambda=c0./f;
k0=2*pi./lambda;
end
and teh triangle basis function
function z = triangle_basisn(phi, k)
% Get number of segments (N) and compute segment width (dftm)
[~, N, ~, ~, ~, ~] = parameter();
df = 2*pi/ N; % Segment width
% Compute the left and right boundaries for the triangle basis
left_bound = (k – 2) * df;
right_bound = (k – 1) * df;
center_bound = k * df;
% Check if phi lies within the support of the triangular basis function
if phi >= left_bound & phi <= right_bound
% Left part of the triangle
z = (phi – left_bound) / df;
elseif phi > right_bound & phi <= center_bound
% Right part of the triangle
z = (center_bound – phi) / df;
else
% Outside the support of the triangle
z = 0;
end
end
function z=E_in_z(phi)
%amplitude
[f,N,ra,k0,Z0] = parameter();
E0=1;
%z=E0.*exp(j.*k0.*ra.*cos(phi)+j.*k0.*ra.*sin(phi));
z=E0.*exp(+j.*k0.*ra.*cos(phi));
end
for the triangle
function z=E_in_z(phi)
%amplitude
[f,N,ra,k0,Z0] = parameter();
E0=1;
%z=E0.*exp(j.*k0.*ra.*cos(phi)+j.*k0.*ra.*sin(phi));
z=E0.*exp(-j.*k0.*ra.*cos(phi));
end
for the pulse
thank you
George
the main script is
clear all
clc
[f,N,ra,k0,Z0,lambda] = parameter();
%ph_i=pi/2;
rho=6*lambda ;
phi=-pi:pi/180:pi;
Es=zeros(size(phi));
phi_d=zeros(size(phi));
%phi=0:pi/200:pi/3
tic
parfor jj=1:length(phi)
Es(jj)=abs(Escat(rho,phi(jj)));
phi_d(jj)=phi(jj).*(180/pi);
end
plot(phi_d,Es,’b–‘,’LineWidth’,2) mom, matrix, scattering MATLAB Answers — New Questions
What are ways to generate .NET code from Matlab/Simulink?
*I need to share my Matlab codes and algorithms to use for a .NET application. What are the different ways to get this done.*
I know that with the use of Matlab Compiler SDK we can build .NET apps.
Any other way to do so without having Matlab Compiler SDK. I have licenses for Matlab and simulink Coder.
It would be great if we can discuss limitations of the workarounds.*I need to share my Matlab codes and algorithms to use for a .NET application. What are the different ways to get this done.*
I know that with the use of Matlab Compiler SDK we can build .NET apps.
Any other way to do so without having Matlab Compiler SDK. I have licenses for Matlab and simulink Coder.
It would be great if we can discuss limitations of the workarounds. *I need to share my Matlab codes and algorithms to use for a .NET application. What are the different ways to get this done.*
I know that with the use of Matlab Compiler SDK we can build .NET apps.
Any other way to do so without having Matlab Compiler SDK. I have licenses for Matlab and simulink Coder.
It would be great if we can discuss limitations of the workarounds. matlab coder, code generation, .net, java, matlab compiler MATLAB Answers — New Questions
What is the simplest way to transfer my MATLAB settings from linux to windows (specifically: modified keyboard shortcut settings and the path to my library stored in Dropbox)
I do most of my work in Linux but sometime have to use Windows for certain applications. I have MATLAB on both but have only recently wanted to use MATLAB on Windows. What is the simplest method for transferring my settings from Linux to Windows? I have my library of m files stored on Dropbox but I do not actually put every subfolder into the path. I also store my `.matlab/` directory in Dropbox (sync setting between my Linux desktop and laptop) and can see my `EmacsModifiedDefaultSet.xml` file with my keyboard preferences but MATLAB says it cannot import that.
I doubt it would be possible to sync the keyboard shortcuts file but if not, please let me know.I do most of my work in Linux but sometime have to use Windows for certain applications. I have MATLAB on both but have only recently wanted to use MATLAB on Windows. What is the simplest method for transferring my settings from Linux to Windows? I have my library of m files stored on Dropbox but I do not actually put every subfolder into the path. I also store my `.matlab/` directory in Dropbox (sync setting between my Linux desktop and laptop) and can see my `EmacsModifiedDefaultSet.xml` file with my keyboard preferences but MATLAB says it cannot import that.
I doubt it would be possible to sync the keyboard shortcuts file but if not, please let me know. I do most of my work in Linux but sometime have to use Windows for certain applications. I have MATLAB on both but have only recently wanted to use MATLAB on Windows. What is the simplest method for transferring my settings from Linux to Windows? I have my library of m files stored on Dropbox but I do not actually put every subfolder into the path. I also store my `.matlab/` directory in Dropbox (sync setting between my Linux desktop and laptop) and can see my `EmacsModifiedDefaultSet.xml` file with my keyboard preferences but MATLAB says it cannot import that.
I doubt it would be possible to sync the keyboard shortcuts file but if not, please let me know. settings, path, windows, linux, preferences MATLAB Answers — New Questions
plot multiple points in multiple colors
I am trying to plot the peaks and their harmonics. Figure 5 plots the peaks between 0-135 Hz and figure 6 plots the peaks and their harmonics between the normal frequency range i.e. 0-2000 Hz.
The first part of Figure 6 plots normal graph between freq_s(0-2000 Hz) and Signal_fft_hilbert. I want to plot xx2 peaks on this plot. I am not able to draw this plot. I want to mark these points in different colors for each ‘k’.Also I am getting error with regards to size of freq_s and xx2. Can somebody suggest anything?
figure(5)
ind = (freq_s>=0 & freq_s<= 135); %// logical index to select desired range
[peaks, locs] = findpeaks(abs(Signal_fft_hilbert(ind)))
plot(freq_s(locs),abs(Signal_fft_hilbert(locs)))
hold on
plot(freq_s(locs),peaks,’*g’)
for k=1:length(peaks)
z=z+1;
top1{k}=freq_s(locs(k));
for s1=1:length(peaks)
xx{s1}=top1{k}*s1;
end
[xx1]=[xx(:)]
xx2=cell2mat(xx1);
figure(6)
plot(freq_s(2:250),abs(Signal_fft_hilbert(2:250)))
hold on
plot(freq_s,xx2,’*g’)
endI am trying to plot the peaks and their harmonics. Figure 5 plots the peaks between 0-135 Hz and figure 6 plots the peaks and their harmonics between the normal frequency range i.e. 0-2000 Hz.
The first part of Figure 6 plots normal graph between freq_s(0-2000 Hz) and Signal_fft_hilbert. I want to plot xx2 peaks on this plot. I am not able to draw this plot. I want to mark these points in different colors for each ‘k’.Also I am getting error with regards to size of freq_s and xx2. Can somebody suggest anything?
figure(5)
ind = (freq_s>=0 & freq_s<= 135); %// logical index to select desired range
[peaks, locs] = findpeaks(abs(Signal_fft_hilbert(ind)))
plot(freq_s(locs),abs(Signal_fft_hilbert(locs)))
hold on
plot(freq_s(locs),peaks,’*g’)
for k=1:length(peaks)
z=z+1;
top1{k}=freq_s(locs(k));
for s1=1:length(peaks)
xx{s1}=top1{k}*s1;
end
[xx1]=[xx(:)]
xx2=cell2mat(xx1);
figure(6)
plot(freq_s(2:250),abs(Signal_fft_hilbert(2:250)))
hold on
plot(freq_s,xx2,’*g’)
end I am trying to plot the peaks and their harmonics. Figure 5 plots the peaks between 0-135 Hz and figure 6 plots the peaks and their harmonics between the normal frequency range i.e. 0-2000 Hz.
The first part of Figure 6 plots normal graph between freq_s(0-2000 Hz) and Signal_fft_hilbert. I want to plot xx2 peaks on this plot. I am not able to draw this plot. I want to mark these points in different colors for each ‘k’.Also I am getting error with regards to size of freq_s and xx2. Can somebody suggest anything?
figure(5)
ind = (freq_s>=0 & freq_s<= 135); %// logical index to select desired range
[peaks, locs] = findpeaks(abs(Signal_fft_hilbert(ind)))
plot(freq_s(locs),abs(Signal_fft_hilbert(locs)))
hold on
plot(freq_s(locs),peaks,’*g’)
for k=1:length(peaks)
z=z+1;
top1{k}=freq_s(locs(k));
for s1=1:length(peaks)
xx{s1}=top1{k}*s1;
end
[xx1]=[xx(:)]
xx2=cell2mat(xx1);
figure(6)
plot(freq_s(2:250),abs(Signal_fft_hilbert(2:250)))
hold on
plot(freq_s,xx2,’*g’)
end color, multiple, plot MATLAB Answers — New Questions
How to Programmatically Create S-function in Matlab r2023a
Hi,
i would like to know how using m-script we can create the S-function for a top level subsystem.Manually i am able to achive this by right clicking on the subsystem->C/C++ Code->Generate S-function.Any answers related to S-function viw m-script are welcome
Thanks for your support in advance.Hi,
i would like to know how using m-script we can create the S-function for a top level subsystem.Manually i am able to achive this by right clicking on the subsystem->C/C++ Code->Generate S-function.Any answers related to S-function viw m-script are welcome
Thanks for your support in advance. Hi,
i would like to know how using m-script we can create the S-function for a top level subsystem.Manually i am able to achive this by right clicking on the subsystem->C/C++ Code->Generate S-function.Any answers related to S-function viw m-script are welcome
Thanks for your support in advance. s-function MATLAB Answers — New Questions
I want to test if this page has any issues or not
testtest test test MATLAB Answers — New Questions
How do I connect and read data from pixhawk 6x when using simulink/ UAVToolbox?
I am trying to have a play around with simulink and the UAVToolbox but am having issues in simply connecting to the pixhawk.
During the hardware setup for PX4 in simulink, (building firmware, uploading, testing connection etc), I am unable to read accelerometer data, however the odd thing is that I AM able to build and upload the firmware. I am very confused as to why it can connect when uploading, but not when trying to read data. Additionally I dont have this problem when using things such as QGC.
As far as I am aware, the port for uploading is the same as reading (/dev/ttyACM0), regardless of this I have tried various ports and still no connection.
What do I need to do for this to connect and read from my pixhawk?
Note: I am trying to do this with pixhawk 6x as the target to be deployed in to a physical aircraft, NOT SITL or HITL, alot of the examples and tutorials cover only simulated scenarios and they are not helpful in my current situation, so please do not refer me to any of them unless it specifically refers to a connection issue like this, thank you.
System – Ubuntu 20.04
any help would be great,
thanksI am trying to have a play around with simulink and the UAVToolbox but am having issues in simply connecting to the pixhawk.
During the hardware setup for PX4 in simulink, (building firmware, uploading, testing connection etc), I am unable to read accelerometer data, however the odd thing is that I AM able to build and upload the firmware. I am very confused as to why it can connect when uploading, but not when trying to read data. Additionally I dont have this problem when using things such as QGC.
As far as I am aware, the port for uploading is the same as reading (/dev/ttyACM0), regardless of this I have tried various ports and still no connection.
What do I need to do for this to connect and read from my pixhawk?
Note: I am trying to do this with pixhawk 6x as the target to be deployed in to a physical aircraft, NOT SITL or HITL, alot of the examples and tutorials cover only simulated scenarios and they are not helpful in my current situation, so please do not refer me to any of them unless it specifically refers to a connection issue like this, thank you.
System – Ubuntu 20.04
any help would be great,
thanks I am trying to have a play around with simulink and the UAVToolbox but am having issues in simply connecting to the pixhawk.
During the hardware setup for PX4 in simulink, (building firmware, uploading, testing connection etc), I am unable to read accelerometer data, however the odd thing is that I AM able to build and upload the firmware. I am very confused as to why it can connect when uploading, but not when trying to read data. Additionally I dont have this problem when using things such as QGC.
As far as I am aware, the port for uploading is the same as reading (/dev/ttyACM0), regardless of this I have tried various ports and still no connection.
What do I need to do for this to connect and read from my pixhawk?
Note: I am trying to do this with pixhawk 6x as the target to be deployed in to a physical aircraft, NOT SITL or HITL, alot of the examples and tutorials cover only simulated scenarios and they are not helpful in my current situation, so please do not refer me to any of them unless it specifically refers to a connection issue like this, thank you.
System – Ubuntu 20.04
any help would be great,
thanks pixhawk, px4, linux MATLAB Answers — New Questions
Bought new computer. What is procedure to transfer Matlab?
Bought new computer. What is procedure to transfer Matlab? I have Home license.Bought new computer. What is procedure to transfer Matlab? I have Home license. Bought new computer. What is procedure to transfer Matlab? I have Home license. new computer MATLAB Answers — New Questions
I am getting the error message “Device discovery error: input stream error”
I’m using N1 210 rev 4 usrp radio and I want to use it in Matlab environment.
My problem is the following. If I type "findsdru" in Matlab command line, then I get the following result.
———- begin libuhd error message output ———-
Device discovery error: input stream error
———- end libuhd error message output ———-
ans =
Platform: ‘N200/N210/USRP2’
IPAddress: ‘192.168.10.2’
SerialNum: ‘E7R26M7UP’
Status: ‘Success’
It seems the Matlab finds the usrp device well, but I couldn’t figure out why the error message "Device discovery error: input stream error" occurs.
How can I fix this?I’m using N1 210 rev 4 usrp radio and I want to use it in Matlab environment.
My problem is the following. If I type "findsdru" in Matlab command line, then I get the following result.
———- begin libuhd error message output ———-
Device discovery error: input stream error
———- end libuhd error message output ———-
ans =
Platform: ‘N200/N210/USRP2’
IPAddress: ‘192.168.10.2’
SerialNum: ‘E7R26M7UP’
Status: ‘Success’
It seems the Matlab finds the usrp device well, but I couldn’t figure out why the error message "Device discovery error: input stream error" occurs.
How can I fix this? I’m using N1 210 rev 4 usrp radio and I want to use it in Matlab environment.
My problem is the following. If I type "findsdru" in Matlab command line, then I get the following result.
———- begin libuhd error message output ———-
Device discovery error: input stream error
———- end libuhd error message output ———-
ans =
Platform: ‘N200/N210/USRP2’
IPAddress: ‘192.168.10.2’
SerialNum: ‘E7R26M7UP’
Status: ‘Success’
It seems the Matlab finds the usrp device well, but I couldn’t figure out why the error message "Device discovery error: input stream error" occurs.
How can I fix this? usrp, error MATLAB Answers — New Questions
How to get height sensor and ground feedback when UAV Simulink and UE joint simulation
Hello, I’m conducting joint simulation of UAV using MATLAB/Simulink 2023b and UE4.27.
I couldn’t find any sensors related to UAV altitude in Simulink. I want to obtain the height data between the current position of the UAV and the road directly beneath it.
Additionally, I’d like to know if there are any functional modules related to ground feedback during the UAV simulation process.Hello, I’m conducting joint simulation of UAV using MATLAB/Simulink 2023b and UE4.27.
I couldn’t find any sensors related to UAV altitude in Simulink. I want to obtain the height data between the current position of the UAV and the road directly beneath it.
Additionally, I’d like to know if there are any functional modules related to ground feedback during the UAV simulation process. Hello, I’m conducting joint simulation of UAV using MATLAB/Simulink 2023b and UE4.27.
I couldn’t find any sensors related to UAV altitude in Simulink. I want to obtain the height data between the current position of the UAV and the road directly beneath it.
Additionally, I’d like to know if there are any functional modules related to ground feedback during the UAV simulation process. uav MATLAB Answers — New Questions
I am struggling to modify the “Highway lane change” example.
I am trying to implement the "Highway lane change" example with my own controller. Initially I designed my controller such that if I can provide the controller a reference path ( in the form of a N*2 matrix) the controller will be able to follow that path. Now I want to extend my project such that the reference path will be generated autonomously with the help of sensor fusion. I can see the similar thing has been done in the "Highway lane change" project. But for my controller I need to extract the reference X and Y values. But I am struggling to find those 2 values. I have tries with a matlab function block with the following code –
function [X_ref, Y_ref] = extractWaypoints(TrajectoryInfo)
% Extract X and Y waypoints from the planned trajectory
optimalTrajIndex = TrajectoryInfo.OptimalTrajectoryIndex;
trajectory = TrajectoryInfo.GlobalTrajectory(optimalTrajIndex).Trajectory;
% Extract X and Y positions
X_ref = trajectory(:, 1);
Y_ref = trajectory(:, 2);
end
But with this I am getting the error, "Error:’Input Port 1′ of ‘MotionPlanner/Ref_waypoints’ expects a bus but receives a nonbus signal from ‘Output Port 1’ of ‘MotionPlanner/MATLAB Function2’."
I am not sure how to work on this example.I am trying to implement the "Highway lane change" example with my own controller. Initially I designed my controller such that if I can provide the controller a reference path ( in the form of a N*2 matrix) the controller will be able to follow that path. Now I want to extend my project such that the reference path will be generated autonomously with the help of sensor fusion. I can see the similar thing has been done in the "Highway lane change" project. But for my controller I need to extract the reference X and Y values. But I am struggling to find those 2 values. I have tries with a matlab function block with the following code –
function [X_ref, Y_ref] = extractWaypoints(TrajectoryInfo)
% Extract X and Y waypoints from the planned trajectory
optimalTrajIndex = TrajectoryInfo.OptimalTrajectoryIndex;
trajectory = TrajectoryInfo.GlobalTrajectory(optimalTrajIndex).Trajectory;
% Extract X and Y positions
X_ref = trajectory(:, 1);
Y_ref = trajectory(:, 2);
end
But with this I am getting the error, "Error:’Input Port 1′ of ‘MotionPlanner/Ref_waypoints’ expects a bus but receives a nonbus signal from ‘Output Port 1’ of ‘MotionPlanner/MATLAB Function2’."
I am not sure how to work on this example. I am trying to implement the "Highway lane change" example with my own controller. Initially I designed my controller such that if I can provide the controller a reference path ( in the form of a N*2 matrix) the controller will be able to follow that path. Now I want to extend my project such that the reference path will be generated autonomously with the help of sensor fusion. I can see the similar thing has been done in the "Highway lane change" project. But for my controller I need to extract the reference X and Y values. But I am struggling to find those 2 values. I have tries with a matlab function block with the following code –
function [X_ref, Y_ref] = extractWaypoints(TrajectoryInfo)
% Extract X and Y waypoints from the planned trajectory
optimalTrajIndex = TrajectoryInfo.OptimalTrajectoryIndex;
trajectory = TrajectoryInfo.GlobalTrajectory(optimalTrajIndex).Trajectory;
% Extract X and Y positions
X_ref = trajectory(:, 1);
Y_ref = trajectory(:, 2);
end
But with this I am getting the error, "Error:’Input Port 1′ of ‘MotionPlanner/Ref_waypoints’ expects a bus but receives a nonbus signal from ‘Output Port 1’ of ‘MotionPlanner/MATLAB Function2’."
I am not sure how to work on this example. highway lane change controller modification MATLAB Answers — New Questions
Error using feval and Invalid function name
Please friends, i will aprecciate your help,
I have this code:
function I= Trapecios(f,a,b,n)
%Fórmula Trapecios compuesta
h=(b-a)/n;
x=a:h:b;
x=x(:);
for i=1:n-1
k1=feval(f,x(i));
pesos=[1 2*ones(1,n-1) 1];
I=h./2*sum(pesos*k1);
end
end
So when I input the arguments, issues these messagges:
>> Trapecios(‘x/56’,-56/2,9*56/10,8)
Error using feval
Invalid function name ‘x/56’.
Error in Trapecios (line 7)
k1=feval(f,x(i));Please friends, i will aprecciate your help,
I have this code:
function I= Trapecios(f,a,b,n)
%Fórmula Trapecios compuesta
h=(b-a)/n;
x=a:h:b;
x=x(:);
for i=1:n-1
k1=feval(f,x(i));
pesos=[1 2*ones(1,n-1) 1];
I=h./2*sum(pesos*k1);
end
end
So when I input the arguments, issues these messagges:
>> Trapecios(‘x/56’,-56/2,9*56/10,8)
Error using feval
Invalid function name ‘x/56’.
Error in Trapecios (line 7)
k1=feval(f,x(i)); Please friends, i will aprecciate your help,
I have this code:
function I= Trapecios(f,a,b,n)
%Fórmula Trapecios compuesta
h=(b-a)/n;
x=a:h:b;
x=x(:);
for i=1:n-1
k1=feval(f,x(i));
pesos=[1 2*ones(1,n-1) 1];
I=h./2*sum(pesos*k1);
end
end
So when I input the arguments, issues these messagges:
>> Trapecios(‘x/56’,-56/2,9*56/10,8)
Error using feval
Invalid function name ‘x/56’.
Error in Trapecios (line 7)
k1=feval(f,x(i)); feval, function MATLAB Answers — New Questions