Category: Matlab
Category Archives: Matlab
How to use PID controller
I have a control loop such that:
The loop starts by calculating the error between the desired and measured temperature.
The relay block turns the heating system on or off based on this error, with a hysteresis of ±5 degrees to prevent frequent switching.
The output from the relay (on/off signal) is passed through a transfer function to simulate the dynamics of the system (introducing a delay or lag in the heating response).
The scaled output from the transfer function (now a power signal) is converted into a physical signal.
Finally, the physical signal controls the heat source, which in turn affects the system’s temperature.
I want to use PID controller block instead of this, how can I achieve that?I have a control loop such that:
The loop starts by calculating the error between the desired and measured temperature.
The relay block turns the heating system on or off based on this error, with a hysteresis of ±5 degrees to prevent frequent switching.
The output from the relay (on/off signal) is passed through a transfer function to simulate the dynamics of the system (introducing a delay or lag in the heating response).
The scaled output from the transfer function (now a power signal) is converted into a physical signal.
Finally, the physical signal controls the heat source, which in turn affects the system’s temperature.
I want to use PID controller block instead of this, how can I achieve that? I have a control loop such that:
The loop starts by calculating the error between the desired and measured temperature.
The relay block turns the heating system on or off based on this error, with a hysteresis of ±5 degrees to prevent frequent switching.
The output from the relay (on/off signal) is passed through a transfer function to simulate the dynamics of the system (introducing a delay or lag in the heating response).
The scaled output from the transfer function (now a power signal) is converted into a physical signal.
Finally, the physical signal controls the heat source, which in turn affects the system’s temperature.
I want to use PID controller block instead of this, how can I achieve that? simulink, pid, simscape MATLAB Answers — New Questions
Variable gets cleared after each simulation step with simulink
Hello all,
I am using a System Object (SO) in combination with Simulink to simulate some stuff. Within that SO multiple objects of normal Matlab classes are instantiated in the setupImpl method. From one stepImpl to the next it seems that Matlab/Simulink clears/re-initializes the properties of those Matlab objects which in return costs time. How can I prevent this from happening? I want the memory of the Matlab Objects to be untouched because the size of their properties is large and don’t change over time. I thought of using persistent variables but I fail in defining persistent properties. Is that possible and if so, how?
Any hint is highly appreciated!Hello all,
I am using a System Object (SO) in combination with Simulink to simulate some stuff. Within that SO multiple objects of normal Matlab classes are instantiated in the setupImpl method. From one stepImpl to the next it seems that Matlab/Simulink clears/re-initializes the properties of those Matlab objects which in return costs time. How can I prevent this from happening? I want the memory of the Matlab Objects to be untouched because the size of their properties is large and don’t change over time. I thought of using persistent variables but I fail in defining persistent properties. Is that possible and if so, how?
Any hint is highly appreciated! Hello all,
I am using a System Object (SO) in combination with Simulink to simulate some stuff. Within that SO multiple objects of normal Matlab classes are instantiated in the setupImpl method. From one stepImpl to the next it seems that Matlab/Simulink clears/re-initializes the properties of those Matlab objects which in return costs time. How can I prevent this from happening? I want the memory of the Matlab Objects to be untouched because the size of their properties is large and don’t change over time. I thought of using persistent variables but I fail in defining persistent properties. Is that possible and if so, how?
Any hint is highly appreciated! persistent memory, simulink, class MATLAB Answers — New Questions
How to Measure Power Consumption of a Multiplexer and XOR Gate in MATLAB Simulink?
Hello everyone,
I am currently working on a logic circuit in MATLAB Simulink that involves a Multiplexer (MUX) and an XOR gate. I would like to measure the power consumption (current) of both the MUX and XOR components, but I’m not sure how to go about it in Simulink.
Here are some details about my setup:
I have a 4-to-1 MUX and an XOR gate in my design.
I am looking to measure the dynamic power consumption for each gate during operation.
Could anyone provide guidance on:
How to model or simulate the power consumption for logic components like MUX and XOR gates in Simulink?
Any recommended blocks or libraries to use?
Approaches for accurately measuring the current drawn by these components?
Any tips or examples would be greatly appreciated!Hello everyone,
I am currently working on a logic circuit in MATLAB Simulink that involves a Multiplexer (MUX) and an XOR gate. I would like to measure the power consumption (current) of both the MUX and XOR components, but I’m not sure how to go about it in Simulink.
Here are some details about my setup:
I have a 4-to-1 MUX and an XOR gate in my design.
I am looking to measure the dynamic power consumption for each gate during operation.
Could anyone provide guidance on:
How to model or simulate the power consumption for logic components like MUX and XOR gates in Simulink?
Any recommended blocks or libraries to use?
Approaches for accurately measuring the current drawn by these components?
Any tips or examples would be greatly appreciated! Hello everyone,
I am currently working on a logic circuit in MATLAB Simulink that involves a Multiplexer (MUX) and an XOR gate. I would like to measure the power consumption (current) of both the MUX and XOR components, but I’m not sure how to go about it in Simulink.
Here are some details about my setup:
I have a 4-to-1 MUX and an XOR gate in my design.
I am looking to measure the dynamic power consumption for each gate during operation.
Could anyone provide guidance on:
How to model or simulate the power consumption for logic components like MUX and XOR gates in Simulink?
Any recommended blocks or libraries to use?
Approaches for accurately measuring the current drawn by these components?
Any tips or examples would be greatly appreciated! simulink, mux, xor, current-power MATLAB Answers — New Questions
Need to show solutions (x) per iteration
I am using this optimizer tool since Matlab obliterated the old one —->
It has all these options, shown in the image bellow, to display many different values per iteration, except an option to display each value of the solution, x, at each iteration – which is what I need.
I have noticed that a lot of people have already asked the same question, but all the answers don’t seem to apply to the code I’m using (generated by the new optimization tool). While answers related to the old tool box do not apply anymore. The code the new tool generates looks a bit like this:
% Pass fixed parameters to objfun
objfun19 = @(x)LDR(x);
% Set nondefault solver options
options20 = optimoptions("gamultiobj","ConstraintTolerance",1e-05,"Display",…
"iter");
% Solve
[solution0,objectiveValue0] = gamultiobj(objfun19,v0,[],[],[],[],min,max,[],[],…
options20);
Where x is an array. I have been using multi-objective genetic algorithm, pareto search, and fmincon, which all look almost the same.
Appreciate any help. Please and thank you.I am using this optimizer tool since Matlab obliterated the old one —->
It has all these options, shown in the image bellow, to display many different values per iteration, except an option to display each value of the solution, x, at each iteration – which is what I need.
I have noticed that a lot of people have already asked the same question, but all the answers don’t seem to apply to the code I’m using (generated by the new optimization tool). While answers related to the old tool box do not apply anymore. The code the new tool generates looks a bit like this:
% Pass fixed parameters to objfun
objfun19 = @(x)LDR(x);
% Set nondefault solver options
options20 = optimoptions("gamultiobj","ConstraintTolerance",1e-05,"Display",…
"iter");
% Solve
[solution0,objectiveValue0] = gamultiobj(objfun19,v0,[],[],[],[],min,max,[],[],…
options20);
Where x is an array. I have been using multi-objective genetic algorithm, pareto search, and fmincon, which all look almost the same.
Appreciate any help. Please and thank you. I am using this optimizer tool since Matlab obliterated the old one —->
It has all these options, shown in the image bellow, to display many different values per iteration, except an option to display each value of the solution, x, at each iteration – which is what I need.
I have noticed that a lot of people have already asked the same question, but all the answers don’t seem to apply to the code I’m using (generated by the new optimization tool). While answers related to the old tool box do not apply anymore. The code the new tool generates looks a bit like this:
% Pass fixed parameters to objfun
objfun19 = @(x)LDR(x);
% Set nondefault solver options
options20 = optimoptions("gamultiobj","ConstraintTolerance",1e-05,"Display",…
"iter");
% Solve
[solution0,objectiveValue0] = gamultiobj(objfun19,v0,[],[],[],[],min,max,[],[],…
options20);
Where x is an array. I have been using multi-objective genetic algorithm, pareto search, and fmincon, which all look almost the same.
Appreciate any help. Please and thank you. optimization MATLAB Answers — New Questions
ERROR: ld.so: object ‘/tools/matlab/R2023bU1/bin/glnxa64/glibc-2.17_shim.so’ from LD_PRELOAD cannot be preloaded: ignored.
I experience this error when using HDL Verifier on a Linux machine (RedHat 7)
ERROR: ld.so: object ‘/tools/matlab/R2023bU1/bin/glnxa64/glibc-2.17_shim.so’ from LD_PRELOAD cannot be preloaded: ignored.
Do you know how I can overcome this issue?I experience this error when using HDL Verifier on a Linux machine (RedHat 7)
ERROR: ld.so: object ‘/tools/matlab/R2023bU1/bin/glnxa64/glibc-2.17_shim.so’ from LD_PRELOAD cannot be preloaded: ignored.
Do you know how I can overcome this issue? I experience this error when using HDL Verifier on a Linux machine (RedHat 7)
ERROR: ld.so: object ‘/tools/matlab/R2023bU1/bin/glnxa64/glibc-2.17_shim.so’ from LD_PRELOAD cannot be preloaded: ignored.
Do you know how I can overcome this issue? hdlverifier, simulink, linux, redhat MATLAB Answers — New Questions
How to determine the surrounding vertices of a particular node/voronoi cell ?
I want to determine the surrounding(corresponding) vertices of all the nodes of the voronoi cells. Please help adding to the program below.
x=[2 2 3 3 4 5 5 5 6 7 8];
y=[1 3 1 3 4 4 5 6 5 4 2];
N=[x’ y’];
axis([0 10 0 10]);
hold on;
scatter(x,y, [], ‘filled’);
%Labelling the nodes
labels = cellstr( num2str([1:length(x)]’) );
plot(N(:,1), N(:,2), ‘bx’)
text(N(:,1), N(:,2), labels, ‘VerticalAlignment’,’bottom’, …
‘HorizontalAlignment’,’right’)
%Voronoi
voronoi(x,y,’green’);
[vx,vy]=voronoi(x,y);
plot(vx,vy,’rx’);
grid on
[V C]=voronoin(N); %
%Labelling the vertices
labels = cellstr( num2str([1:length(V)]’) );
plot(V(:,1), V(:,2), ‘rx’)
text(V(:,1), V(:,2), labels, ‘VerticalAlignment’,’bottom’, …
‘HorizontalAlignment’,’right’)I want to determine the surrounding(corresponding) vertices of all the nodes of the voronoi cells. Please help adding to the program below.
x=[2 2 3 3 4 5 5 5 6 7 8];
y=[1 3 1 3 4 4 5 6 5 4 2];
N=[x’ y’];
axis([0 10 0 10]);
hold on;
scatter(x,y, [], ‘filled’);
%Labelling the nodes
labels = cellstr( num2str([1:length(x)]’) );
plot(N(:,1), N(:,2), ‘bx’)
text(N(:,1), N(:,2), labels, ‘VerticalAlignment’,’bottom’, …
‘HorizontalAlignment’,’right’)
%Voronoi
voronoi(x,y,’green’);
[vx,vy]=voronoi(x,y);
plot(vx,vy,’rx’);
grid on
[V C]=voronoin(N); %
%Labelling the vertices
labels = cellstr( num2str([1:length(V)]’) );
plot(V(:,1), V(:,2), ‘rx’)
text(V(:,1), V(:,2), labels, ‘VerticalAlignment’,’bottom’, …
‘HorizontalAlignment’,’right’) I want to determine the surrounding(corresponding) vertices of all the nodes of the voronoi cells. Please help adding to the program below.
x=[2 2 3 3 4 5 5 5 6 7 8];
y=[1 3 1 3 4 4 5 6 5 4 2];
N=[x’ y’];
axis([0 10 0 10]);
hold on;
scatter(x,y, [], ‘filled’);
%Labelling the nodes
labels = cellstr( num2str([1:length(x)]’) );
plot(N(:,1), N(:,2), ‘bx’)
text(N(:,1), N(:,2), labels, ‘VerticalAlignment’,’bottom’, …
‘HorizontalAlignment’,’right’)
%Voronoi
voronoi(x,y,’green’);
[vx,vy]=voronoi(x,y);
plot(vx,vy,’rx’);
grid on
[V C]=voronoin(N); %
%Labelling the vertices
labels = cellstr( num2str([1:length(V)]’) );
plot(V(:,1), V(:,2), ‘rx’)
text(V(:,1), V(:,2), labels, ‘VerticalAlignment’,’bottom’, …
‘HorizontalAlignment’,’right’) aida MATLAB Answers — New Questions
I need a program with a triangular Bezier patch in matlab
I need a program with a triangular Bezier patch in matlabI need a program with a triangular Bezier patch in matlab I need a program with a triangular Bezier patch in matlab bezier -patch -triangular-surf MATLAB Answers — New Questions
TI C2000 Microcontroller Slow IPC-Transmission of an int32 with just 1kHz
I tried to send an int32 via IPC transmit from the C28x CPU to the ARM M4-Cortex every 100 microseconds (10kHz clock-frequency) by using an EPWM-block and an EPWM-Hardware-Interrupt. Unfortunately, the IPC transmission only works fine until clock-frequencies of 1kHz (every 1 milliseconds). For higher clock-frequencys, the IPC-tranmission shuts down. Even by using the IPC-Receive on polling instead of using an IPC-Hardware-Interrupt, frequencies higher than 1kHz cannot be reached. In my understanding, the transmission should only be limited by the reading&writing speed of the Message-RAM (which must be at least 1MHz for an int32).
Could somebody assist how to increase the performance of the IPC transmission? Thanks in advance!
Kind regards!I tried to send an int32 via IPC transmit from the C28x CPU to the ARM M4-Cortex every 100 microseconds (10kHz clock-frequency) by using an EPWM-block and an EPWM-Hardware-Interrupt. Unfortunately, the IPC transmission only works fine until clock-frequencies of 1kHz (every 1 milliseconds). For higher clock-frequencys, the IPC-tranmission shuts down. Even by using the IPC-Receive on polling instead of using an IPC-Hardware-Interrupt, frequencies higher than 1kHz cannot be reached. In my understanding, the transmission should only be limited by the reading&writing speed of the Message-RAM (which must be at least 1MHz for an int32).
Could somebody assist how to increase the performance of the IPC transmission? Thanks in advance!
Kind regards! I tried to send an int32 via IPC transmit from the C28x CPU to the ARM M4-Cortex every 100 microseconds (10kHz clock-frequency) by using an EPWM-block and an EPWM-Hardware-Interrupt. Unfortunately, the IPC transmission only works fine until clock-frequencies of 1kHz (every 1 milliseconds). For higher clock-frequencys, the IPC-tranmission shuts down. Even by using the IPC-Receive on polling instead of using an IPC-Hardware-Interrupt, frequencies higher than 1kHz cannot be reached. In my understanding, the transmission should only be limited by the reading&writing speed of the Message-RAM (which must be at least 1MHz for an int32).
Could somebody assist how to increase the performance of the IPC transmission? Thanks in advance!
Kind regards! c2000, ipc, ipc-transmit, ipc-receive MATLAB Answers — New Questions
How do I resolve this error “Can’t load C:ProgramFilesMATLAB2024abinwin64l……: while trying to load SIMULINK
Hello, while attempting to use SIMULINK in MATLAB 2024a for my training, the above message was seen. Any help?Hello, while attempting to use SIMULINK in MATLAB 2024a for my training, the above message was seen. Any help? Hello, while attempting to use SIMULINK in MATLAB 2024a for my training, the above message was seen. Any help? simulink, matlab MATLAB Answers — New Questions
How to extract pixel intensity of a grayscale image (*.jpg) to a MS Excel table
Hello everyone, I am a very new beginner with image processing and Mathlab. Please help me with the following isse, many thanks in advance !
I have a grayscale image. I’d like to extract its pixel intensities to a MS Excel table with three vectors, including pixel intensiy, X and Y coordinates of the pixel.Hello everyone, I am a very new beginner with image processing and Mathlab. Please help me with the following isse, many thanks in advance !
I have a grayscale image. I’d like to extract its pixel intensities to a MS Excel table with three vectors, including pixel intensiy, X and Y coordinates of the pixel. Hello everyone, I am a very new beginner with image processing and Mathlab. Please help me with the following isse, many thanks in advance !
I have a grayscale image. I’d like to extract its pixel intensities to a MS Excel table with three vectors, including pixel intensiy, X and Y coordinates of the pixel. digital image processing, mathematics MATLAB Answers — New Questions
creating multiple holes in a flatwire PDE Modeler
Hi,
Matlab suggested me to create a more efficient code: what i am trying to do is to create 12 holes vertically in a strip of wire and repeat it 7x times over a 0.2 distance: i started with this code:
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
pderect([rectx rect_width recty,rect_height] )
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
pdecirc(x_center, y_center,radius)
hold on;
end
end
axis equal;
hold off;
better code as matlab suggested: but get stuck with an error:
Error in TestSkript2 (line 38)
ns(idx+1)=[‘C’,num2str(idx)];
please advise.
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
R1=[3,4,rectx, rectx+rect_width,rectx+rect_width,rectx,recty,recty,recty+rect_height,recty+rect_height]’;
%preallocating the arrays(more efficient for matlab CHAT GPT)
num_circles = num_holes_y * num_rep_x;
gd = zeros(10, 1 + num_circles);
gd(:, 1) = R1;
ns = cell(1+num_circles,1);
ns{ones}=’R1′;
sf=’R1′;
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
C=[1,x_center, y_center,radius]’;
idx=j*num_holes_y+i+1;
gd(1:4,idx+1)=C;
ns{idx+1}=[‘C’,num2str(idx)];
sf=[sf,’C’,num2str(idx)];
end
end
ns=char(ns);
g=decsg(gd,sf,ns);
axis equal;
hold off;Hi,
Matlab suggested me to create a more efficient code: what i am trying to do is to create 12 holes vertically in a strip of wire and repeat it 7x times over a 0.2 distance: i started with this code:
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
pderect([rectx rect_width recty,rect_height] )
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
pdecirc(x_center, y_center,radius)
hold on;
end
end
axis equal;
hold off;
better code as matlab suggested: but get stuck with an error:
Error in TestSkript2 (line 38)
ns(idx+1)=[‘C’,num2str(idx)];
please advise.
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
R1=[3,4,rectx, rectx+rect_width,rectx+rect_width,rectx,recty,recty,recty+rect_height,recty+rect_height]’;
%preallocating the arrays(more efficient for matlab CHAT GPT)
num_circles = num_holes_y * num_rep_x;
gd = zeros(10, 1 + num_circles);
gd(:, 1) = R1;
ns = cell(1+num_circles,1);
ns{ones}=’R1′;
sf=’R1′;
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
C=[1,x_center, y_center,radius]’;
idx=j*num_holes_y+i+1;
gd(1:4,idx+1)=C;
ns{idx+1}=[‘C’,num2str(idx)];
sf=[sf,’C’,num2str(idx)];
end
end
ns=char(ns);
g=decsg(gd,sf,ns);
axis equal;
hold off; Hi,
Matlab suggested me to create a more efficient code: what i am trying to do is to create 12 holes vertically in a strip of wire and repeat it 7x times over a 0.2 distance: i started with this code:
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
pderect([rectx rect_width recty,rect_height] )
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
pdecirc(x_center, y_center,radius)
hold on;
end
end
axis equal;
hold off;
better code as matlab suggested: but get stuck with an error:
Error in TestSkript2 (line 38)
ns(idx+1)=[‘C’,num2str(idx)];
please advise.
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
R1=[3,4,rectx, rectx+rect_width,rectx+rect_width,rectx,recty,recty,recty+rect_height,recty+rect_height]’;
%preallocating the arrays(more efficient for matlab CHAT GPT)
num_circles = num_holes_y * num_rep_x;
gd = zeros(10, 1 + num_circles);
gd(:, 1) = R1;
ns = cell(1+num_circles,1);
ns{ones}=’R1′;
sf=’R1′;
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
C=[1,x_center, y_center,radius]’;
idx=j*num_holes_y+i+1;
gd(1:4,idx+1)=C;
ns{idx+1}=[‘C’,num2str(idx)];
sf=[sf,’C’,num2str(idx)];
end
end
ns=char(ns);
g=decsg(gd,sf,ns);
axis equal;
hold off; pde modeler script. MATLAB Answers — New Questions
Mex Build Error: the following files have the same file name which cannot be packaged together in a flat hierarchy
I have files that multiple Sfuns use. When I want to build the project, I get the following error. What is the reason for this and is there a solution?
"the following files have the same file name which cannot be packaged together in a flat hierarchy"I have files that multiple Sfuns use. When I want to build the project, I get the following error. What is the reason for this and is there a solution?
"the following files have the same file name which cannot be packaged together in a flat hierarchy" I have files that multiple Sfuns use. When I want to build the project, I get the following error. What is the reason for this and is there a solution?
"the following files have the same file name which cannot be packaged together in a flat hierarchy" simulink, embedded coder, code generation MATLAB Answers — New Questions
Simscape Multibody Model with Elastic tooth mesh
Hi everybody,
I want to simulate an elastic tooth mesh within my simscape multibody model. The model is very simple and consists only two gears. The model works fine with the "Common Gear Constraint" block, but I want to simulate spring and damping effects. Therefore I added a Torsional Spring-Damper which I connected to the model via a Rotational Multibody Interface.
Error:An error occurred during simulation and the simulation was terminated
Caused by:
[‘Test_ElastischerZahneingriff_1/Solver Configuration’]: Initial conditions solve failed to converge.
Nonlinear solver: Linear Algebra error. Failed to solve using iteration matrix.
The model may not give enough information to make it possible to solve for values of some of its variables. Specific advice is given below.
all components and nodal across variables involved
Tie variable ‘Torsional_Spring_Damper.R.w’ (Rotational velocity) to a definite value, for example by connecting an appropriate domain reference block.
Dependency found among topology equations. Check for missing reference node.
Is anybody out there who can help me fixing this error?
You can see the model in the pictures.
Thank’s everybody for any helpful comment….
Kind regards,
ThomasHi everybody,
I want to simulate an elastic tooth mesh within my simscape multibody model. The model is very simple and consists only two gears. The model works fine with the "Common Gear Constraint" block, but I want to simulate spring and damping effects. Therefore I added a Torsional Spring-Damper which I connected to the model via a Rotational Multibody Interface.
Error:An error occurred during simulation and the simulation was terminated
Caused by:
[‘Test_ElastischerZahneingriff_1/Solver Configuration’]: Initial conditions solve failed to converge.
Nonlinear solver: Linear Algebra error. Failed to solve using iteration matrix.
The model may not give enough information to make it possible to solve for values of some of its variables. Specific advice is given below.
all components and nodal across variables involved
Tie variable ‘Torsional_Spring_Damper.R.w’ (Rotational velocity) to a definite value, for example by connecting an appropriate domain reference block.
Dependency found among topology equations. Check for missing reference node.
Is anybody out there who can help me fixing this error?
You can see the model in the pictures.
Thank’s everybody for any helpful comment….
Kind regards,
Thomas Hi everybody,
I want to simulate an elastic tooth mesh within my simscape multibody model. The model is very simple and consists only two gears. The model works fine with the "Common Gear Constraint" block, but I want to simulate spring and damping effects. Therefore I added a Torsional Spring-Damper which I connected to the model via a Rotational Multibody Interface.
Error:An error occurred during simulation and the simulation was terminated
Caused by:
[‘Test_ElastischerZahneingriff_1/Solver Configuration’]: Initial conditions solve failed to converge.
Nonlinear solver: Linear Algebra error. Failed to solve using iteration matrix.
The model may not give enough information to make it possible to solve for values of some of its variables. Specific advice is given below.
all components and nodal across variables involved
Tie variable ‘Torsional_Spring_Damper.R.w’ (Rotational velocity) to a definite value, for example by connecting an appropriate domain reference block.
Dependency found among topology equations. Check for missing reference node.
Is anybody out there who can help me fixing this error?
You can see the model in the pictures.
Thank’s everybody for any helpful comment….
Kind regards,
Thomas simscape, multibody, gear, elastic tooth mesh MATLAB Answers — New Questions
How do I install STM32Cube Firmware manually for use with the “Embedded Coder Support Package for STMicroelectronics STM32 Processors”?
During the Hardware Setup for the "Embedded Coder Support Package for STMicroelectronics STM32 Processors", the step "Install STM32Cube Firmware" fails with the error "Installation of STM32Cube firmware failed with the following error" as shown in the screenshot below.
Is there a different way to download the STM32Cube firmware for use with MATLAB/Simulink?During the Hardware Setup for the "Embedded Coder Support Package for STMicroelectronics STM32 Processors", the step "Install STM32Cube Firmware" fails with the error "Installation of STM32Cube firmware failed with the following error" as shown in the screenshot below.
Is there a different way to download the STM32Cube firmware for use with MATLAB/Simulink? During the Hardware Setup for the "Embedded Coder Support Package for STMicroelectronics STM32 Processors", the step "Install STM32Cube Firmware" fails with the error "Installation of STM32Cube firmware failed with the following error" as shown in the screenshot below.
Is there a different way to download the STM32Cube firmware for use with MATLAB/Simulink? offline, firewall, cubemx, stm32cubemx, firmware, stm32, setup MATLAB Answers — New Questions
Simulink build TI CCS Project error.
Post Content Post Content ccs ti MATLAB Answers — New Questions
Equivalence of MSK and Offset QPSK
Hi everyone,
i’m currently trying to create a offset QPSK modulation using an MSK with a half-sine matched filter. This is based on the IEEE paper https://ieeexplore.ieee.org/document/4102435. I generated an OQPSK and MSK signal with MATLAB and plotted the angle of the signal. Both can be seen below. There is no frequency error or noise. They spectrum for both is the same and the amplitude of the symbol stays constant, so this is indeed a OQPSK signal. Just the resulting bits are different.
I can demodulated the OQPSK using the OQPSK demodulation function from the Communications Toolbox as well as the with the symbol order based on the phase seen in the picture. So the OQPSK is correct. I can also demodulate the MSK with a normal FSK demodulater and the ouput is the same as with the OQPSK. But when applying any kinf of OQPSK demodulation to the MSK signal the resulting sequence is different as well as the phase (picture).
So is a MSK with Half-Sine Filter really equivalent to an OQPSK and both can be received with the same receiver?
This is the phase of the MSK signal
And this is the phase of the OQPSK signal
Best Regards,
AxelHi everyone,
i’m currently trying to create a offset QPSK modulation using an MSK with a half-sine matched filter. This is based on the IEEE paper https://ieeexplore.ieee.org/document/4102435. I generated an OQPSK and MSK signal with MATLAB and plotted the angle of the signal. Both can be seen below. There is no frequency error or noise. They spectrum for both is the same and the amplitude of the symbol stays constant, so this is indeed a OQPSK signal. Just the resulting bits are different.
I can demodulated the OQPSK using the OQPSK demodulation function from the Communications Toolbox as well as the with the symbol order based on the phase seen in the picture. So the OQPSK is correct. I can also demodulate the MSK with a normal FSK demodulater and the ouput is the same as with the OQPSK. But when applying any kinf of OQPSK demodulation to the MSK signal the resulting sequence is different as well as the phase (picture).
So is a MSK with Half-Sine Filter really equivalent to an OQPSK and both can be received with the same receiver?
This is the phase of the MSK signal
And this is the phase of the OQPSK signal
Best Regards,
Axel Hi everyone,
i’m currently trying to create a offset QPSK modulation using an MSK with a half-sine matched filter. This is based on the IEEE paper https://ieeexplore.ieee.org/document/4102435. I generated an OQPSK and MSK signal with MATLAB and plotted the angle of the signal. Both can be seen below. There is no frequency error or noise. They spectrum for both is the same and the amplitude of the symbol stays constant, so this is indeed a OQPSK signal. Just the resulting bits are different.
I can demodulated the OQPSK using the OQPSK demodulation function from the Communications Toolbox as well as the with the symbol order based on the phase seen in the picture. So the OQPSK is correct. I can also demodulate the MSK with a normal FSK demodulater and the ouput is the same as with the OQPSK. But when applying any kinf of OQPSK demodulation to the MSK signal the resulting sequence is different as well as the phase (picture).
So is a MSK with Half-Sine Filter really equivalent to an OQPSK and both can be received with the same receiver?
This is the phase of the MSK signal
And this is the phase of the OQPSK signal
Best Regards,
Axel msk, oqpsk MATLAB Answers — New Questions
You have to transmit Data Sequence 11100010 with transmission bit rate 1000000 through QPSK. Write a Matlab code and a) Generate data sequence and all the above mentioned wave
clear all
close all
Data_Seq=[1,1,1,0,0,0,1,0]
stem(Data_Seq)
bitrate= 1000000;
SR=1/bitrate;
ylim([-1 1])
t=0:0.01:length(Data_Seq)
Data_Seq2=[1,1,1,-1,-1,-1,1,-1]
stem(Data_Seq2)
A = Data_Seq2(1:2:end,:) %
B = Data_Seq2(2:2:end,:)
stem(A)
even = Data_Seq(2:2:end);
odd = Data_Seq(1:2:end);
stem(even)
// i Want to seperate even and odd signal but not undrstanding how to plotclear all
close all
Data_Seq=[1,1,1,0,0,0,1,0]
stem(Data_Seq)
bitrate= 1000000;
SR=1/bitrate;
ylim([-1 1])
t=0:0.01:length(Data_Seq)
Data_Seq2=[1,1,1,-1,-1,-1,1,-1]
stem(Data_Seq2)
A = Data_Seq2(1:2:end,:) %
B = Data_Seq2(2:2:end,:)
stem(A)
even = Data_Seq(2:2:end);
odd = Data_Seq(1:2:end);
stem(even)
// i Want to seperate even and odd signal but not undrstanding how to plot clear all
close all
Data_Seq=[1,1,1,0,0,0,1,0]
stem(Data_Seq)
bitrate= 1000000;
SR=1/bitrate;
ylim([-1 1])
t=0:0.01:length(Data_Seq)
Data_Seq2=[1,1,1,-1,-1,-1,1,-1]
stem(Data_Seq2)
A = Data_Seq2(1:2:end,:) %
B = Data_Seq2(2:2:end,:)
stem(A)
even = Data_Seq(2:2:end);
odd = Data_Seq(1:2:end);
stem(even)
// i Want to seperate even and odd signal but not undrstanding how to plot qpsk modulation MATLAB Answers — New Questions
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