Category: Matlab
Category Archives: Matlab
Recreating embedded antenna pattern from isolated element and S-parameter matrix
My objective is to calculate the active element pattern of the central element in a rectangular array. According to Eq. (17) in David M. Pozar’s paper, "A Relation Between the Active Input Impedance and the Active Element Pattern of a Phased Array," this equation provides the embedded pattern of the mth antenna. While I believe I have correctly implemented this function, the results are not as expected. If anyone has experience with similar calculations, I would appreciate any insights or feedback on why there is a discrepancy between complexEmbPattern and complexEmbPattern_.
The conversion from phi/ theta to elevation/azimuth has been done according to Matlab’s: Antenna Toolbox Coordinate System – MATLAB & Simulink (mathworks.com)
Thank you in advance for your assistance!
Physical Constants:
freq = 30e9;
c = physconst(‘lightspeed’);
lambda = c/freq;
wn = 2*pi/lambda;
azimuth = -180:5:180;
elevation = -90:5:90;
Isolated Element:
element = dipole;
element.Length = 0.47*lambda;
element.Width = cylinder2strip(0.191e-3);
figure;
show(element);
isoEfieldPattern = pattern(element, freq, azimuth, elevation, …
‘Type’, ‘efield’);
isoPhasePattern = pattern(element, freq, azimuth, elevation, …
‘Type’, ‘phase’, …
‘Polarization’, ‘V’);
complexIsoPattern = isoEfieldPattern.*exp(1j*deg2rad(isoPhasePattern));
Embedded Element Pattern:
N = 3;
M = 3;
K = M*N;
a = 0.5*lambda;
b = 0.5*lambda;
array = rectangularArray;
array.Element = element;
array.Element.Tilt = 90;
array.Element.TiltAxis = ‘Y’;
array.Size = [N M];
array.ColumnSpacing = a;
array.RowSpacing = b;
array.Tilt = 90;
array.TiltAxis = ‘Y’;
figure;
show(array);
ElemIndex = (prod(array.Size) – 1)/2 + 1;
Zinf = 76 + 1i*31;
embEfieldPattern = pattern(array, freq, azimuth, elevation, …
‘ElementNumber’, ElemIndex, …
‘Termination’, real(Zinf), …
‘Type’, ‘efield’);
embPhasePattern = pattern(array, freq, azimuth, elevation, …
‘ElementNumber’, ElemIndex, …
‘Termination’, real(Zinf), …
‘Type’, ‘phase’, …
‘Polarization’, ‘V’);
complexEmbPattern = embEfieldPattern.*exp(1j*deg2rad(embPhasePattern));
Sparam = sparameters(array, freq, real(Zinf)).Parameters;
complexEmbPattern_ = ones(size(elevation,2),size(azimuth,2));
m = ElemIndex;
for az = 1:length(azimuth)
for el = 1:length(elevation)
u = wn*a*cosd(elevation(el))*sind(azimuth(az));
v = wn*b*sind(elevation(el));
i_m = mod(m – 1, M) + 1;
j_m = floor((m – 1)/M) + 1;
sum = 0;
for n = 1:K
i_n = mod(n – 1, M) + 1;
j_n = floor((n – 1)/M) + 1;
sum = sum + Sparam(n, m)*exp(1i*((i_n – 1)*u + (j_n – 1)*v));
end
complexEmbPattern_(el, az) = complexIsoPattern(el, az)*(exp(1i*((i_m – 1)*u + (j_m – 1)*v)) + sum);
end
endMy objective is to calculate the active element pattern of the central element in a rectangular array. According to Eq. (17) in David M. Pozar’s paper, "A Relation Between the Active Input Impedance and the Active Element Pattern of a Phased Array," this equation provides the embedded pattern of the mth antenna. While I believe I have correctly implemented this function, the results are not as expected. If anyone has experience with similar calculations, I would appreciate any insights or feedback on why there is a discrepancy between complexEmbPattern and complexEmbPattern_.
The conversion from phi/ theta to elevation/azimuth has been done according to Matlab’s: Antenna Toolbox Coordinate System – MATLAB & Simulink (mathworks.com)
Thank you in advance for your assistance!
Physical Constants:
freq = 30e9;
c = physconst(‘lightspeed’);
lambda = c/freq;
wn = 2*pi/lambda;
azimuth = -180:5:180;
elevation = -90:5:90;
Isolated Element:
element = dipole;
element.Length = 0.47*lambda;
element.Width = cylinder2strip(0.191e-3);
figure;
show(element);
isoEfieldPattern = pattern(element, freq, azimuth, elevation, …
‘Type’, ‘efield’);
isoPhasePattern = pattern(element, freq, azimuth, elevation, …
‘Type’, ‘phase’, …
‘Polarization’, ‘V’);
complexIsoPattern = isoEfieldPattern.*exp(1j*deg2rad(isoPhasePattern));
Embedded Element Pattern:
N = 3;
M = 3;
K = M*N;
a = 0.5*lambda;
b = 0.5*lambda;
array = rectangularArray;
array.Element = element;
array.Element.Tilt = 90;
array.Element.TiltAxis = ‘Y’;
array.Size = [N M];
array.ColumnSpacing = a;
array.RowSpacing = b;
array.Tilt = 90;
array.TiltAxis = ‘Y’;
figure;
show(array);
ElemIndex = (prod(array.Size) – 1)/2 + 1;
Zinf = 76 + 1i*31;
embEfieldPattern = pattern(array, freq, azimuth, elevation, …
‘ElementNumber’, ElemIndex, …
‘Termination’, real(Zinf), …
‘Type’, ‘efield’);
embPhasePattern = pattern(array, freq, azimuth, elevation, …
‘ElementNumber’, ElemIndex, …
‘Termination’, real(Zinf), …
‘Type’, ‘phase’, …
‘Polarization’, ‘V’);
complexEmbPattern = embEfieldPattern.*exp(1j*deg2rad(embPhasePattern));
Sparam = sparameters(array, freq, real(Zinf)).Parameters;
complexEmbPattern_ = ones(size(elevation,2),size(azimuth,2));
m = ElemIndex;
for az = 1:length(azimuth)
for el = 1:length(elevation)
u = wn*a*cosd(elevation(el))*sind(azimuth(az));
v = wn*b*sind(elevation(el));
i_m = mod(m – 1, M) + 1;
j_m = floor((m – 1)/M) + 1;
sum = 0;
for n = 1:K
i_n = mod(n – 1, M) + 1;
j_n = floor((n – 1)/M) + 1;
sum = sum + Sparam(n, m)*exp(1i*((i_n – 1)*u + (j_n – 1)*v));
end
complexEmbPattern_(el, az) = complexIsoPattern(el, az)*(exp(1i*((i_m – 1)*u + (j_m – 1)*v)) + sum);
end
end My objective is to calculate the active element pattern of the central element in a rectangular array. According to Eq. (17) in David M. Pozar’s paper, "A Relation Between the Active Input Impedance and the Active Element Pattern of a Phased Array," this equation provides the embedded pattern of the mth antenna. While I believe I have correctly implemented this function, the results are not as expected. If anyone has experience with similar calculations, I would appreciate any insights or feedback on why there is a discrepancy between complexEmbPattern and complexEmbPattern_.
The conversion from phi/ theta to elevation/azimuth has been done according to Matlab’s: Antenna Toolbox Coordinate System – MATLAB & Simulink (mathworks.com)
Thank you in advance for your assistance!
Physical Constants:
freq = 30e9;
c = physconst(‘lightspeed’);
lambda = c/freq;
wn = 2*pi/lambda;
azimuth = -180:5:180;
elevation = -90:5:90;
Isolated Element:
element = dipole;
element.Length = 0.47*lambda;
element.Width = cylinder2strip(0.191e-3);
figure;
show(element);
isoEfieldPattern = pattern(element, freq, azimuth, elevation, …
‘Type’, ‘efield’);
isoPhasePattern = pattern(element, freq, azimuth, elevation, …
‘Type’, ‘phase’, …
‘Polarization’, ‘V’);
complexIsoPattern = isoEfieldPattern.*exp(1j*deg2rad(isoPhasePattern));
Embedded Element Pattern:
N = 3;
M = 3;
K = M*N;
a = 0.5*lambda;
b = 0.5*lambda;
array = rectangularArray;
array.Element = element;
array.Element.Tilt = 90;
array.Element.TiltAxis = ‘Y’;
array.Size = [N M];
array.ColumnSpacing = a;
array.RowSpacing = b;
array.Tilt = 90;
array.TiltAxis = ‘Y’;
figure;
show(array);
ElemIndex = (prod(array.Size) – 1)/2 + 1;
Zinf = 76 + 1i*31;
embEfieldPattern = pattern(array, freq, azimuth, elevation, …
‘ElementNumber’, ElemIndex, …
‘Termination’, real(Zinf), …
‘Type’, ‘efield’);
embPhasePattern = pattern(array, freq, azimuth, elevation, …
‘ElementNumber’, ElemIndex, …
‘Termination’, real(Zinf), …
‘Type’, ‘phase’, …
‘Polarization’, ‘V’);
complexEmbPattern = embEfieldPattern.*exp(1j*deg2rad(embPhasePattern));
Sparam = sparameters(array, freq, real(Zinf)).Parameters;
complexEmbPattern_ = ones(size(elevation,2),size(azimuth,2));
m = ElemIndex;
for az = 1:length(azimuth)
for el = 1:length(elevation)
u = wn*a*cosd(elevation(el))*sind(azimuth(az));
v = wn*b*sind(elevation(el));
i_m = mod(m – 1, M) + 1;
j_m = floor((m – 1)/M) + 1;
sum = 0;
for n = 1:K
i_n = mod(n – 1, M) + 1;
j_n = floor((n – 1)/M) + 1;
sum = sum + Sparam(n, m)*exp(1i*((i_n – 1)*u + (j_n – 1)*v));
end
complexEmbPattern_(el, az) = complexIsoPattern(el, az)*(exp(1i*((i_m – 1)*u + (j_m – 1)*v)) + sum);
end
end s-parameters, embedded element pattern, active element pattern, matlab MATLAB Answers — New Questions
Match analytical and simulation values of SER vs SNR curve.
% Parameters
M = 4; % MQAM order (e.g., 16-QAM)
N = 1e5; % Number of transmit symbols
% Define SNR range
SNR_dB_range = 0:10;
num_SNR_points = length(SNR_dB_range);
% Initialize SER array
SER_values = zeros(num_SNR_points, 1);
% Create MQAM constellation
constellation = createMQAM(M);
% Loop over each SNR value
for idx = 1:num_SNR_points
SNR_dB = SNR_dB_range(idx);
% Generate transmit symbols
transmitSymbols = generateSymbols(constellation, N);
% Transmit through AWGN channel
receivedSymbols = transmitSymbolsThroughAWGN(transmitSymbols, SNR_dB);
% Demodulate symbols
decodedSymbols = demodulateSymbols(receivedSymbols, constellation);
% Compute Symbol Error Rate
SER = computeSER(transmitSymbols, decodedSymbols);
% Store SER value
SER_values(idx) = SER;
% Compute Theoretical SER
SER_theoretical = computeTheoreticalSER(M, SNR_dB_range);
SER_theoretical_values = SER_theoretical;
end
% Plot SER vs SNR
figure;
semilogy(SNR_dB_range, SER_values, ‘o-‘, ‘DisplayName’, ‘Simulated SER’);
hold on;
semilogy(SNR_dB_range, SER_theoretical_values, ‘r–‘, ‘DisplayName’, ‘Theoretical SER’);
xlabel(‘SNR (dB)’);
ylabel(‘Symbol Error Rate (SER)’);
title(‘SER vs. SNR for MQAM’);
legend;
grid on;
function constellation = createMQAM(M)
% Create an MQAM constellation manually
% M: Number of symbols (e.g., 16, 64, etc.)
% Check that M is a perfect square
k = sqrt(M);
if mod(k,1) ~= 0
error(‘M must be a perfect square’);
end
% Generate constellation points
k = round(k); % Number of points per side
[X, Y] = meshgrid(linspace(-k+1, k-1, k), linspace(-k+1, k-1, k));
constellation = X(:) + 1i*Y(:);
end
function symbols = generateSymbols(constellation, N)
% Generate N random transmit symbols
% constellation: The MQAM constellation points
% N: Number of symbols to generate
numPoints = length(constellation);
indices = randi([1 numPoints], [N, 1]); % Randomly choose indices
symbols = constellation(indices); % Select symbols from the constellation
end
function received = transmitSymbolsThroughAWGN(symbols, SNR_dB)
% Transmit symbols through a SISO AWGN channel
% symbols: Transmit symbols
% SNR_dB: Signal-to-noise ratio in dB
% Convert SNR from dB to linear scale
SNR_linear = 10^(SNR_dB / 10);
% Calculate noise variance
noise_variance = 1 / SNR_linear;
% Generate noise
noise = sqrt(noise_variance / 2) * (randn(size(symbols)) + 1i*randn(size(symbols)));
% Received symbols
received = symbols + noise;
end
function decodedSymbols = demodulateSymbols(received, constellation)
% Demodulate symbols using minimum distance decoding
% received: Received symbols
% constellation: MQAM constellation points
numSymbols = length(received);
numPoints = length(constellation);
% Initialize decoded symbols
decodedSymbols = zeros(size(received));
for i = 1:numSymbols
% Compute distances to all constellation points
distances = abs(received(i) – constellation).^2;
% Find the closest constellation point
[~, idx] = min(distances);
decodedSymbols(i) = constellation(idx);
end
end
function SER = computeSER(originalSymbols, decodedSymbols)
% Compute symbol error rate
% originalSymbols: Transmit symbols
% decodedSymbols: Received and decoded symbols
numErrors = sum(originalSymbols ~= decodedSymbols);
totalSymbols = length(originalSymbols);
SER = numErrors / totalSymbols;
end
function SER_theoretical = computeTheoreticalSER(M, SNR_dB)
% Compute the theoretical SER for MQAM in AWGN
% M: Number of symbols (e.g., 16, 64, etc.)
% SNR_dB: SNR in dB
% Convert SNR from dB to linear scale
SNR_linear = 10.^(SNR_dB / 10);
% Compute theoretical SER
k = sqrt(M); % Number of points per side
if mod(k,1) ~= 0
error(‘M must be a perfect square’);
end
% Calculate SER using the Q-function
SER_theoretical = 4*(1-1./sqrt(M))*qfunc(sqrt(3./(M-1)*SNR_linear));
end
In the above code when I plot the SER v/s SNR and compare the simulation and analytical values don’t match. Can someone tell me what is the error in my code and how can I match the curves ?% Parameters
M = 4; % MQAM order (e.g., 16-QAM)
N = 1e5; % Number of transmit symbols
% Define SNR range
SNR_dB_range = 0:10;
num_SNR_points = length(SNR_dB_range);
% Initialize SER array
SER_values = zeros(num_SNR_points, 1);
% Create MQAM constellation
constellation = createMQAM(M);
% Loop over each SNR value
for idx = 1:num_SNR_points
SNR_dB = SNR_dB_range(idx);
% Generate transmit symbols
transmitSymbols = generateSymbols(constellation, N);
% Transmit through AWGN channel
receivedSymbols = transmitSymbolsThroughAWGN(transmitSymbols, SNR_dB);
% Demodulate symbols
decodedSymbols = demodulateSymbols(receivedSymbols, constellation);
% Compute Symbol Error Rate
SER = computeSER(transmitSymbols, decodedSymbols);
% Store SER value
SER_values(idx) = SER;
% Compute Theoretical SER
SER_theoretical = computeTheoreticalSER(M, SNR_dB_range);
SER_theoretical_values = SER_theoretical;
end
% Plot SER vs SNR
figure;
semilogy(SNR_dB_range, SER_values, ‘o-‘, ‘DisplayName’, ‘Simulated SER’);
hold on;
semilogy(SNR_dB_range, SER_theoretical_values, ‘r–‘, ‘DisplayName’, ‘Theoretical SER’);
xlabel(‘SNR (dB)’);
ylabel(‘Symbol Error Rate (SER)’);
title(‘SER vs. SNR for MQAM’);
legend;
grid on;
function constellation = createMQAM(M)
% Create an MQAM constellation manually
% M: Number of symbols (e.g., 16, 64, etc.)
% Check that M is a perfect square
k = sqrt(M);
if mod(k,1) ~= 0
error(‘M must be a perfect square’);
end
% Generate constellation points
k = round(k); % Number of points per side
[X, Y] = meshgrid(linspace(-k+1, k-1, k), linspace(-k+1, k-1, k));
constellation = X(:) + 1i*Y(:);
end
function symbols = generateSymbols(constellation, N)
% Generate N random transmit symbols
% constellation: The MQAM constellation points
% N: Number of symbols to generate
numPoints = length(constellation);
indices = randi([1 numPoints], [N, 1]); % Randomly choose indices
symbols = constellation(indices); % Select symbols from the constellation
end
function received = transmitSymbolsThroughAWGN(symbols, SNR_dB)
% Transmit symbols through a SISO AWGN channel
% symbols: Transmit symbols
% SNR_dB: Signal-to-noise ratio in dB
% Convert SNR from dB to linear scale
SNR_linear = 10^(SNR_dB / 10);
% Calculate noise variance
noise_variance = 1 / SNR_linear;
% Generate noise
noise = sqrt(noise_variance / 2) * (randn(size(symbols)) + 1i*randn(size(symbols)));
% Received symbols
received = symbols + noise;
end
function decodedSymbols = demodulateSymbols(received, constellation)
% Demodulate symbols using minimum distance decoding
% received: Received symbols
% constellation: MQAM constellation points
numSymbols = length(received);
numPoints = length(constellation);
% Initialize decoded symbols
decodedSymbols = zeros(size(received));
for i = 1:numSymbols
% Compute distances to all constellation points
distances = abs(received(i) – constellation).^2;
% Find the closest constellation point
[~, idx] = min(distances);
decodedSymbols(i) = constellation(idx);
end
end
function SER = computeSER(originalSymbols, decodedSymbols)
% Compute symbol error rate
% originalSymbols: Transmit symbols
% decodedSymbols: Received and decoded symbols
numErrors = sum(originalSymbols ~= decodedSymbols);
totalSymbols = length(originalSymbols);
SER = numErrors / totalSymbols;
end
function SER_theoretical = computeTheoreticalSER(M, SNR_dB)
% Compute the theoretical SER for MQAM in AWGN
% M: Number of symbols (e.g., 16, 64, etc.)
% SNR_dB: SNR in dB
% Convert SNR from dB to linear scale
SNR_linear = 10.^(SNR_dB / 10);
% Compute theoretical SER
k = sqrt(M); % Number of points per side
if mod(k,1) ~= 0
error(‘M must be a perfect square’);
end
% Calculate SER using the Q-function
SER_theoretical = 4*(1-1./sqrt(M))*qfunc(sqrt(3./(M-1)*SNR_linear));
end
In the above code when I plot the SER v/s SNR and compare the simulation and analytical values don’t match. Can someone tell me what is the error in my code and how can I match the curves ? % Parameters
M = 4; % MQAM order (e.g., 16-QAM)
N = 1e5; % Number of transmit symbols
% Define SNR range
SNR_dB_range = 0:10;
num_SNR_points = length(SNR_dB_range);
% Initialize SER array
SER_values = zeros(num_SNR_points, 1);
% Create MQAM constellation
constellation = createMQAM(M);
% Loop over each SNR value
for idx = 1:num_SNR_points
SNR_dB = SNR_dB_range(idx);
% Generate transmit symbols
transmitSymbols = generateSymbols(constellation, N);
% Transmit through AWGN channel
receivedSymbols = transmitSymbolsThroughAWGN(transmitSymbols, SNR_dB);
% Demodulate symbols
decodedSymbols = demodulateSymbols(receivedSymbols, constellation);
% Compute Symbol Error Rate
SER = computeSER(transmitSymbols, decodedSymbols);
% Store SER value
SER_values(idx) = SER;
% Compute Theoretical SER
SER_theoretical = computeTheoreticalSER(M, SNR_dB_range);
SER_theoretical_values = SER_theoretical;
end
% Plot SER vs SNR
figure;
semilogy(SNR_dB_range, SER_values, ‘o-‘, ‘DisplayName’, ‘Simulated SER’);
hold on;
semilogy(SNR_dB_range, SER_theoretical_values, ‘r–‘, ‘DisplayName’, ‘Theoretical SER’);
xlabel(‘SNR (dB)’);
ylabel(‘Symbol Error Rate (SER)’);
title(‘SER vs. SNR for MQAM’);
legend;
grid on;
function constellation = createMQAM(M)
% Create an MQAM constellation manually
% M: Number of symbols (e.g., 16, 64, etc.)
% Check that M is a perfect square
k = sqrt(M);
if mod(k,1) ~= 0
error(‘M must be a perfect square’);
end
% Generate constellation points
k = round(k); % Number of points per side
[X, Y] = meshgrid(linspace(-k+1, k-1, k), linspace(-k+1, k-1, k));
constellation = X(:) + 1i*Y(:);
end
function symbols = generateSymbols(constellation, N)
% Generate N random transmit symbols
% constellation: The MQAM constellation points
% N: Number of symbols to generate
numPoints = length(constellation);
indices = randi([1 numPoints], [N, 1]); % Randomly choose indices
symbols = constellation(indices); % Select symbols from the constellation
end
function received = transmitSymbolsThroughAWGN(symbols, SNR_dB)
% Transmit symbols through a SISO AWGN channel
% symbols: Transmit symbols
% SNR_dB: Signal-to-noise ratio in dB
% Convert SNR from dB to linear scale
SNR_linear = 10^(SNR_dB / 10);
% Calculate noise variance
noise_variance = 1 / SNR_linear;
% Generate noise
noise = sqrt(noise_variance / 2) * (randn(size(symbols)) + 1i*randn(size(symbols)));
% Received symbols
received = symbols + noise;
end
function decodedSymbols = demodulateSymbols(received, constellation)
% Demodulate symbols using minimum distance decoding
% received: Received symbols
% constellation: MQAM constellation points
numSymbols = length(received);
numPoints = length(constellation);
% Initialize decoded symbols
decodedSymbols = zeros(size(received));
for i = 1:numSymbols
% Compute distances to all constellation points
distances = abs(received(i) – constellation).^2;
% Find the closest constellation point
[~, idx] = min(distances);
decodedSymbols(i) = constellation(idx);
end
end
function SER = computeSER(originalSymbols, decodedSymbols)
% Compute symbol error rate
% originalSymbols: Transmit symbols
% decodedSymbols: Received and decoded symbols
numErrors = sum(originalSymbols ~= decodedSymbols);
totalSymbols = length(originalSymbols);
SER = numErrors / totalSymbols;
end
function SER_theoretical = computeTheoreticalSER(M, SNR_dB)
% Compute the theoretical SER for MQAM in AWGN
% M: Number of symbols (e.g., 16, 64, etc.)
% SNR_dB: SNR in dB
% Convert SNR from dB to linear scale
SNR_linear = 10.^(SNR_dB / 10);
% Compute theoretical SER
k = sqrt(M); % Number of points per side
if mod(k,1) ~= 0
error(‘M must be a perfect square’);
end
% Calculate SER using the Q-function
SER_theoretical = 4*(1-1./sqrt(M))*qfunc(sqrt(3./(M-1)*SNR_linear));
end
In the above code when I plot the SER v/s SNR and compare the simulation and analytical values don’t match. Can someone tell me what is the error in my code and how can I match the curves ? communication, plot MATLAB Answers — New Questions
Create a 3D matrix from 2 2D matrix
Hi all,
I want to create a 3D matrix from three 2D matrix with different size.
The first matrix has the size of 360×560 which contain the information of grid for x.
The second matrix has the same size (360×560) and has the grid details of z.
The third matrix has the size of 100×560 and it contain the detail of grid for y.
To simply, the size of x, y and z are 560, 360 and 100.
I would like to create a 3D matrix with a size of 100x360x560 with grid information for the x, y and z direction.
May I know how to achieve that? I have attached a test.mat file that include x, y and z.
Thanks for your help!Hi all,
I want to create a 3D matrix from three 2D matrix with different size.
The first matrix has the size of 360×560 which contain the information of grid for x.
The second matrix has the same size (360×560) and has the grid details of z.
The third matrix has the size of 100×560 and it contain the detail of grid for y.
To simply, the size of x, y and z are 560, 360 and 100.
I would like to create a 3D matrix with a size of 100x360x560 with grid information for the x, y and z direction.
May I know how to achieve that? I have attached a test.mat file that include x, y and z.
Thanks for your help! Hi all,
I want to create a 3D matrix from three 2D matrix with different size.
The first matrix has the size of 360×560 which contain the information of grid for x.
The second matrix has the same size (360×560) and has the grid details of z.
The third matrix has the size of 100×560 and it contain the detail of grid for y.
To simply, the size of x, y and z are 560, 360 and 100.
I would like to create a 3D matrix with a size of 100x360x560 with grid information for the x, y and z direction.
May I know how to achieve that? I have attached a test.mat file that include x, y and z.
Thanks for your help! combine matrix MATLAB Answers — New Questions
Transmission-Reception using USRPs(B210s) with 5G NR Waveform Synchronization failing
Hi Everyone,
I am trying to create a 5G environment with USRPs, one as transmitter (PC1 with MATLAB) and other as receiver (PC2 with MATLAB) and they are connect with wired antennas.
I am generating the 5G NR waveform at transmitter side and sending it to receiver over connected antennas.
The waveform signal is sent for 10 seconds and receiver also receiving it for same duration with 1 second provided for transmission delay (through USRP’s USBs and wires). However, the synchronization is failing and the waveform I received are not the same which leads to inability to extract the sent waveform properties like PDCCH and PDSCH, data, etc. The datatypes of sent and received waveform are also different (Complex-double at transmitter, Complex-int16 at receiver).
I used the below link for designing the waveform for transmission.
https://in.mathworks.com/help/5g/ug/5g-nr-waveform-capture-and-analysis-using-software-defined-radio.html
Although there is no details about the receiver side in the above link.
If someone faced the similar issues, kindly suggest some help
If there exist any tutorial for this kind of work Please share?
ThanksHi Everyone,
I am trying to create a 5G environment with USRPs, one as transmitter (PC1 with MATLAB) and other as receiver (PC2 with MATLAB) and they are connect with wired antennas.
I am generating the 5G NR waveform at transmitter side and sending it to receiver over connected antennas.
The waveform signal is sent for 10 seconds and receiver also receiving it for same duration with 1 second provided for transmission delay (through USRP’s USBs and wires). However, the synchronization is failing and the waveform I received are not the same which leads to inability to extract the sent waveform properties like PDCCH and PDSCH, data, etc. The datatypes of sent and received waveform are also different (Complex-double at transmitter, Complex-int16 at receiver).
I used the below link for designing the waveform for transmission.
https://in.mathworks.com/help/5g/ug/5g-nr-waveform-capture-and-analysis-using-software-defined-radio.html
Although there is no details about the receiver side in the above link.
If someone faced the similar issues, kindly suggest some help
If there exist any tutorial for this kind of work Please share?
Thanks Hi Everyone,
I am trying to create a 5G environment with USRPs, one as transmitter (PC1 with MATLAB) and other as receiver (PC2 with MATLAB) and they are connect with wired antennas.
I am generating the 5G NR waveform at transmitter side and sending it to receiver over connected antennas.
The waveform signal is sent for 10 seconds and receiver also receiving it for same duration with 1 second provided for transmission delay (through USRP’s USBs and wires). However, the synchronization is failing and the waveform I received are not the same which leads to inability to extract the sent waveform properties like PDCCH and PDSCH, data, etc. The datatypes of sent and received waveform are also different (Complex-double at transmitter, Complex-int16 at receiver).
I used the below link for designing the waveform for transmission.
https://in.mathworks.com/help/5g/ug/5g-nr-waveform-capture-and-analysis-using-software-defined-radio.html
Although there is no details about the receiver side in the above link.
If someone faced the similar issues, kindly suggest some help
If there exist any tutorial for this kind of work Please share?
Thanks 5g nr waveform synchronization using usrps (b210s) MATLAB Answers — New Questions
Not able to login form docker image for 1 month trail subscription?
Hi Support team.
I am trying to do MATLAB login from docker image, but my login is failing.
Note:- I am using 1 month free trial login credetials.
Docker file and error image I have given below.
Docker File:-
# Use MATLAB base image from MathWorks
FROM mathworks/matlab:r2023b
# Set the working directory inside the container
WORKDIR /usr/src/matlab
# Copy your MATLAB conversion script to the container
COPY convert_mf4_to_csv.m .
## Environment varibales for MathWorks credentials
ENV MW_USERNAME = "{User_email}"
ENV MW_PASSWORD = "{password}"
# Expose the port for communication (if needed)
EXPOSE 8080
# The default command will pass arguments for input and output paths
CMD ["matlab", "-batch", "convert_mf4_to_csv(‘/x_input_folder/input_file.mf4’, ‘/x_output_folder/output_file.csv’)"]
Error:-
MATLAB is selecting SOFTWARE OPENGL rendering.
Please enter your MathWorks Account email address and press Enter:
Sign-in failed. Would you like to retry? y/n [n]
Please check attached image.
Any support will be appreciable.
Thanks in Advance!!Hi Support team.
I am trying to do MATLAB login from docker image, but my login is failing.
Note:- I am using 1 month free trial login credetials.
Docker file and error image I have given below.
Docker File:-
# Use MATLAB base image from MathWorks
FROM mathworks/matlab:r2023b
# Set the working directory inside the container
WORKDIR /usr/src/matlab
# Copy your MATLAB conversion script to the container
COPY convert_mf4_to_csv.m .
## Environment varibales for MathWorks credentials
ENV MW_USERNAME = "{User_email}"
ENV MW_PASSWORD = "{password}"
# Expose the port for communication (if needed)
EXPOSE 8080
# The default command will pass arguments for input and output paths
CMD ["matlab", "-batch", "convert_mf4_to_csv(‘/x_input_folder/input_file.mf4’, ‘/x_output_folder/output_file.csv’)"]
Error:-
MATLAB is selecting SOFTWARE OPENGL rendering.
Please enter your MathWorks Account email address and press Enter:
Sign-in failed. Would you like to retry? y/n [n]
Please check attached image.
Any support will be appreciable.
Thanks in Advance!! Hi Support team.
I am trying to do MATLAB login from docker image, but my login is failing.
Note:- I am using 1 month free trial login credetials.
Docker file and error image I have given below.
Docker File:-
# Use MATLAB base image from MathWorks
FROM mathworks/matlab:r2023b
# Set the working directory inside the container
WORKDIR /usr/src/matlab
# Copy your MATLAB conversion script to the container
COPY convert_mf4_to_csv.m .
## Environment varibales for MathWorks credentials
ENV MW_USERNAME = "{User_email}"
ENV MW_PASSWORD = "{password}"
# Expose the port for communication (if needed)
EXPOSE 8080
# The default command will pass arguments for input and output paths
CMD ["matlab", "-batch", "convert_mf4_to_csv(‘/x_input_folder/input_file.mf4’, ‘/x_output_folder/output_file.csv’)"]
Error:-
MATLAB is selecting SOFTWARE OPENGL rendering.
Please enter your MathWorks Account email address and press Enter:
Sign-in failed. Would you like to retry? y/n [n]
Please check attached image.
Any support will be appreciable.
Thanks in Advance!! docker, sign in issue MATLAB Answers — New Questions
LSTM-CNN “The size of the convolution dimension of the padded input data must be larger than or equal to the filter size”
Hello everyone,
I am trying to implement LSTM-CNN for speech recognition, I have a matrix for train and test which already are converted it to cell, when I excuted the code I got the error below:
net = trainNetwork(AllCellTrain, YCA, layers, options);
Caused by:
Layer 3: The size of the convolution dimension of the padded input data must be larger than or equal to the filter
size. For networks with sequence input, this check depends on the MinLength property of the sequence input layer. To
ensure that this check is accurate, set MinLength to the shortest sequence length of your training data.
The code that I have used:
% Define LSTM-CNN model architecture
numHiddenUnits = 100; % Number of hidden units in the LSTM layer
numFilters = 100; % Number of filters in the CNN layer
%filterSize = [3, 3]; % Size of the filters in the CNN layer
filterSize=3;
num_features = 39;
layers = [
sequenceInputLayer(num_features)
lstmLayer(numHiddenUnits,’OutputMode’,’sequence’)
convolution1dLayer(filterSize, numFilters)
maxPooling2dLayer(2, ‘Stride’, 2)
fullyConnectedLayer(num_classes)
softmaxLayer
classificationLayer
];
% Specify the training options
max_epochs = 26;
mini_batch_size = 128;
initial_learning_rate = 0.001;
options = trainingOptions(‘adam’, …
‘MaxEpochs’, max_epochs, …
‘MiniBatchSize’, mini_batch_size, …
‘InitialLearnRate’, initial_learning_rate, …
‘GradientThreshold’, 1, …
‘Shuffle’, ‘every-epoch’, …
‘Verbose’, 1, …
‘ExecutionEnvironment’,’auto’, …
‘Plots’, ‘training-progress’);
% Train the LSTM-CNN model
YCA = categorical(CA);
net = trainNetwork(AllCellTrain, YCA, layers, options);
Thanks in advance!Hello everyone,
I am trying to implement LSTM-CNN for speech recognition, I have a matrix for train and test which already are converted it to cell, when I excuted the code I got the error below:
net = trainNetwork(AllCellTrain, YCA, layers, options);
Caused by:
Layer 3: The size of the convolution dimension of the padded input data must be larger than or equal to the filter
size. For networks with sequence input, this check depends on the MinLength property of the sequence input layer. To
ensure that this check is accurate, set MinLength to the shortest sequence length of your training data.
The code that I have used:
% Define LSTM-CNN model architecture
numHiddenUnits = 100; % Number of hidden units in the LSTM layer
numFilters = 100; % Number of filters in the CNN layer
%filterSize = [3, 3]; % Size of the filters in the CNN layer
filterSize=3;
num_features = 39;
layers = [
sequenceInputLayer(num_features)
lstmLayer(numHiddenUnits,’OutputMode’,’sequence’)
convolution1dLayer(filterSize, numFilters)
maxPooling2dLayer(2, ‘Stride’, 2)
fullyConnectedLayer(num_classes)
softmaxLayer
classificationLayer
];
% Specify the training options
max_epochs = 26;
mini_batch_size = 128;
initial_learning_rate = 0.001;
options = trainingOptions(‘adam’, …
‘MaxEpochs’, max_epochs, …
‘MiniBatchSize’, mini_batch_size, …
‘InitialLearnRate’, initial_learning_rate, …
‘GradientThreshold’, 1, …
‘Shuffle’, ‘every-epoch’, …
‘Verbose’, 1, …
‘ExecutionEnvironment’,’auto’, …
‘Plots’, ‘training-progress’);
% Train the LSTM-CNN model
YCA = categorical(CA);
net = trainNetwork(AllCellTrain, YCA, layers, options);
Thanks in advance! Hello everyone,
I am trying to implement LSTM-CNN for speech recognition, I have a matrix for train and test which already are converted it to cell, when I excuted the code I got the error below:
net = trainNetwork(AllCellTrain, YCA, layers, options);
Caused by:
Layer 3: The size of the convolution dimension of the padded input data must be larger than or equal to the filter
size. For networks with sequence input, this check depends on the MinLength property of the sequence input layer. To
ensure that this check is accurate, set MinLength to the shortest sequence length of your training data.
The code that I have used:
% Define LSTM-CNN model architecture
numHiddenUnits = 100; % Number of hidden units in the LSTM layer
numFilters = 100; % Number of filters in the CNN layer
%filterSize = [3, 3]; % Size of the filters in the CNN layer
filterSize=3;
num_features = 39;
layers = [
sequenceInputLayer(num_features)
lstmLayer(numHiddenUnits,’OutputMode’,’sequence’)
convolution1dLayer(filterSize, numFilters)
maxPooling2dLayer(2, ‘Stride’, 2)
fullyConnectedLayer(num_classes)
softmaxLayer
classificationLayer
];
% Specify the training options
max_epochs = 26;
mini_batch_size = 128;
initial_learning_rate = 0.001;
options = trainingOptions(‘adam’, …
‘MaxEpochs’, max_epochs, …
‘MiniBatchSize’, mini_batch_size, …
‘InitialLearnRate’, initial_learning_rate, …
‘GradientThreshold’, 1, …
‘Shuffle’, ‘every-epoch’, …
‘Verbose’, 1, …
‘ExecutionEnvironment’,’auto’, …
‘Plots’, ‘training-progress’);
% Train the LSTM-CNN model
YCA = categorical(CA);
net = trainNetwork(AllCellTrain, YCA, layers, options);
Thanks in advance! cnn, audio, lstm, deep learning, machine learning, classification MATLAB Answers — New Questions
How to disable two/three-finger zoom (pinch) in app on touchscreen?
I have an app developed with AppDesigner that you can see below on the left. It is being run on a touchscreen. Using two or three fingers (also called a "pinch") on the touchscreen, it is possible to zoom in on the app window contents. The picture on the right shows what is happening (and apologies for the glare). This was reproduced across two OSs and two different touchscreens, which suggests it is something inherent to MATLAB. This only appears to be possible with a touchscreen, since I was unable to zoom like this using combinations of mouse and/or keyboard.
Would anyone know how to disable this zoom?I have an app developed with AppDesigner that you can see below on the left. It is being run on a touchscreen. Using two or three fingers (also called a "pinch") on the touchscreen, it is possible to zoom in on the app window contents. The picture on the right shows what is happening (and apologies for the glare). This was reproduced across two OSs and two different touchscreens, which suggests it is something inherent to MATLAB. This only appears to be possible with a touchscreen, since I was unable to zoom like this using combinations of mouse and/or keyboard.
Would anyone know how to disable this zoom? I have an app developed with AppDesigner that you can see below on the left. It is being run on a touchscreen. Using two or three fingers (also called a "pinch") on the touchscreen, it is possible to zoom in on the app window contents. The picture on the right shows what is happening (and apologies for the glare). This was reproduced across two OSs and two different touchscreens, which suggests it is something inherent to MATLAB. This only appears to be possible with a touchscreen, since I was unable to zoom like this using combinations of mouse and/or keyboard.
Would anyone know how to disable this zoom? app, gui, ui, touchscreen, multitouch, gesture, pinch, zoom MATLAB Answers — New Questions
Error in Modeling and Simulation of an Autonomous Underwater Vehicle matlab exemple
I was trying to familiarize myself with this example made by matlab, but I can’t test it because of this error. I haven’t changed anything. Why is this mismatch happening? It only occurs when switching to high fidelity simulation in the asbAUV.slx.I was trying to familiarize myself with this example made by matlab, but I can’t test it because of this error. I haven’t changed anything. Why is this mismatch happening? It only occurs when switching to high fidelity simulation in the asbAUV.slx. I was trying to familiarize myself with this example made by matlab, but I can’t test it because of this error. I haven’t changed anything. Why is this mismatch happening? It only occurs when switching to high fidelity simulation in the asbAUV.slx. exemple MATLAB Answers — New Questions
Assistance Needed: Simulating Power-Exponent-Phase Vortex Beam (PEPVB) Propagation in Oceanic Turbulence
I am attempting to simulate the propagation characteristics of the Power-Exponent-Phase Vortex Beam (PEPVB) in oceanic turbulence based on the theoretical model provided in the paper Propagation properties of rotationally-symmetric power-exponent-phase vortex beam through oceanic turbulence. The model uses the extended Huygens-Fresnel diffraction integral and oceanic turbulence theory, and I’m trying to implement this in MATLAB.
I have followed the mathematical formulas provided in section 2 of the paper, particularly equations (1) to (8), which define the electric field and cross-spectral density for the PEPVB passing through turbulence. However, despite various attempts, I haven’t been able to get the simulation to work as expected.
The first image shows the results I generated using my own code, while the second image shows the results provided by the authors of the PEPVB study. The differences between these results are confusing me, especially regarding the implementation of the electric field formulas and how to handle the oceanic turbulence parameters, such as the rate of dissipation of turbulence kinetic energy (ε), the temperature-salinity contribution ratio (ω), and the dissipation rate of the mean-squared temperature (χT).
Could anyone with experience in PEPVB or similar simulations in MATLAB help me check my code or provide working examples? Any help would be greatly appreciated!
Thank you for your time and assistanceI am attempting to simulate the propagation characteristics of the Power-Exponent-Phase Vortex Beam (PEPVB) in oceanic turbulence based on the theoretical model provided in the paper Propagation properties of rotationally-symmetric power-exponent-phase vortex beam through oceanic turbulence. The model uses the extended Huygens-Fresnel diffraction integral and oceanic turbulence theory, and I’m trying to implement this in MATLAB.
I have followed the mathematical formulas provided in section 2 of the paper, particularly equations (1) to (8), which define the electric field and cross-spectral density for the PEPVB passing through turbulence. However, despite various attempts, I haven’t been able to get the simulation to work as expected.
The first image shows the results I generated using my own code, while the second image shows the results provided by the authors of the PEPVB study. The differences between these results are confusing me, especially regarding the implementation of the electric field formulas and how to handle the oceanic turbulence parameters, such as the rate of dissipation of turbulence kinetic energy (ε), the temperature-salinity contribution ratio (ω), and the dissipation rate of the mean-squared temperature (χT).
Could anyone with experience in PEPVB or similar simulations in MATLAB help me check my code or provide working examples? Any help would be greatly appreciated!
Thank you for your time and assistance I am attempting to simulate the propagation characteristics of the Power-Exponent-Phase Vortex Beam (PEPVB) in oceanic turbulence based on the theoretical model provided in the paper Propagation properties of rotationally-symmetric power-exponent-phase vortex beam through oceanic turbulence. The model uses the extended Huygens-Fresnel diffraction integral and oceanic turbulence theory, and I’m trying to implement this in MATLAB.
I have followed the mathematical formulas provided in section 2 of the paper, particularly equations (1) to (8), which define the electric field and cross-spectral density for the PEPVB passing through turbulence. However, despite various attempts, I haven’t been able to get the simulation to work as expected.
The first image shows the results I generated using my own code, while the second image shows the results provided by the authors of the PEPVB study. The differences between these results are confusing me, especially regarding the implementation of the electric field formulas and how to handle the oceanic turbulence parameters, such as the rate of dissipation of turbulence kinetic energy (ε), the temperature-salinity contribution ratio (ω), and the dissipation rate of the mean-squared temperature (χT).
Could anyone with experience in PEPVB or similar simulations in MATLAB help me check my code or provide working examples? Any help would be greatly appreciated!
Thank you for your time and assistance optical communication, laser beams, angular momentum MATLAB Answers — New Questions
How to convert csv to Heatmap?
Hello, I am relatively new to using MATLAB so I am coming across some issues. I want to convert a .csv file with A LOT of raw data and visualize it as a heatmap. It is a 36189×88 data table. This code I have so far shows something but it is not really giving me what I want. Any help or advice would be greatly appreciated.
clc;
clear
close all;
data = readtable("N303_M.2.csv");
%% Data Filtering/Processing
clc, clearvars -except data, format compact, close all
%convert from Table to Array
strain(:, 1:88) = table2array(data(:,1:88));
%% Data Visualizations
figure(1);
plot(strain(:, 1:88));
heatmap(strain(:, 1:88),’Colormap’, jet,)
title(‘Visual Data for Mat’)Hello, I am relatively new to using MATLAB so I am coming across some issues. I want to convert a .csv file with A LOT of raw data and visualize it as a heatmap. It is a 36189×88 data table. This code I have so far shows something but it is not really giving me what I want. Any help or advice would be greatly appreciated.
clc;
clear
close all;
data = readtable("N303_M.2.csv");
%% Data Filtering/Processing
clc, clearvars -except data, format compact, close all
%convert from Table to Array
strain(:, 1:88) = table2array(data(:,1:88));
%% Data Visualizations
figure(1);
plot(strain(:, 1:88));
heatmap(strain(:, 1:88),’Colormap’, jet,)
title(‘Visual Data for Mat’) Hello, I am relatively new to using MATLAB so I am coming across some issues. I want to convert a .csv file with A LOT of raw data and visualize it as a heatmap. It is a 36189×88 data table. This code I have so far shows something but it is not really giving me what I want. Any help or advice would be greatly appreciated.
clc;
clear
close all;
data = readtable("N303_M.2.csv");
%% Data Filtering/Processing
clc, clearvars -except data, format compact, close all
%convert from Table to Array
strain(:, 1:88) = table2array(data(:,1:88));
%% Data Visualizations
figure(1);
plot(strain(:, 1:88));
heatmap(strain(:, 1:88),’Colormap’, jet,)
title(‘Visual Data for Mat’) heatmap, csv, raw data, matlab MATLAB Answers — New Questions
How to callback same function for changes in multiple uiobjects?
I am creating a uifigure-based app programatically for de-noising the noisy images. The code for which is as follows:
function filteredImage
fig = uifigure;
g = uigridlayout(fig,[3 2]);
g.RowHeight = {30,30,’1x’};
g.ColumnSpacing = 10;
filterLabel = uilabel(g,"Text","Filter Type","WordWrap","on","FontSize",18,"FontWeight","bold");
filterLabel.Layout.Row = 1;
filterLabel.Layout.Column = 1;
% Choose type of filter to be displayed
filterType = uidropdown(g,"Editable","on","Position",[0 50 20 10],"FontSize",18);
filterType.Layout.Row = 1;
filterType.Layout.Column = 2;
filterType.Items = ["Arithmetic Mean Filter",
"Geometric Mean Filter",
"Weighted Average Filter"];
kernelDimlabel = uilabel("Parent",g,"Text","Kernel Dimensions","FontSize",18,"FontWeight","bold");
kernelDimlabel.Layout.Row = 2;
kernelDimlabel.Layout.Column = 1;
% Set the kernel size (since it is a square matrix, #rows = #columns)
kernelDim = uispinner("Parent",g,"Step",2,"Value",3,"Limits",[3 11],"FontSize",18);
kernelDim.Layout.Row = 2;
kernelDim.Layout.Column = 2;
% Noisy image displayed
im1 = uiimage(g,"ImageSource","poutsalt & pepper.png");
im1.Layout.Row = 3;
im1.Layout.Column = 1;
% Filtered image displayed
im2 = uiimage(g);
im2.Layout.Row = 3;
im2.Layout.Column = 2;
% Here, filterImage updates im2 whenever the value of filterType changes
filterType.ValueChangedFcn = @(src,event)filterImage(src,event,im1,im2,filterType,kernelDim);
% I want to update im2 when either the value of filterType changes OR when
% kernelDim changes
end
function filterImage(src,event,im1,im2,filterType,kernelDim)
kDim = kernelDim.Value;
I = imread(im1.ImageSource);
I_name = erase(im1.ImageSource,".png");
incr = floor(kDim/2);
im1_padded = double(padarray(I,[incr incr],0,’both’));
[r,c] = size(I);
switch filterType.Value
case "Arithmetic Mean Filter"
kernel = double(ones(kDim));
for i=1:r
for j=1:c
I_filtered(i+incr,j+incr) = (1/(kDim*kDim))*sum(sum(kernel.*im1_padded(i:i+kDim-1,j:j+kDim-1)));
end
end
ext = "_amf"+"_"+ string(kDim) + ".png";
case "Geometric Mean Filter"
kernel = double(ones(kDim));
for i=1:r
for j=1:c
I_filtered(i+incr,j+incr) = prod(prod(kernel.*im1_padded(i:i+kDim-1,j:j+kDim-1))).^(1/(kDim*kDim));
end
end
ext = "_gmf"+"_"+ string(kDim) + ".png";
case "Weighted Average Filter"
if kDim == 3
kernel = (1/16)*[1 2 1;
2 4 2;
1 2 1];
else
kernel = (1/52)*[1 1 2 1 1;
1 2 4 2 1;
2 4 8 4 2;
1 2 4 2 1;
1 1 2 1 1];
end
for i=1:r
for j=1:c
I_filtered(i+incr,j+incr) = sum(sum(kernel.*im1_padded(i:i+kDim-1,j:j+kDim-1)));
end
end
ext = "_waf"+"_"+ string(kDim) + ".png";
end
I_filtered = uint8(I_filtered);
filteredImagePath = strcat(I_name,ext);
imwrite(I_filtered,filteredImagePath);
im2.ImageSource = filteredImagePath;
end
As of now I am getting the filtered image output. Initially there’s no image in im2. But it appears only after I change the kernelDim followed by filterType. One obvious way is to explicitly write the code for initial values, but I want the function filterImage to somehow do it.
Please suggest techniques to do the same in an efficient manner.I am creating a uifigure-based app programatically for de-noising the noisy images. The code for which is as follows:
function filteredImage
fig = uifigure;
g = uigridlayout(fig,[3 2]);
g.RowHeight = {30,30,’1x’};
g.ColumnSpacing = 10;
filterLabel = uilabel(g,"Text","Filter Type","WordWrap","on","FontSize",18,"FontWeight","bold");
filterLabel.Layout.Row = 1;
filterLabel.Layout.Column = 1;
% Choose type of filter to be displayed
filterType = uidropdown(g,"Editable","on","Position",[0 50 20 10],"FontSize",18);
filterType.Layout.Row = 1;
filterType.Layout.Column = 2;
filterType.Items = ["Arithmetic Mean Filter",
"Geometric Mean Filter",
"Weighted Average Filter"];
kernelDimlabel = uilabel("Parent",g,"Text","Kernel Dimensions","FontSize",18,"FontWeight","bold");
kernelDimlabel.Layout.Row = 2;
kernelDimlabel.Layout.Column = 1;
% Set the kernel size (since it is a square matrix, #rows = #columns)
kernelDim = uispinner("Parent",g,"Step",2,"Value",3,"Limits",[3 11],"FontSize",18);
kernelDim.Layout.Row = 2;
kernelDim.Layout.Column = 2;
% Noisy image displayed
im1 = uiimage(g,"ImageSource","poutsalt & pepper.png");
im1.Layout.Row = 3;
im1.Layout.Column = 1;
% Filtered image displayed
im2 = uiimage(g);
im2.Layout.Row = 3;
im2.Layout.Column = 2;
% Here, filterImage updates im2 whenever the value of filterType changes
filterType.ValueChangedFcn = @(src,event)filterImage(src,event,im1,im2,filterType,kernelDim);
% I want to update im2 when either the value of filterType changes OR when
% kernelDim changes
end
function filterImage(src,event,im1,im2,filterType,kernelDim)
kDim = kernelDim.Value;
I = imread(im1.ImageSource);
I_name = erase(im1.ImageSource,".png");
incr = floor(kDim/2);
im1_padded = double(padarray(I,[incr incr],0,’both’));
[r,c] = size(I);
switch filterType.Value
case "Arithmetic Mean Filter"
kernel = double(ones(kDim));
for i=1:r
for j=1:c
I_filtered(i+incr,j+incr) = (1/(kDim*kDim))*sum(sum(kernel.*im1_padded(i:i+kDim-1,j:j+kDim-1)));
end
end
ext = "_amf"+"_"+ string(kDim) + ".png";
case "Geometric Mean Filter"
kernel = double(ones(kDim));
for i=1:r
for j=1:c
I_filtered(i+incr,j+incr) = prod(prod(kernel.*im1_padded(i:i+kDim-1,j:j+kDim-1))).^(1/(kDim*kDim));
end
end
ext = "_gmf"+"_"+ string(kDim) + ".png";
case "Weighted Average Filter"
if kDim == 3
kernel = (1/16)*[1 2 1;
2 4 2;
1 2 1];
else
kernel = (1/52)*[1 1 2 1 1;
1 2 4 2 1;
2 4 8 4 2;
1 2 4 2 1;
1 1 2 1 1];
end
for i=1:r
for j=1:c
I_filtered(i+incr,j+incr) = sum(sum(kernel.*im1_padded(i:i+kDim-1,j:j+kDim-1)));
end
end
ext = "_waf"+"_"+ string(kDim) + ".png";
end
I_filtered = uint8(I_filtered);
filteredImagePath = strcat(I_name,ext);
imwrite(I_filtered,filteredImagePath);
im2.ImageSource = filteredImagePath;
end
As of now I am getting the filtered image output. Initially there’s no image in im2. But it appears only after I change the kernelDim followed by filterType. One obvious way is to explicitly write the code for initial values, but I want the function filterImage to somehow do it.
Please suggest techniques to do the same in an efficient manner. I am creating a uifigure-based app programatically for de-noising the noisy images. The code for which is as follows:
function filteredImage
fig = uifigure;
g = uigridlayout(fig,[3 2]);
g.RowHeight = {30,30,’1x’};
g.ColumnSpacing = 10;
filterLabel = uilabel(g,"Text","Filter Type","WordWrap","on","FontSize",18,"FontWeight","bold");
filterLabel.Layout.Row = 1;
filterLabel.Layout.Column = 1;
% Choose type of filter to be displayed
filterType = uidropdown(g,"Editable","on","Position",[0 50 20 10],"FontSize",18);
filterType.Layout.Row = 1;
filterType.Layout.Column = 2;
filterType.Items = ["Arithmetic Mean Filter",
"Geometric Mean Filter",
"Weighted Average Filter"];
kernelDimlabel = uilabel("Parent",g,"Text","Kernel Dimensions","FontSize",18,"FontWeight","bold");
kernelDimlabel.Layout.Row = 2;
kernelDimlabel.Layout.Column = 1;
% Set the kernel size (since it is a square matrix, #rows = #columns)
kernelDim = uispinner("Parent",g,"Step",2,"Value",3,"Limits",[3 11],"FontSize",18);
kernelDim.Layout.Row = 2;
kernelDim.Layout.Column = 2;
% Noisy image displayed
im1 = uiimage(g,"ImageSource","poutsalt & pepper.png");
im1.Layout.Row = 3;
im1.Layout.Column = 1;
% Filtered image displayed
im2 = uiimage(g);
im2.Layout.Row = 3;
im2.Layout.Column = 2;
% Here, filterImage updates im2 whenever the value of filterType changes
filterType.ValueChangedFcn = @(src,event)filterImage(src,event,im1,im2,filterType,kernelDim);
% I want to update im2 when either the value of filterType changes OR when
% kernelDim changes
end
function filterImage(src,event,im1,im2,filterType,kernelDim)
kDim = kernelDim.Value;
I = imread(im1.ImageSource);
I_name = erase(im1.ImageSource,".png");
incr = floor(kDim/2);
im1_padded = double(padarray(I,[incr incr],0,’both’));
[r,c] = size(I);
switch filterType.Value
case "Arithmetic Mean Filter"
kernel = double(ones(kDim));
for i=1:r
for j=1:c
I_filtered(i+incr,j+incr) = (1/(kDim*kDim))*sum(sum(kernel.*im1_padded(i:i+kDim-1,j:j+kDim-1)));
end
end
ext = "_amf"+"_"+ string(kDim) + ".png";
case "Geometric Mean Filter"
kernel = double(ones(kDim));
for i=1:r
for j=1:c
I_filtered(i+incr,j+incr) = prod(prod(kernel.*im1_padded(i:i+kDim-1,j:j+kDim-1))).^(1/(kDim*kDim));
end
end
ext = "_gmf"+"_"+ string(kDim) + ".png";
case "Weighted Average Filter"
if kDim == 3
kernel = (1/16)*[1 2 1;
2 4 2;
1 2 1];
else
kernel = (1/52)*[1 1 2 1 1;
1 2 4 2 1;
2 4 8 4 2;
1 2 4 2 1;
1 1 2 1 1];
end
for i=1:r
for j=1:c
I_filtered(i+incr,j+incr) = sum(sum(kernel.*im1_padded(i:i+kDim-1,j:j+kDim-1)));
end
end
ext = "_waf"+"_"+ string(kDim) + ".png";
end
I_filtered = uint8(I_filtered);
filteredImagePath = strcat(I_name,ext);
imwrite(I_filtered,filteredImagePath);
im2.ImageSource = filteredImagePath;
end
As of now I am getting the filtered image output. Initially there’s no image in im2. But it appears only after I change the kernelDim followed by filterType. One obvious way is to explicitly write the code for initial values, but I want the function filterImage to somehow do it.
Please suggest techniques to do the same in an efficient manner. image-processing, uifigure MATLAB Answers — New Questions
Embedded Coder for STM32F446RE about CAN communication
Hello Matlab Support Team,
I am currently using Simulink to implement CAN communication with an STM32-NucleoF446RE board, but I am facing some difficulties and would like to request support.
At the moment, I have connected an MCU-230 transceiver to a 500 kbit/s CAN bus, with the RX-TX lines of the transceiver connected to the STM32 board. I have also ensured that the baud rate is set correctly, but the problem of not receiving any values through CAN Receive persists.
Attached are some images showing parts of the code I have written and screenshots from STM32 IDE.
If there is any information you need, feel free to ask, and I will provide it. Also, if I have made any mistakes, please don’t hesitate to contact me.Hello Matlab Support Team,
I am currently using Simulink to implement CAN communication with an STM32-NucleoF446RE board, but I am facing some difficulties and would like to request support.
At the moment, I have connected an MCU-230 transceiver to a 500 kbit/s CAN bus, with the RX-TX lines of the transceiver connected to the STM32 board. I have also ensured that the baud rate is set correctly, but the problem of not receiving any values through CAN Receive persists.
Attached are some images showing parts of the code I have written and screenshots from STM32 IDE.
If there is any information you need, feel free to ask, and I will provide it. Also, if I have made any mistakes, please don’t hesitate to contact me. Hello Matlab Support Team,
I am currently using Simulink to implement CAN communication with an STM32-NucleoF446RE board, but I am facing some difficulties and would like to request support.
At the moment, I have connected an MCU-230 transceiver to a 500 kbit/s CAN bus, with the RX-TX lines of the transceiver connected to the STM32 board. I have also ensured that the baud rate is set correctly, but the problem of not receiving any values through CAN Receive persists.
Attached are some images showing parts of the code I have written and screenshots from STM32 IDE.
If there is any information you need, feel free to ask, and I will provide it. Also, if I have made any mistakes, please don’t hesitate to contact me. can, stm32f4xx, embedded coder, simulink MATLAB Answers — New Questions
can some one tell me how to do the aspen plus excel matlab link ??
I need to use a user model subroutine in Aspen plus linked to Matlab and excel can some one tell me the procedure step by step please….I need to use a user model subroutine in Aspen plus linked to Matlab and excel can some one tell me the procedure step by step please…. I need to use a user model subroutine in Aspen plus linked to Matlab and excel can some one tell me the procedure step by step please…. aspen plus- excel- matlab link MATLAB Answers — New Questions
Simulink Desktop Real-Time issue under Matlab R2024a
I am trying to run SLDRT models with Matlab/Simulink R2024a.
The models were functionnal under Matlab R2023a
In Matlab/Simulink R2024a, the analog inputs of my NI-PCI 6321 card update at a very slow pace and the analog outputs never update.
To ensure that this is not a Windows 11 issue, I reverted back to Matlab/Simulink R2023a and the old models still worked fine.
Is there a real issue or am I missing something?I am trying to run SLDRT models with Matlab/Simulink R2024a.
The models were functionnal under Matlab R2023a
In Matlab/Simulink R2024a, the analog inputs of my NI-PCI 6321 card update at a very slow pace and the analog outputs never update.
To ensure that this is not a Windows 11 issue, I reverted back to Matlab/Simulink R2023a and the old models still worked fine.
Is there a real issue or am I missing something? I am trying to run SLDRT models with Matlab/Simulink R2024a.
The models were functionnal under Matlab R2023a
In Matlab/Simulink R2024a, the analog inputs of my NI-PCI 6321 card update at a very slow pace and the analog outputs never update.
To ensure that this is not a Windows 11 issue, I reverted back to Matlab/Simulink R2023a and the old models still worked fine.
Is there a real issue or am I missing something? simulink desktop real-time, matlab r2024a MATLAB Answers — New Questions
Simulating Levy walk in MATLAB. (Not Levy Flight)
I am trying to simulate Levy Walk in 2D (Not Levy Flight). I do get the MSD and VCAF correctly, but I don’t get the step length distribution correctly ( Levy Walk step lengths have heavy tails). I don’t know my simulation is entirely correct. Can someone confirm my code ?
alpha=1.4;
x(1)=0;
y(1)=0;
n = 100; %
dt =0.1; % time step
v=1; % velocity
for i=1:n
t= round(abs((rand()).^(-1/alpha))./dt); % time before the change in direction taken from a simple stable distribution
theta = 2*pi*rand;
time(i)=t;
for j=1:t
x(end+1) = x(end) + v*dt*cos(theta);
y(end+1) = y(end) + v*dt*sin(theta);
end
end
figure(1);
plot(x, y, ‘-‘);
%% Distribution of step size
dx = diff(x);
dy = diff(y);
vxy=([dx, dy]);
bins = linspace(min(vxy), max(vxy), 75);
[count, edge]= histcounts(vxy, bins, ‘Normalization’, ‘PDF’);
pd= fitdist(transpose(vxy),’Normal’);
countfit=pdf(pd, edge(1:end-1));
figure(3)
semilogy(edge(1:end-1), count, ‘o’, ‘LineWidth’,2.0); hold on;
semilogy(edge(1:end-1),countfit,’-r’,’LineWidth’,2.0); hold off;I am trying to simulate Levy Walk in 2D (Not Levy Flight). I do get the MSD and VCAF correctly, but I don’t get the step length distribution correctly ( Levy Walk step lengths have heavy tails). I don’t know my simulation is entirely correct. Can someone confirm my code ?
alpha=1.4;
x(1)=0;
y(1)=0;
n = 100; %
dt =0.1; % time step
v=1; % velocity
for i=1:n
t= round(abs((rand()).^(-1/alpha))./dt); % time before the change in direction taken from a simple stable distribution
theta = 2*pi*rand;
time(i)=t;
for j=1:t
x(end+1) = x(end) + v*dt*cos(theta);
y(end+1) = y(end) + v*dt*sin(theta);
end
end
figure(1);
plot(x, y, ‘-‘);
%% Distribution of step size
dx = diff(x);
dy = diff(y);
vxy=([dx, dy]);
bins = linspace(min(vxy), max(vxy), 75);
[count, edge]= histcounts(vxy, bins, ‘Normalization’, ‘PDF’);
pd= fitdist(transpose(vxy),’Normal’);
countfit=pdf(pd, edge(1:end-1));
figure(3)
semilogy(edge(1:end-1), count, ‘o’, ‘LineWidth’,2.0); hold on;
semilogy(edge(1:end-1),countfit,’-r’,’LineWidth’,2.0); hold off; I am trying to simulate Levy Walk in 2D (Not Levy Flight). I do get the MSD and VCAF correctly, but I don’t get the step length distribution correctly ( Levy Walk step lengths have heavy tails). I don’t know my simulation is entirely correct. Can someone confirm my code ?
alpha=1.4;
x(1)=0;
y(1)=0;
n = 100; %
dt =0.1; % time step
v=1; % velocity
for i=1:n
t= round(abs((rand()).^(-1/alpha))./dt); % time before the change in direction taken from a simple stable distribution
theta = 2*pi*rand;
time(i)=t;
for j=1:t
x(end+1) = x(end) + v*dt*cos(theta);
y(end+1) = y(end) + v*dt*sin(theta);
end
end
figure(1);
plot(x, y, ‘-‘);
%% Distribution of step size
dx = diff(x);
dy = diff(y);
vxy=([dx, dy]);
bins = linspace(min(vxy), max(vxy), 75);
[count, edge]= histcounts(vxy, bins, ‘Normalization’, ‘PDF’);
pd= fitdist(transpose(vxy),’Normal’);
countfit=pdf(pd, edge(1:end-1));
figure(3)
semilogy(edge(1:end-1), count, ‘o’, ‘LineWidth’,2.0); hold on;
semilogy(edge(1:end-1),countfit,’-r’,’LineWidth’,2.0); hold off; randomwalk, biology, levywalk, physics MATLAB Answers — New Questions
resolution of MDOF using ode45
i have a problem solving the system with ode45. the code works but the displacement in graphed output is not what i would expect from a chirp signal. What could be the error in my code?
%MATRIX
M=diag([m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19]);
% stiffness matrix 19×19
K = zeros(19,19);
K(1,1) = k1 + k4 + k7 + k8;
K(1,2) = -k1;
K(1,5) = -k4;
K(1,7) = -k7;
K(1,8) = -k8;
K(2,1) = -k1;
K(2,2) = k1 + k2;
K(2,3) = -k2;
K(3,2) = -k2;
K(3,3) = k2 + k3;
K(3,4) = -k3;
K(4,3) = -k3;
K(4,4) = k3;
K(5,1) = -k4;
K(5,5) = k4 + k5 + k6;
K(5,6) = -k5;
K(5,7) = -k6;
K(6,5) = -k5;
K(6,6) = k5 + k11;
K(6,11) = -k11;
K(7,1) = -k7;
K(7,5) = -k6;
K(7,7) = k6 + k7 + k23;
K(7,18) = -k23;
K(8,1) = -k8;
K(8,8) = k8 + k9;
K(8,9) = -k9;
K(9,8) = -k9;
K(9,9) = k9 + k10;
K(9,10) = -k10;
K(10,9) = -k10;
K(10,10) = k10;
K(11,6) = -k11;
K(11,7) = -k12;
K(11,11) = k11 + k12 + k13 + k14;
K(11,12) = -k13;
K(11,13) = -k14;
K(12,11) = -k13;
K(12,12) = k13 + k15;
K(12,14) = -k15;
K(13,11) = -k14;
K(13,13) = k14 + k16;
K(13,15) = -k16;
K(14,12) = -k15;
K(14,14) = k15 + k17;
K(14,16) = -k17;
K(15,13) = -k16;
K(15,15) = k16 + k18;
K(15,17) = -k18;
K(16,14) = -k17;
K(16,16) = k17 + k19;
K(17,15) = -k18;
K(17,17) = k18 + k20;
K(18,7) = -k23;
K(18,18) = k23 + k21 + k22;
K(18,19) = -k21 – k22;
K(19,18) = -k21 – k22;
K(19,19) = k21 + k22;
% damping matrix 19×19
C = zeros(19,19);
C(1,1) = c1 + c4 + c7 + c8;
C(1,2) = -c1;
C(1,5) = -c4;
C(1,7) = -c7;
C(1,8) = -c8;
C(2,1) = -c1;
C(2,2) = c1 + c2;
C(2,3) = -c2;
C(3,2) = -c2;
C(3,3) = c2 + c3;
C(3,4) = -c3;
C(4,3) = -c3;
C(4,4) = c3;
C(5,1) = -c4;
C(5,5) = c4 + c5 + c6;
C(5,6) = -c5;
C(5,7) = -c6;
C(6,5) = -c5;
C(6,6) = c5 + c11;
C(6,11) = -c11;
C(7,1) = -c7;
C(7,5) = -c6;
C(7,7) = c6 + c7 + c23;
C(7,18) = -c23;
C(8,1) = -c8;
C(8,8) = c8 + c9;
C(8,9) = -c9;
C(9,8) = -c9;
C(9,9) = c9 + c10;
C(9,10) = -c10;
C(10,9) = -c10;
C(10,10) = c10;
C(11,6) = -c11;
C(11,7) = -c12;
C(11,11) = c11 + c12 + c13 + c14;
C(11,12) = -c13;
C(11,13) = -c14;
C(12,11) = -c13;
C(12,12) = c13 + c15;
C(12,14) = -c15;
C(13,11) = -c14;
C(13,13) = c14 + c16;
C(13,15) = -c16;
C(14,12) = -c15;
C(14,14) = c15 + c17;
C(14,16) = -c17;
C(15,13) = -c16;
C(15,15) = c16 + c18;
C(15,17) = -c18;
C(16,14) = -c17;
C(16,16) = c17 + c19;
C(17,15) = -c18;
C(17,17) = c18 + c20;
C(18,7) = -c23;
C(18,18) = c23 + c21 + c22;
C(18,19) = -c21 – c22;
C(19,18) = -c21 – c22;
C(19,19) = c21 + c22;
n=19;
y0 = zeros(2*n,1);
tspan = [0 120];
% ode45
[t, y] = ode45(@(t, y) odefcn_standing(t, y, M, C, K), tspan, y0);
figure;
plot(t, y(:, 19));
xlabel(‘Time (s)’);
ylabel(‘Displacement (m)’);
% legend(‘y1’, ‘y2’, ‘y3’);
title(‘response of the system 19DOF’);
grid on;
function dy = odefcn_standing(t, y, M, C, K)
n = 19; % Numero di gradi di libertà
dy = zeros(2 * n, 1);
% Construction of matrix A
A = [zeros(n), eye(n);
-inv(M) * K, -inv(M) * C];
F = zeros(19, 1);
f0 = 0.5; % initial frequency
f1 = 80; % final frequency
t_f = 120; % duration of chirp signal
chirp_signal = chirp(t, f0, t_f, f1);
F(16,:) = 10*chirp_signal; % on mass 16
F(17,:) = 10*chirp_signal; % on mass 17
% Construction of matrix B
B = [zeros(n, n); inv(M)];
dy = A * y + B * F;
endi have a problem solving the system with ode45. the code works but the displacement in graphed output is not what i would expect from a chirp signal. What could be the error in my code?
%MATRIX
M=diag([m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19]);
% stiffness matrix 19×19
K = zeros(19,19);
K(1,1) = k1 + k4 + k7 + k8;
K(1,2) = -k1;
K(1,5) = -k4;
K(1,7) = -k7;
K(1,8) = -k8;
K(2,1) = -k1;
K(2,2) = k1 + k2;
K(2,3) = -k2;
K(3,2) = -k2;
K(3,3) = k2 + k3;
K(3,4) = -k3;
K(4,3) = -k3;
K(4,4) = k3;
K(5,1) = -k4;
K(5,5) = k4 + k5 + k6;
K(5,6) = -k5;
K(5,7) = -k6;
K(6,5) = -k5;
K(6,6) = k5 + k11;
K(6,11) = -k11;
K(7,1) = -k7;
K(7,5) = -k6;
K(7,7) = k6 + k7 + k23;
K(7,18) = -k23;
K(8,1) = -k8;
K(8,8) = k8 + k9;
K(8,9) = -k9;
K(9,8) = -k9;
K(9,9) = k9 + k10;
K(9,10) = -k10;
K(10,9) = -k10;
K(10,10) = k10;
K(11,6) = -k11;
K(11,7) = -k12;
K(11,11) = k11 + k12 + k13 + k14;
K(11,12) = -k13;
K(11,13) = -k14;
K(12,11) = -k13;
K(12,12) = k13 + k15;
K(12,14) = -k15;
K(13,11) = -k14;
K(13,13) = k14 + k16;
K(13,15) = -k16;
K(14,12) = -k15;
K(14,14) = k15 + k17;
K(14,16) = -k17;
K(15,13) = -k16;
K(15,15) = k16 + k18;
K(15,17) = -k18;
K(16,14) = -k17;
K(16,16) = k17 + k19;
K(17,15) = -k18;
K(17,17) = k18 + k20;
K(18,7) = -k23;
K(18,18) = k23 + k21 + k22;
K(18,19) = -k21 – k22;
K(19,18) = -k21 – k22;
K(19,19) = k21 + k22;
% damping matrix 19×19
C = zeros(19,19);
C(1,1) = c1 + c4 + c7 + c8;
C(1,2) = -c1;
C(1,5) = -c4;
C(1,7) = -c7;
C(1,8) = -c8;
C(2,1) = -c1;
C(2,2) = c1 + c2;
C(2,3) = -c2;
C(3,2) = -c2;
C(3,3) = c2 + c3;
C(3,4) = -c3;
C(4,3) = -c3;
C(4,4) = c3;
C(5,1) = -c4;
C(5,5) = c4 + c5 + c6;
C(5,6) = -c5;
C(5,7) = -c6;
C(6,5) = -c5;
C(6,6) = c5 + c11;
C(6,11) = -c11;
C(7,1) = -c7;
C(7,5) = -c6;
C(7,7) = c6 + c7 + c23;
C(7,18) = -c23;
C(8,1) = -c8;
C(8,8) = c8 + c9;
C(8,9) = -c9;
C(9,8) = -c9;
C(9,9) = c9 + c10;
C(9,10) = -c10;
C(10,9) = -c10;
C(10,10) = c10;
C(11,6) = -c11;
C(11,7) = -c12;
C(11,11) = c11 + c12 + c13 + c14;
C(11,12) = -c13;
C(11,13) = -c14;
C(12,11) = -c13;
C(12,12) = c13 + c15;
C(12,14) = -c15;
C(13,11) = -c14;
C(13,13) = c14 + c16;
C(13,15) = -c16;
C(14,12) = -c15;
C(14,14) = c15 + c17;
C(14,16) = -c17;
C(15,13) = -c16;
C(15,15) = c16 + c18;
C(15,17) = -c18;
C(16,14) = -c17;
C(16,16) = c17 + c19;
C(17,15) = -c18;
C(17,17) = c18 + c20;
C(18,7) = -c23;
C(18,18) = c23 + c21 + c22;
C(18,19) = -c21 – c22;
C(19,18) = -c21 – c22;
C(19,19) = c21 + c22;
n=19;
y0 = zeros(2*n,1);
tspan = [0 120];
% ode45
[t, y] = ode45(@(t, y) odefcn_standing(t, y, M, C, K), tspan, y0);
figure;
plot(t, y(:, 19));
xlabel(‘Time (s)’);
ylabel(‘Displacement (m)’);
% legend(‘y1’, ‘y2’, ‘y3’);
title(‘response of the system 19DOF’);
grid on;
function dy = odefcn_standing(t, y, M, C, K)
n = 19; % Numero di gradi di libertà
dy = zeros(2 * n, 1);
% Construction of matrix A
A = [zeros(n), eye(n);
-inv(M) * K, -inv(M) * C];
F = zeros(19, 1);
f0 = 0.5; % initial frequency
f1 = 80; % final frequency
t_f = 120; % duration of chirp signal
chirp_signal = chirp(t, f0, t_f, f1);
F(16,:) = 10*chirp_signal; % on mass 16
F(17,:) = 10*chirp_signal; % on mass 17
% Construction of matrix B
B = [zeros(n, n); inv(M)];
dy = A * y + B * F;
end i have a problem solving the system with ode45. the code works but the displacement in graphed output is not what i would expect from a chirp signal. What could be the error in my code?
%MATRIX
M=diag([m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19]);
% stiffness matrix 19×19
K = zeros(19,19);
K(1,1) = k1 + k4 + k7 + k8;
K(1,2) = -k1;
K(1,5) = -k4;
K(1,7) = -k7;
K(1,8) = -k8;
K(2,1) = -k1;
K(2,2) = k1 + k2;
K(2,3) = -k2;
K(3,2) = -k2;
K(3,3) = k2 + k3;
K(3,4) = -k3;
K(4,3) = -k3;
K(4,4) = k3;
K(5,1) = -k4;
K(5,5) = k4 + k5 + k6;
K(5,6) = -k5;
K(5,7) = -k6;
K(6,5) = -k5;
K(6,6) = k5 + k11;
K(6,11) = -k11;
K(7,1) = -k7;
K(7,5) = -k6;
K(7,7) = k6 + k7 + k23;
K(7,18) = -k23;
K(8,1) = -k8;
K(8,8) = k8 + k9;
K(8,9) = -k9;
K(9,8) = -k9;
K(9,9) = k9 + k10;
K(9,10) = -k10;
K(10,9) = -k10;
K(10,10) = k10;
K(11,6) = -k11;
K(11,7) = -k12;
K(11,11) = k11 + k12 + k13 + k14;
K(11,12) = -k13;
K(11,13) = -k14;
K(12,11) = -k13;
K(12,12) = k13 + k15;
K(12,14) = -k15;
K(13,11) = -k14;
K(13,13) = k14 + k16;
K(13,15) = -k16;
K(14,12) = -k15;
K(14,14) = k15 + k17;
K(14,16) = -k17;
K(15,13) = -k16;
K(15,15) = k16 + k18;
K(15,17) = -k18;
K(16,14) = -k17;
K(16,16) = k17 + k19;
K(17,15) = -k18;
K(17,17) = k18 + k20;
K(18,7) = -k23;
K(18,18) = k23 + k21 + k22;
K(18,19) = -k21 – k22;
K(19,18) = -k21 – k22;
K(19,19) = k21 + k22;
% damping matrix 19×19
C = zeros(19,19);
C(1,1) = c1 + c4 + c7 + c8;
C(1,2) = -c1;
C(1,5) = -c4;
C(1,7) = -c7;
C(1,8) = -c8;
C(2,1) = -c1;
C(2,2) = c1 + c2;
C(2,3) = -c2;
C(3,2) = -c2;
C(3,3) = c2 + c3;
C(3,4) = -c3;
C(4,3) = -c3;
C(4,4) = c3;
C(5,1) = -c4;
C(5,5) = c4 + c5 + c6;
C(5,6) = -c5;
C(5,7) = -c6;
C(6,5) = -c5;
C(6,6) = c5 + c11;
C(6,11) = -c11;
C(7,1) = -c7;
C(7,5) = -c6;
C(7,7) = c6 + c7 + c23;
C(7,18) = -c23;
C(8,1) = -c8;
C(8,8) = c8 + c9;
C(8,9) = -c9;
C(9,8) = -c9;
C(9,9) = c9 + c10;
C(9,10) = -c10;
C(10,9) = -c10;
C(10,10) = c10;
C(11,6) = -c11;
C(11,7) = -c12;
C(11,11) = c11 + c12 + c13 + c14;
C(11,12) = -c13;
C(11,13) = -c14;
C(12,11) = -c13;
C(12,12) = c13 + c15;
C(12,14) = -c15;
C(13,11) = -c14;
C(13,13) = c14 + c16;
C(13,15) = -c16;
C(14,12) = -c15;
C(14,14) = c15 + c17;
C(14,16) = -c17;
C(15,13) = -c16;
C(15,15) = c16 + c18;
C(15,17) = -c18;
C(16,14) = -c17;
C(16,16) = c17 + c19;
C(17,15) = -c18;
C(17,17) = c18 + c20;
C(18,7) = -c23;
C(18,18) = c23 + c21 + c22;
C(18,19) = -c21 – c22;
C(19,18) = -c21 – c22;
C(19,19) = c21 + c22;
n=19;
y0 = zeros(2*n,1);
tspan = [0 120];
% ode45
[t, y] = ode45(@(t, y) odefcn_standing(t, y, M, C, K), tspan, y0);
figure;
plot(t, y(:, 19));
xlabel(‘Time (s)’);
ylabel(‘Displacement (m)’);
% legend(‘y1’, ‘y2’, ‘y3’);
title(‘response of the system 19DOF’);
grid on;
function dy = odefcn_standing(t, y, M, C, K)
n = 19; % Numero di gradi di libertà
dy = zeros(2 * n, 1);
% Construction of matrix A
A = [zeros(n), eye(n);
-inv(M) * K, -inv(M) * C];
F = zeros(19, 1);
f0 = 0.5; % initial frequency
f1 = 80; % final frequency
t_f = 120; % duration of chirp signal
chirp_signal = chirp(t, f0, t_f, f1);
F(16,:) = 10*chirp_signal; % on mass 16
F(17,:) = 10*chirp_signal; % on mass 17
% Construction of matrix B
B = [zeros(n, n); inv(M)];
dy = A * y + B * F;
end ode45, mdof MATLAB Answers — New Questions
Getting the Error “Not enough input arguments” but I did the exact same method earlier in the code without issue..
clear all
close all
clc
% EMEC-342 Mini Project: 4-Bar Linkage Analysis
% Known Values
a=10; % cm
b=25; %cm
c=25; %cm
d = 20; % cm
AP=50; % cm
n=a/2;
q=c/2;
delta2=0;
delta3=0;
delta4=0;
w2=10; %rad/sec
alpha2=0;
oc=1;
t2=zeros(1,361); % rotation angle theta2 of O2A
for (i=1:361)
t2=i-1;
end
% Calculation of K1,K2,K3,K4,K5
K1=d/a;
K2=d/c;
K3=(a^2-b^2+c^2+d^2)/(2*a*c);
K4=d/b;
K5=(c^2-d^2-a^2-b^2)/(2*a*b);
%% Matlab Functions
function f=Grashof(lengths)
u=sort(lengths);
if((u(1)+u(4))<(u(2)+u(3)))
f=1;
elseif (u(1)+u(4))==(u(2)+u(3))
f=0;
else
f=-1;
end
end
%% Functions for calculation of angular orientations theta3, theta4
% of links AB and O4B
% Calculation of A
function AA=A(K1,K2,K3,t2)
AA=cos(t2)-K1-K2*cos(t2)+K3;
end
% Calculation of B
function BB=B(t2)
BB=-2*sin(t2);
end
% Calculation of C
function CC=C(K1,K2,K3,t2)
CC=K1-(K2+1)*cos(t2)+K3;
end
% Calculation of angular orientation theta4
function t4=theta4(K1,K2,K3,t2,oc)
AA = A(K1,K2,K3,theta2);
BB = B(theta2);
CC = C(K1,K2,K3,theta2);
t4=2*atan((-BB+oc*sqrt(BB^2-4*AA*CC))/(2*AA));
end
% Calculation of D
function DD=D(K1,K4,K5,t2)
DD=cos(t2)-K1+(K4*cos(t2))+K5;
end
% Calculation of E
function EE=E(t2)
EE=-2*sin(t2);
end
% Calculation of F
function FF=F(K1,K4,K5,t2)
FF=K1+(K4-1)*cos(t2)+K5;
end
% Calculation of angular orientation theta3
function t3=theta3(K1,K4,K5,t2,oc)
DD=D(K1,K4,K5,t2);
EE=E(t2);
FF=F(K1,K4,K5,t2);
t3=2*atan((-EE+oc*sqrt(EE^2-4*DD*FF))/(2*DD));
end
%% Functions for calculation of angular speeds omega3, omega4
% of links AB and O4B
%returns results as vector of x and y components
% returns x and y component
function as=angSpeed(a,b,c,w2,t2,t3,t4)
as=[w2*a/b*sin(t4-t2)/sin(t3-t4),w2*a/c*sin(t2-t3)/sin(t4-t3)];
end
%% Position Vectors
function r=RAO2(a,t2)
r= [a*cos(t2),a*sin(t2)];
end
function r=RPA(AP,t3,delta3)
r=AP*[cos(t3+delta3),sin(t3+delta3)];
end
function r=RPO2(a,PA,t2,t3,delta3)
r=RAO2(a,t2)+RPA(PA,t3,delta3);
end
%% Functions for calculation of angular acceleration alpha3, alpha4
% of links AB and O4B
%returns results as vector of x and y components
% returns x and y component
% Calculation of G
function GG=G(c,theta4)
GG=c*sin(theta4);
end
% Calculation of H
function HH=H(b,theta3)
HH=b*sin(theta3);
end
% Calculation of I
function II=I(a,b,c,alpha2,w2,omega3,omega4,t2,theta3,theta4)
II=(a*alpha2*sin(t2))+(a*w2^2*cos(t2))+(b*omega3^2*cos(theta3))-(c*omega4^2*cos(theta4));
end
% Calculation of J
function JJ=J(c,theta4)
JJ=c*cos(theta4);
end
% Calculation of K
function KK=K(b,theta3)
KK=b*cos(theta3);
end
% Calculation of L
function LL=L(a,b,c,alpha2,w2,angSpeed,t2,theta3,theta4)
LL=(a*alpha2*cos(t2))+(a*w2^2*sin(t2))+(b*angSpeed(1)^2*sin(theta3))-(c*angSpeed(2)^2*sin(theta4));
end
function aa=angAccel(G,H,I,J,K,L)
GG=G(c,theta4);
HH=H(b,theta3);
II=I(a,b,c,alpha2,w2,omega3,omega4,t2,theta3,theta4);
JJ=J(c,theta4);
KK=K(b,theta3);
LL=L(a,b,c,alpha2,w2,angSpeed,t2,theta3,theta4);
aa=[(II*JJ-GG*LL)/(GG*KK-HH*JJ),(II*KK-HH*JJ)/(GG*KK-HH*JJ)];
end
%% Trace Point Velocity
function v=VA(a,w2,t2)
v=[-a*w2*sin(t2),a*w2*cos(t2)];
end
function v=VPA(AP,angSpeed,theta3,delta3)
v=AP*[-angSpeed(1)*sin(theta3+delta3),angSpeed(1)*cos(theta3+delta3)];
end
function v=VPO2(a,w2,angSpeed,t2,theta3,delta3,AP)
v=VA(a,w2,t2)+VPA(AP,angSpeed(1),theta3,delta3);
end
%% Trace Point Acceleration
function a=aA(a,alpha2,t2,w2)
a=[-a*alpha2*sin(t2),-a*w2^2*cos(t2)];
end
function a=APA(AP,angSpeed,theta3,delta3,angAccel)
a=AP*[-angAccel(1)*sin(theta3+delta3),-angSpeed(1)^2*cos(theta3+delta3)];
end
function a=APO2(a,w2,angSpeed,t2,theta3,delta3,AP)
a=aA(a,alpha2,t2,w2)+APA(AP,angSpeed(1),theta3,delta3,alpha3);
end
%% Tracepoint Acceleration N
function aN=ANO2(alpha2,t2,delta2,w2,RNO2)
aN=RNO2*[-alpha2*sin(t2+delta2)-(w2^2*cos(t2+deta2)),alpha2*cos(t2+delta2)-(w2^2*sin(t2+delta2))];
end
%% Plots
% Plot of theta3 and theta4 as functions of theta2
figure(1)
plot(t2,theta3,’r:’);
hold on
plot(t2,theta4,’b-‘);
% Plot of omega3 and omega4 as functions if theta2
figure(2)
plot(t2,angSpeed(1),’r:’);
hold on
plot(t2,angSpeed(2),’b-‘);
% Plot of alpha3 and alpha4 as functions of theta2
figure(3)
plot(t2,angAccel(1),’r:’);
hold on
plot(t2,angAccel(2),’b-‘);
% Plot of RPO2y as a function of RPO2x
figure(4)
plot(RPO2(1),RPO2(2));
% Plot of VPO2x as a function of RPO2x
figure(5)
plot(RPO2(1),VPO2(1));
% Plot of VPO2y as a function of RPO2y
figure(6)
plot(RPO2(2),VPO2(2));
% Plot of magnitude of VPO2 as a function of theta2
figure(7)
VPO2mag=sqrt(v(1,i)^2+v(2,i)^2);
plot(t2,VPO2mag);
% Plot of aPO2x as a function of RPO2x
figure(8)
plot(r(1),a(2));
% Plot of aPO2y as a function of RPO2y
figure(9)
plot(r(2),a(2));
% Plot of VPO2y as a function of RPO2y
figure(10)
aNO2mag=sqrt(aN(1,i)^2+aN(2,i)^2);
plot(t2,aNO2mag);clear all
close all
clc
% EMEC-342 Mini Project: 4-Bar Linkage Analysis
% Known Values
a=10; % cm
b=25; %cm
c=25; %cm
d = 20; % cm
AP=50; % cm
n=a/2;
q=c/2;
delta2=0;
delta3=0;
delta4=0;
w2=10; %rad/sec
alpha2=0;
oc=1;
t2=zeros(1,361); % rotation angle theta2 of O2A
for (i=1:361)
t2=i-1;
end
% Calculation of K1,K2,K3,K4,K5
K1=d/a;
K2=d/c;
K3=(a^2-b^2+c^2+d^2)/(2*a*c);
K4=d/b;
K5=(c^2-d^2-a^2-b^2)/(2*a*b);
%% Matlab Functions
function f=Grashof(lengths)
u=sort(lengths);
if((u(1)+u(4))<(u(2)+u(3)))
f=1;
elseif (u(1)+u(4))==(u(2)+u(3))
f=0;
else
f=-1;
end
end
%% Functions for calculation of angular orientations theta3, theta4
% of links AB and O4B
% Calculation of A
function AA=A(K1,K2,K3,t2)
AA=cos(t2)-K1-K2*cos(t2)+K3;
end
% Calculation of B
function BB=B(t2)
BB=-2*sin(t2);
end
% Calculation of C
function CC=C(K1,K2,K3,t2)
CC=K1-(K2+1)*cos(t2)+K3;
end
% Calculation of angular orientation theta4
function t4=theta4(K1,K2,K3,t2,oc)
AA = A(K1,K2,K3,theta2);
BB = B(theta2);
CC = C(K1,K2,K3,theta2);
t4=2*atan((-BB+oc*sqrt(BB^2-4*AA*CC))/(2*AA));
end
% Calculation of D
function DD=D(K1,K4,K5,t2)
DD=cos(t2)-K1+(K4*cos(t2))+K5;
end
% Calculation of E
function EE=E(t2)
EE=-2*sin(t2);
end
% Calculation of F
function FF=F(K1,K4,K5,t2)
FF=K1+(K4-1)*cos(t2)+K5;
end
% Calculation of angular orientation theta3
function t3=theta3(K1,K4,K5,t2,oc)
DD=D(K1,K4,K5,t2);
EE=E(t2);
FF=F(K1,K4,K5,t2);
t3=2*atan((-EE+oc*sqrt(EE^2-4*DD*FF))/(2*DD));
end
%% Functions for calculation of angular speeds omega3, omega4
% of links AB and O4B
%returns results as vector of x and y components
% returns x and y component
function as=angSpeed(a,b,c,w2,t2,t3,t4)
as=[w2*a/b*sin(t4-t2)/sin(t3-t4),w2*a/c*sin(t2-t3)/sin(t4-t3)];
end
%% Position Vectors
function r=RAO2(a,t2)
r= [a*cos(t2),a*sin(t2)];
end
function r=RPA(AP,t3,delta3)
r=AP*[cos(t3+delta3),sin(t3+delta3)];
end
function r=RPO2(a,PA,t2,t3,delta3)
r=RAO2(a,t2)+RPA(PA,t3,delta3);
end
%% Functions for calculation of angular acceleration alpha3, alpha4
% of links AB and O4B
%returns results as vector of x and y components
% returns x and y component
% Calculation of G
function GG=G(c,theta4)
GG=c*sin(theta4);
end
% Calculation of H
function HH=H(b,theta3)
HH=b*sin(theta3);
end
% Calculation of I
function II=I(a,b,c,alpha2,w2,omega3,omega4,t2,theta3,theta4)
II=(a*alpha2*sin(t2))+(a*w2^2*cos(t2))+(b*omega3^2*cos(theta3))-(c*omega4^2*cos(theta4));
end
% Calculation of J
function JJ=J(c,theta4)
JJ=c*cos(theta4);
end
% Calculation of K
function KK=K(b,theta3)
KK=b*cos(theta3);
end
% Calculation of L
function LL=L(a,b,c,alpha2,w2,angSpeed,t2,theta3,theta4)
LL=(a*alpha2*cos(t2))+(a*w2^2*sin(t2))+(b*angSpeed(1)^2*sin(theta3))-(c*angSpeed(2)^2*sin(theta4));
end
function aa=angAccel(G,H,I,J,K,L)
GG=G(c,theta4);
HH=H(b,theta3);
II=I(a,b,c,alpha2,w2,omega3,omega4,t2,theta3,theta4);
JJ=J(c,theta4);
KK=K(b,theta3);
LL=L(a,b,c,alpha2,w2,angSpeed,t2,theta3,theta4);
aa=[(II*JJ-GG*LL)/(GG*KK-HH*JJ),(II*KK-HH*JJ)/(GG*KK-HH*JJ)];
end
%% Trace Point Velocity
function v=VA(a,w2,t2)
v=[-a*w2*sin(t2),a*w2*cos(t2)];
end
function v=VPA(AP,angSpeed,theta3,delta3)
v=AP*[-angSpeed(1)*sin(theta3+delta3),angSpeed(1)*cos(theta3+delta3)];
end
function v=VPO2(a,w2,angSpeed,t2,theta3,delta3,AP)
v=VA(a,w2,t2)+VPA(AP,angSpeed(1),theta3,delta3);
end
%% Trace Point Acceleration
function a=aA(a,alpha2,t2,w2)
a=[-a*alpha2*sin(t2),-a*w2^2*cos(t2)];
end
function a=APA(AP,angSpeed,theta3,delta3,angAccel)
a=AP*[-angAccel(1)*sin(theta3+delta3),-angSpeed(1)^2*cos(theta3+delta3)];
end
function a=APO2(a,w2,angSpeed,t2,theta3,delta3,AP)
a=aA(a,alpha2,t2,w2)+APA(AP,angSpeed(1),theta3,delta3,alpha3);
end
%% Tracepoint Acceleration N
function aN=ANO2(alpha2,t2,delta2,w2,RNO2)
aN=RNO2*[-alpha2*sin(t2+delta2)-(w2^2*cos(t2+deta2)),alpha2*cos(t2+delta2)-(w2^2*sin(t2+delta2))];
end
%% Plots
% Plot of theta3 and theta4 as functions of theta2
figure(1)
plot(t2,theta3,’r:’);
hold on
plot(t2,theta4,’b-‘);
% Plot of omega3 and omega4 as functions if theta2
figure(2)
plot(t2,angSpeed(1),’r:’);
hold on
plot(t2,angSpeed(2),’b-‘);
% Plot of alpha3 and alpha4 as functions of theta2
figure(3)
plot(t2,angAccel(1),’r:’);
hold on
plot(t2,angAccel(2),’b-‘);
% Plot of RPO2y as a function of RPO2x
figure(4)
plot(RPO2(1),RPO2(2));
% Plot of VPO2x as a function of RPO2x
figure(5)
plot(RPO2(1),VPO2(1));
% Plot of VPO2y as a function of RPO2y
figure(6)
plot(RPO2(2),VPO2(2));
% Plot of magnitude of VPO2 as a function of theta2
figure(7)
VPO2mag=sqrt(v(1,i)^2+v(2,i)^2);
plot(t2,VPO2mag);
% Plot of aPO2x as a function of RPO2x
figure(8)
plot(r(1),a(2));
% Plot of aPO2y as a function of RPO2y
figure(9)
plot(r(2),a(2));
% Plot of VPO2y as a function of RPO2y
figure(10)
aNO2mag=sqrt(aN(1,i)^2+aN(2,i)^2);
plot(t2,aNO2mag); clear all
close all
clc
% EMEC-342 Mini Project: 4-Bar Linkage Analysis
% Known Values
a=10; % cm
b=25; %cm
c=25; %cm
d = 20; % cm
AP=50; % cm
n=a/2;
q=c/2;
delta2=0;
delta3=0;
delta4=0;
w2=10; %rad/sec
alpha2=0;
oc=1;
t2=zeros(1,361); % rotation angle theta2 of O2A
for (i=1:361)
t2=i-1;
end
% Calculation of K1,K2,K3,K4,K5
K1=d/a;
K2=d/c;
K3=(a^2-b^2+c^2+d^2)/(2*a*c);
K4=d/b;
K5=(c^2-d^2-a^2-b^2)/(2*a*b);
%% Matlab Functions
function f=Grashof(lengths)
u=sort(lengths);
if((u(1)+u(4))<(u(2)+u(3)))
f=1;
elseif (u(1)+u(4))==(u(2)+u(3))
f=0;
else
f=-1;
end
end
%% Functions for calculation of angular orientations theta3, theta4
% of links AB and O4B
% Calculation of A
function AA=A(K1,K2,K3,t2)
AA=cos(t2)-K1-K2*cos(t2)+K3;
end
% Calculation of B
function BB=B(t2)
BB=-2*sin(t2);
end
% Calculation of C
function CC=C(K1,K2,K3,t2)
CC=K1-(K2+1)*cos(t2)+K3;
end
% Calculation of angular orientation theta4
function t4=theta4(K1,K2,K3,t2,oc)
AA = A(K1,K2,K3,theta2);
BB = B(theta2);
CC = C(K1,K2,K3,theta2);
t4=2*atan((-BB+oc*sqrt(BB^2-4*AA*CC))/(2*AA));
end
% Calculation of D
function DD=D(K1,K4,K5,t2)
DD=cos(t2)-K1+(K4*cos(t2))+K5;
end
% Calculation of E
function EE=E(t2)
EE=-2*sin(t2);
end
% Calculation of F
function FF=F(K1,K4,K5,t2)
FF=K1+(K4-1)*cos(t2)+K5;
end
% Calculation of angular orientation theta3
function t3=theta3(K1,K4,K5,t2,oc)
DD=D(K1,K4,K5,t2);
EE=E(t2);
FF=F(K1,K4,K5,t2);
t3=2*atan((-EE+oc*sqrt(EE^2-4*DD*FF))/(2*DD));
end
%% Functions for calculation of angular speeds omega3, omega4
% of links AB and O4B
%returns results as vector of x and y components
% returns x and y component
function as=angSpeed(a,b,c,w2,t2,t3,t4)
as=[w2*a/b*sin(t4-t2)/sin(t3-t4),w2*a/c*sin(t2-t3)/sin(t4-t3)];
end
%% Position Vectors
function r=RAO2(a,t2)
r= [a*cos(t2),a*sin(t2)];
end
function r=RPA(AP,t3,delta3)
r=AP*[cos(t3+delta3),sin(t3+delta3)];
end
function r=RPO2(a,PA,t2,t3,delta3)
r=RAO2(a,t2)+RPA(PA,t3,delta3);
end
%% Functions for calculation of angular acceleration alpha3, alpha4
% of links AB and O4B
%returns results as vector of x and y components
% returns x and y component
% Calculation of G
function GG=G(c,theta4)
GG=c*sin(theta4);
end
% Calculation of H
function HH=H(b,theta3)
HH=b*sin(theta3);
end
% Calculation of I
function II=I(a,b,c,alpha2,w2,omega3,omega4,t2,theta3,theta4)
II=(a*alpha2*sin(t2))+(a*w2^2*cos(t2))+(b*omega3^2*cos(theta3))-(c*omega4^2*cos(theta4));
end
% Calculation of J
function JJ=J(c,theta4)
JJ=c*cos(theta4);
end
% Calculation of K
function KK=K(b,theta3)
KK=b*cos(theta3);
end
% Calculation of L
function LL=L(a,b,c,alpha2,w2,angSpeed,t2,theta3,theta4)
LL=(a*alpha2*cos(t2))+(a*w2^2*sin(t2))+(b*angSpeed(1)^2*sin(theta3))-(c*angSpeed(2)^2*sin(theta4));
end
function aa=angAccel(G,H,I,J,K,L)
GG=G(c,theta4);
HH=H(b,theta3);
II=I(a,b,c,alpha2,w2,omega3,omega4,t2,theta3,theta4);
JJ=J(c,theta4);
KK=K(b,theta3);
LL=L(a,b,c,alpha2,w2,angSpeed,t2,theta3,theta4);
aa=[(II*JJ-GG*LL)/(GG*KK-HH*JJ),(II*KK-HH*JJ)/(GG*KK-HH*JJ)];
end
%% Trace Point Velocity
function v=VA(a,w2,t2)
v=[-a*w2*sin(t2),a*w2*cos(t2)];
end
function v=VPA(AP,angSpeed,theta3,delta3)
v=AP*[-angSpeed(1)*sin(theta3+delta3),angSpeed(1)*cos(theta3+delta3)];
end
function v=VPO2(a,w2,angSpeed,t2,theta3,delta3,AP)
v=VA(a,w2,t2)+VPA(AP,angSpeed(1),theta3,delta3);
end
%% Trace Point Acceleration
function a=aA(a,alpha2,t2,w2)
a=[-a*alpha2*sin(t2),-a*w2^2*cos(t2)];
end
function a=APA(AP,angSpeed,theta3,delta3,angAccel)
a=AP*[-angAccel(1)*sin(theta3+delta3),-angSpeed(1)^2*cos(theta3+delta3)];
end
function a=APO2(a,w2,angSpeed,t2,theta3,delta3,AP)
a=aA(a,alpha2,t2,w2)+APA(AP,angSpeed(1),theta3,delta3,alpha3);
end
%% Tracepoint Acceleration N
function aN=ANO2(alpha2,t2,delta2,w2,RNO2)
aN=RNO2*[-alpha2*sin(t2+delta2)-(w2^2*cos(t2+deta2)),alpha2*cos(t2+delta2)-(w2^2*sin(t2+delta2))];
end
%% Plots
% Plot of theta3 and theta4 as functions of theta2
figure(1)
plot(t2,theta3,’r:’);
hold on
plot(t2,theta4,’b-‘);
% Plot of omega3 and omega4 as functions if theta2
figure(2)
plot(t2,angSpeed(1),’r:’);
hold on
plot(t2,angSpeed(2),’b-‘);
% Plot of alpha3 and alpha4 as functions of theta2
figure(3)
plot(t2,angAccel(1),’r:’);
hold on
plot(t2,angAccel(2),’b-‘);
% Plot of RPO2y as a function of RPO2x
figure(4)
plot(RPO2(1),RPO2(2));
% Plot of VPO2x as a function of RPO2x
figure(5)
plot(RPO2(1),VPO2(1));
% Plot of VPO2y as a function of RPO2y
figure(6)
plot(RPO2(2),VPO2(2));
% Plot of magnitude of VPO2 as a function of theta2
figure(7)
VPO2mag=sqrt(v(1,i)^2+v(2,i)^2);
plot(t2,VPO2mag);
% Plot of aPO2x as a function of RPO2x
figure(8)
plot(r(1),a(2));
% Plot of aPO2y as a function of RPO2y
figure(9)
plot(r(2),a(2));
% Plot of VPO2y as a function of RPO2y
figure(10)
aNO2mag=sqrt(aN(1,i)^2+aN(2,i)^2);
plot(t2,aNO2mag); error MATLAB Answers — New Questions
bitshift in matlab vs ishft in fortran
Hi,
I am trying to convert a large 64 bit number into 2x 32 bit numbers, Here is my code:
U = bitshift(v, -24);
L = bitand(v, 0x000000ffffffs64);
This is replicated off of fortran code:
U = ishft(v, -24)
L = iand(v, Z’000000ffffff’)
For value v = 2830037, the L’s agree, but "bitshift(2830037, -24) = 0" and "ishft(2830037, -24) = 1".
I am confused. Any help would be appreciated!Hi,
I am trying to convert a large 64 bit number into 2x 32 bit numbers, Here is my code:
U = bitshift(v, -24);
L = bitand(v, 0x000000ffffffs64);
This is replicated off of fortran code:
U = ishft(v, -24)
L = iand(v, Z’000000ffffff’)
For value v = 2830037, the L’s agree, but "bitshift(2830037, -24) = 0" and "ishft(2830037, -24) = 1".
I am confused. Any help would be appreciated! Hi,
I am trying to convert a large 64 bit number into 2x 32 bit numbers, Here is my code:
U = bitshift(v, -24);
L = bitand(v, 0x000000ffffffs64);
This is replicated off of fortran code:
U = ishft(v, -24)
L = iand(v, Z’000000ffffff’)
For value v = 2830037, the L’s agree, but "bitshift(2830037, -24) = 0" and "ishft(2830037, -24) = 1".
I am confused. Any help would be appreciated! matlab, fortran MATLAB Answers — New Questions
In the joint simulation of MATLAB (2021b) and NS-3 in Ubuntu (20.04.6), libmx.so => not found libmex.so => not found
How can I download these two missing files libmx.so and libmex.soHow can I download these two missing files libmx.so and libmex.so How can I download these two missing files libmx.so and libmex.so the joint simulation of matlab (2021b) and ns-3 MATLAB Answers — New Questions
Problem with Simscape Onramp
Hello!
I’m trying to access the Simscape Onramp course in browser mode and the Simulink window refuses to open even after waiting for a long time.
The one time it did open, it showed an error when clicking on Submit for the very first assignment.
"Unrecognized function or variable ‘simmechanics.sli.internal.register_datatypes’. (Figure atached)
Thanks!Hello!
I’m trying to access the Simscape Onramp course in browser mode and the Simulink window refuses to open even after waiting for a long time.
The one time it did open, it showed an error when clicking on Submit for the very first assignment.
"Unrecognized function or variable ‘simmechanics.sli.internal.register_datatypes’. (Figure atached)
Thanks! Hello!
I’m trying to access the Simscape Onramp course in browser mode and the Simulink window refuses to open even after waiting for a long time.
The one time it did open, it showed an error when clicking on Submit for the very first assignment.
"Unrecognized function or variable ‘simmechanics.sli.internal.register_datatypes’. (Figure atached)
Thanks! simscape onramp, courses MATLAB Answers — New Questions