Month: September 2024
SNR comparison real/complex signal
Hello,
I have a problem which should be simple but I can’t figure out the best solution.
I have a real signal, cos of frequency f + noise of N points :
signal = sqrt(2 * Ps) * cos(2 * pi * f *t);
noise = sqrt(Pn) * randn(1, N);
total = signal + noise;
I consider the SNR on the whole signal Ps/Pn that I also check using
(mean(abs(signal.^2)) – mean(abs(noise.^2))) / mean(abs(noise.^2))
I filter this signal using a simple FFT of nFFT points and consider an extraction in the signal canal. For instance, with f / fs = 1/4, I consider the nFFT / 4 + 1 canal. Plotting the signal spectrum, I ensure the signal is centered in the FFT canal. Then I compute :
The power in the canal : PsCanal = mean(abs(samplesCanalWithSignal.^2)).
The noise level in a random other canal : PnCanal = mean(abs(samplesCanalWithoutSignal.^2))
And compute SNR in the canal : SNRCanal = (PsCanal – PnCanal) / PnCanal.
Now I consider a complex signal. Same time, fe, etc… I only change signal and noise definition in order to have same global powers :
signal = sqrt(Ps) * exp(2i * pi * f *t)
noise = sqrt(Pn / 2) *(randn(1, N) + 1i * randn(1, N))
total = signal + noise
When I compute the global RSB, I have the exact same RSB than with real signal.
Then I compute the FFT (same nFFT points) and compute SNRCanal = (PsCanal – PnCanal) / PnCanal
Result is the following (compared to real signal test) :
Same PnCanal
PsCanal multiplied by 2
RSBCanal multiplied by 2
Where am I wrong ? I would like to be able to estimate the correct SNR in the FFT canal for real signals… I understand the PSD of the cos is half the one of exp due to positive and negative frequencies, but don’t understand why it is not the case for the noise PSD. Do I have to transform something ?
Thank youHello,
I have a problem which should be simple but I can’t figure out the best solution.
I have a real signal, cos of frequency f + noise of N points :
signal = sqrt(2 * Ps) * cos(2 * pi * f *t);
noise = sqrt(Pn) * randn(1, N);
total = signal + noise;
I consider the SNR on the whole signal Ps/Pn that I also check using
(mean(abs(signal.^2)) – mean(abs(noise.^2))) / mean(abs(noise.^2))
I filter this signal using a simple FFT of nFFT points and consider an extraction in the signal canal. For instance, with f / fs = 1/4, I consider the nFFT / 4 + 1 canal. Plotting the signal spectrum, I ensure the signal is centered in the FFT canal. Then I compute :
The power in the canal : PsCanal = mean(abs(samplesCanalWithSignal.^2)).
The noise level in a random other canal : PnCanal = mean(abs(samplesCanalWithoutSignal.^2))
And compute SNR in the canal : SNRCanal = (PsCanal – PnCanal) / PnCanal.
Now I consider a complex signal. Same time, fe, etc… I only change signal and noise definition in order to have same global powers :
signal = sqrt(Ps) * exp(2i * pi * f *t)
noise = sqrt(Pn / 2) *(randn(1, N) + 1i * randn(1, N))
total = signal + noise
When I compute the global RSB, I have the exact same RSB than with real signal.
Then I compute the FFT (same nFFT points) and compute SNRCanal = (PsCanal – PnCanal) / PnCanal
Result is the following (compared to real signal test) :
Same PnCanal
PsCanal multiplied by 2
RSBCanal multiplied by 2
Where am I wrong ? I would like to be able to estimate the correct SNR in the FFT canal for real signals… I understand the PSD of the cos is half the one of exp due to positive and negative frequencies, but don’t understand why it is not the case for the noise PSD. Do I have to transform something ?
Thank you Hello,
I have a problem which should be simple but I can’t figure out the best solution.
I have a real signal, cos of frequency f + noise of N points :
signal = sqrt(2 * Ps) * cos(2 * pi * f *t);
noise = sqrt(Pn) * randn(1, N);
total = signal + noise;
I consider the SNR on the whole signal Ps/Pn that I also check using
(mean(abs(signal.^2)) – mean(abs(noise.^2))) / mean(abs(noise.^2))
I filter this signal using a simple FFT of nFFT points and consider an extraction in the signal canal. For instance, with f / fs = 1/4, I consider the nFFT / 4 + 1 canal. Plotting the signal spectrum, I ensure the signal is centered in the FFT canal. Then I compute :
The power in the canal : PsCanal = mean(abs(samplesCanalWithSignal.^2)).
The noise level in a random other canal : PnCanal = mean(abs(samplesCanalWithoutSignal.^2))
And compute SNR in the canal : SNRCanal = (PsCanal – PnCanal) / PnCanal.
Now I consider a complex signal. Same time, fe, etc… I only change signal and noise definition in order to have same global powers :
signal = sqrt(Ps) * exp(2i * pi * f *t)
noise = sqrt(Pn / 2) *(randn(1, N) + 1i * randn(1, N))
total = signal + noise
When I compute the global RSB, I have the exact same RSB than with real signal.
Then I compute the FFT (same nFFT points) and compute SNRCanal = (PsCanal – PnCanal) / PnCanal
Result is the following (compared to real signal test) :
Same PnCanal
PsCanal multiplied by 2
RSBCanal multiplied by 2
Where am I wrong ? I would like to be able to estimate the correct SNR in the FFT canal for real signals… I understand the PSD of the cos is half the one of exp due to positive and negative frequencies, but don’t understand why it is not the case for the noise PSD. Do I have to transform something ?
Thank you snr MATLAB Answers — New Questions
How to get holidays and business days from non-US countries in Financial Toolbox?
How do I get holidays and business days from countries other than the United States in Financial Toolbox?
The ‘holidays’ function only returns US holidays.How do I get holidays and business days from countries other than the United States in Financial Toolbox?
The ‘holidays’ function only returns US holidays. How do I get holidays and business days from countries other than the United States in Financial Toolbox?
The ‘holidays’ function only returns US holidays. holiday, businessday, isbusday, business MATLAB Answers — New Questions
How to initialize the Hammerstein model linear block and avoiding that the nlhw function transform the linear block to polynomial form ?
Hi.
I am trying to estiamte a Hammerstein Model. I have a state representation of the linear block to generate the Hammerstein model, however for some reason the idnlhw function convert the state representation that I have to polynomial form. The above should not be a problem, but the poles of linear block are close together due to the slow dynamcis of my system. From what i read in this post https://la.mathworks.com/help/control/ug/sensitivity-of-multiple-roots.html closelied space poles are very sensitivy to model transformaiton from state space to polynomial represntation.
The above becomes problematic because I want to program this model in a 32-bit microncontroller but this pole sensitivy changes the value of my poles when I convert them to single precision.
How can I solve this issue.Hi.
I am trying to estiamte a Hammerstein Model. I have a state representation of the linear block to generate the Hammerstein model, however for some reason the idnlhw function convert the state representation that I have to polynomial form. The above should not be a problem, but the poles of linear block are close together due to the slow dynamcis of my system. From what i read in this post https://la.mathworks.com/help/control/ug/sensitivity-of-multiple-roots.html closelied space poles are very sensitivy to model transformaiton from state space to polynomial represntation.
The above becomes problematic because I want to program this model in a 32-bit microncontroller but this pole sensitivy changes the value of my poles when I convert them to single precision.
How can I solve this issue. Hi.
I am trying to estiamte a Hammerstein Model. I have a state representation of the linear block to generate the Hammerstein model, however for some reason the idnlhw function convert the state representation that I have to polynomial form. The above should not be a problem, but the poles of linear block are close together due to the slow dynamcis of my system. From what i read in this post https://la.mathworks.com/help/control/ug/sensitivity-of-multiple-roots.html closelied space poles are very sensitivy to model transformaiton from state space to polynomial represntation.
The above becomes problematic because I want to program this model in a 32-bit microncontroller but this pole sensitivy changes the value of my poles when I convert them to single precision.
How can I solve this issue. hammerstein model, system identification MATLAB Answers — New Questions
How can I live-stream and visualize signals from my Speedgoat target computer running a real-time application?
What are the different methods to live-stream and visualize signals from Speedgoat hardware running a real-time application, and how can each method be configured?What are the different methods to live-stream and visualize signals from Speedgoat hardware running a real-time application, and how can each method be configured? What are the different methods to live-stream and visualize signals from Speedgoat hardware running a real-time application, and how can each method be configured? real-time, signal, streaming, tracing MATLAB Answers — New Questions
New MAC user with Excel app question.
I am new to MAC and going back to school using an online platform. The institution provides access to Office 365 and all apps on its website. I can open them, but when I open spreadsheets they come up with blue triangles in the data areas. To open the Excel sheet properly, I figured out I could open the Excel App (from the institution page) in a separate window and drag the assignment spreadsheet linked to my course content into the app. This opens it and lets me edit as I need. The next part of the assignment is to Copy the Excel graph and then Paste Special as a Microsoft Excel Object into the Word document. This is where I am stuck. I do not have the Paste Special option and everything I have tried to paste does not work out.
I am new to MAC and going back to school using an online platform. The institution provides access to Office 365 and all apps on its website. I can open them, but when I open spreadsheets they come up with blue triangles in the data areas. To open the Excel sheet properly, I figured out I could open the Excel App (from the institution page) in a separate window and drag the assignment spreadsheet linked to my course content into the app. This opens it and lets me edit as I need. The next part of the assignment is to Copy the Excel graph and then Paste Special as a Microsoft Excel Object into the Word document. This is where I am stuck. I do not have the Paste Special option and everything I have tried to paste does not work out. Read More
Latest Canary Win 11 versions and Star Wars Outlaws.
On my two computers with the latest versions of Canary, the game Star Wars Outlaws recently released by Ubisoft crashes. The game crashes after even several dozen seconds without any error message. Interestingly, many other people are complaining about the same problem in Canary Insider, and the error itself does not appear on the 23h2 version, but unfortunately causes problems on 24h2.
On my two computers with the latest versions of Canary, the game Star Wars Outlaws recently released by Ubisoft crashes. The game crashes after even several dozen seconds without any error message. Interestingly, many other people are complaining about the same problem in Canary Insider, and the error itself does not appear on the 23h2 version, but unfortunately causes problems on 24h2. Read More
Microsoft 365 Personal vs. Microsoft 365 Business
Is there a forum/community/hub for 365 Personal?
I am trying to find knucklehead that developed the auto-create Skype account feature for kids accounts on 365 Family.
Is there a forum/community/hub for 365 Personal? I am trying to find knucklehead that developed the auto-create Skype account feature for kids accounts on 365 Family. Read More
What system of ODE’s does Simscape Electrical’s DC Motor Block use?
I’ve been having trouble getting the DC Motor block’s results for current and rotational velocity to match what I obtain when using coupled differential equations in an ODE45 script. The results are very far apart and I’m not sure what is causing this.
The systems of equations I’ve implemented in ODE45 is standard in the DC motor literature, and is as follows:
Where is the current (), is the armature inductance (), is the armature resistance (), is the motor electrical constant (), is the voltage of the constant voltage source (), is the armature’s mass moment of inertia (), is the motor’s torque constant (), and is the motor damping ().
However, I’ve noticed that in the DC Motor block documentation, the equation for torque across the motor is given as (where is the damping constant). When I add the first term into my differential equation model, the results of ODE45 and Simscape Electrical become very close. I assume that this is the set of equations that Simscape is using, but I don’t like to use equations without understanding them. Where does this added term come from? I don’t believe I’ve seen it in the literature.
I’ve attached plots showing current and rotational velocity of the motor for the three models, so that you can see the discrepancies. (Note that there is zero damping in any of the models, yet only the classical differential equation model shows a rising angular velocity — the other models eventually reach some steady-state non-zero angular velocity.)
Any insight into what is happening here would be appreciated.I’ve been having trouble getting the DC Motor block’s results for current and rotational velocity to match what I obtain when using coupled differential equations in an ODE45 script. The results are very far apart and I’m not sure what is causing this.
The systems of equations I’ve implemented in ODE45 is standard in the DC motor literature, and is as follows:
Where is the current (), is the armature inductance (), is the armature resistance (), is the motor electrical constant (), is the voltage of the constant voltage source (), is the armature’s mass moment of inertia (), is the motor’s torque constant (), and is the motor damping ().
However, I’ve noticed that in the DC Motor block documentation, the equation for torque across the motor is given as (where is the damping constant). When I add the first term into my differential equation model, the results of ODE45 and Simscape Electrical become very close. I assume that this is the set of equations that Simscape is using, but I don’t like to use equations without understanding them. Where does this added term come from? I don’t believe I’ve seen it in the literature.
I’ve attached plots showing current and rotational velocity of the motor for the three models, so that you can see the discrepancies. (Note that there is zero damping in any of the models, yet only the classical differential equation model shows a rising angular velocity — the other models eventually reach some steady-state non-zero angular velocity.)
Any insight into what is happening here would be appreciated. I’ve been having trouble getting the DC Motor block’s results for current and rotational velocity to match what I obtain when using coupled differential equations in an ODE45 script. The results are very far apart and I’m not sure what is causing this.
The systems of equations I’ve implemented in ODE45 is standard in the DC motor literature, and is as follows:
Where is the current (), is the armature inductance (), is the armature resistance (), is the motor electrical constant (), is the voltage of the constant voltage source (), is the armature’s mass moment of inertia (), is the motor’s torque constant (), and is the motor damping ().
However, I’ve noticed that in the DC Motor block documentation, the equation for torque across the motor is given as (where is the damping constant). When I add the first term into my differential equation model, the results of ODE45 and Simscape Electrical become very close. I assume that this is the set of equations that Simscape is using, but I don’t like to use equations without understanding them. Where does this added term come from? I don’t believe I’ve seen it in the literature.
I’ve attached plots showing current and rotational velocity of the motor for the three models, so that you can see the discrepancies. (Note that there is zero damping in any of the models, yet only the classical differential equation model shows a rising angular velocity — the other models eventually reach some steady-state non-zero angular velocity.)
Any insight into what is happening here would be appreciated. simscape, differential equations MATLAB Answers — New Questions
N-dimension curve fit how to
Can someone please walk me through how to do a polynomial curve fit to n-dimensional data? For example: I have a 3D matrix t = [i x j x k] of results for all combinations of 3 different variables x = [i x 1], y = [j x 1], and z = [k x 1], and we know it follows a polynomial fit (e.g. x = 4th order, y = 2nd order, and z = 2nd order). How do I set up the problem, define the fit equation, and find the fit parameters?Can someone please walk me through how to do a polynomial curve fit to n-dimensional data? For example: I have a 3D matrix t = [i x j x k] of results for all combinations of 3 different variables x = [i x 1], y = [j x 1], and z = [k x 1], and we know it follows a polynomial fit (e.g. x = 4th order, y = 2nd order, and z = 2nd order). How do I set up the problem, define the fit equation, and find the fit parameters? Can someone please walk me through how to do a polynomial curve fit to n-dimensional data? For example: I have a 3D matrix t = [i x j x k] of results for all combinations of 3 different variables x = [i x 1], y = [j x 1], and z = [k x 1], and we know it follows a polynomial fit (e.g. x = 4th order, y = 2nd order, and z = 2nd order). How do I set up the problem, define the fit equation, and find the fit parameters? regression, curve fitting, polyfit MATLAB Answers — New Questions
Error trying to link Matlab and Aspen Plus
I have error message while trying to link Matlab with my Aspen Plus simulation:
>> CHLC
Error using COM.Apwn_Document_37_0/invoke
Invoke Error, Dispatch Exception:
Source: Aspen Plus 37.0 OLE Services
Description: Unable to open file.
Error in CHLC (line 8)
Aspen.invoke(‘InitFromFile’,[mess.Name ” Simulation_Name ‘.apwz’]);
This is the code im using:
%% Linking
Aspen = actxserver(‘Apwn.Document.37.0’);
[stat,mess]=fileattrib; % get attributes of folder (Necessary to establish the location of the simulation)
Simulation_Name = ‘CL_SCO2’;% Aspeen Plus Simulation Name
Aspen.invoke(‘InitFromArchive2’,[mess.Name ” Simulation_Name ‘.bkp’]);
Aspen.Visible = 1; % 1 —> Aspen is Visible; 0 —> Aspen is open but not visible
Aspen.SuppressDialogs = 1; % Suppress windows dialogs.
Aspen.Engine.Run2(1); % Run the simulation
while Aspen.Engine.IsRunning == 1 % 1 –> If Aspen is running; 0 —> If Aspen stop.
pause(0.5);
end
Matlab version is R2022a (9.12.0.1884302) 64-bit and Aspen plus V11 (37.0.0395)
Already try saving Aspen simulation as .bkp and .apwz.
Yes, two files ( .m matlab code and .awpz / .bkp simulation) are in the same folder.I have error message while trying to link Matlab with my Aspen Plus simulation:
>> CHLC
Error using COM.Apwn_Document_37_0/invoke
Invoke Error, Dispatch Exception:
Source: Aspen Plus 37.0 OLE Services
Description: Unable to open file.
Error in CHLC (line 8)
Aspen.invoke(‘InitFromFile’,[mess.Name ” Simulation_Name ‘.apwz’]);
This is the code im using:
%% Linking
Aspen = actxserver(‘Apwn.Document.37.0’);
[stat,mess]=fileattrib; % get attributes of folder (Necessary to establish the location of the simulation)
Simulation_Name = ‘CL_SCO2’;% Aspeen Plus Simulation Name
Aspen.invoke(‘InitFromArchive2’,[mess.Name ” Simulation_Name ‘.bkp’]);
Aspen.Visible = 1; % 1 —> Aspen is Visible; 0 —> Aspen is open but not visible
Aspen.SuppressDialogs = 1; % Suppress windows dialogs.
Aspen.Engine.Run2(1); % Run the simulation
while Aspen.Engine.IsRunning == 1 % 1 –> If Aspen is running; 0 —> If Aspen stop.
pause(0.5);
end
Matlab version is R2022a (9.12.0.1884302) 64-bit and Aspen plus V11 (37.0.0395)
Already try saving Aspen simulation as .bkp and .apwz.
Yes, two files ( .m matlab code and .awpz / .bkp simulation) are in the same folder. I have error message while trying to link Matlab with my Aspen Plus simulation:
>> CHLC
Error using COM.Apwn_Document_37_0/invoke
Invoke Error, Dispatch Exception:
Source: Aspen Plus 37.0 OLE Services
Description: Unable to open file.
Error in CHLC (line 8)
Aspen.invoke(‘InitFromFile’,[mess.Name ” Simulation_Name ‘.apwz’]);
This is the code im using:
%% Linking
Aspen = actxserver(‘Apwn.Document.37.0’);
[stat,mess]=fileattrib; % get attributes of folder (Necessary to establish the location of the simulation)
Simulation_Name = ‘CL_SCO2’;% Aspeen Plus Simulation Name
Aspen.invoke(‘InitFromArchive2’,[mess.Name ” Simulation_Name ‘.bkp’]);
Aspen.Visible = 1; % 1 —> Aspen is Visible; 0 —> Aspen is open but not visible
Aspen.SuppressDialogs = 1; % Suppress windows dialogs.
Aspen.Engine.Run2(1); % Run the simulation
while Aspen.Engine.IsRunning == 1 % 1 –> If Aspen is running; 0 —> If Aspen stop.
pause(0.5);
end
Matlab version is R2022a (9.12.0.1884302) 64-bit and Aspen plus V11 (37.0.0395)
Already try saving Aspen simulation as .bkp and .apwz.
Yes, two files ( .m matlab code and .awpz / .bkp simulation) are in the same folder. aspen puls, matlab, link, error MATLAB Answers — New Questions
What is the best method to model or utilize the built-in model for a three-phase voltage regulator in MATLAB Simulink, specifically for the IEEE 34 distribution network?
What is the best method to model or use the built-in model for a three-phase voltage regulator in MATLAB Simulink, specifically for the IEEE 34 distribution network, in a way that works properly with load flow analysis from the Powergui?What is the best method to model or use the built-in model for a three-phase voltage regulator in MATLAB Simulink, specifically for the IEEE 34 distribution network, in a way that works properly with load flow analysis from the Powergui? What is the best method to model or use the built-in model for a three-phase voltage regulator in MATLAB Simulink, specifically for the IEEE 34 distribution network, in a way that works properly with load flow analysis from the Powergui? matlab, simulink, voltage regulator, ieee 34, load MATLAB Answers — New Questions
Email disappears a few seconds after arriving.
I started noticing my email was starting to showing less of my important emails, I have checked all folders and it is just gone. I have seen them pop up and when I go to click on them they are gone before I can try. One time I was responding to an email and it just Disappeared in the middle of me typing. I can use the search menu to find the mail, but that is only if I know the mail I am looking for, when the email is deleted before I see it i can’t search for it. I have changed nothing on the settings and I have contacted support several times and had they were unable to help. I really need these emails so any help would be appreciated. Thank you for your time.
I started noticing my email was starting to showing less of my important emails, I have checked all folders and it is just gone. I have seen them pop up and when I go to click on them they are gone before I can try. One time I was responding to an email and it just Disappeared in the middle of me typing. I can use the search menu to find the mail, but that is only if I know the mail I am looking for, when the email is deleted before I see it i can’t search for it. I have changed nothing on the settings and I have contacted support several times and had they were unable to help. I really need these emails so any help would be appreciated. Thank you for your time. Read More
how can i draw contourf plot
I’m going to make a plot like this picture.
I interpolated the data using the interp1 function. However, contourf can only contain values of 2*2 or more, so the function cannot be executed. How do I solve this?I’m going to make a plot like this picture.
I interpolated the data using the interp1 function. However, contourf can only contain values of 2*2 or more, so the function cannot be executed. How do I solve this? I’m going to make a plot like this picture.
I interpolated the data using the interp1 function. However, contourf can only contain values of 2*2 or more, so the function cannot be executed. How do I solve this? #argo, #interp1, #ocean, #pressure, #temperature, #salinty, #contourf MATLAB Answers — New Questions
how do i model power increment (+udeg, -udeg) limits using matlab function?
how do i model power increment (+udeg, -udeg) limits using matlab function?(sign function)
i am working on power system having constraints.
Thanks in advancehow do i model power increment (+udeg, -udeg) limits using matlab function?(sign function)
i am working on power system having constraints.
Thanks in advance how do i model power increment (+udeg, -udeg) limits using matlab function?(sign function)
i am working on power system having constraints.
Thanks in advance sign function MATLAB Answers — New Questions
how to search in table?
Hi! I want to create a simply calculator for my work.
How do I make a program that will check the protein and urea levels entered by the user and then display recommendations in the “TIP:” field?
Help me! 😭
Hi! I want to create a simply calculator for my work.How do I make a program that will check the protein and urea levels entered by the user and then display recommendations in the “TIP:” field?Help me! 😭 Read More
How to Dynamically Control Debug.Print in MS Access VBA for Optimized Performance
Hello Microsoft Community,
I’m Sasha Froyland, and I run an MS Access consultancy where we focus on optimizing performance while maintaining flexibility in debugging. I’ve recently developed a strategy for dynamically controlling Debug.Print to gain up to a 30% performance boost, which we use in our projects. What follows is this performance best practice that has helped us improve efficiency.
Would a post like this be of interest to the community? If this isn’t the appropriate place for such content, please accept my apologies in advance. My only goal is to facilitate communication and knowledge-sharing of best practices across the Access development space.
Looking forward to hearing your thoughts!
Below, please find the details of the best practice:
At Help4Access, we know how important it is to balance performance with debugging. MS Access developers rely on Debug.Print to track their code, but excessive use can slow your application—sometimes by as much as 30%. To solve this, we’ve designed a dynamic method to enable or disable Debug.Print, giving you a performance boost without sacrificing debugging flexibility.
Step 1: Global Variable for Control
Start by adding a global variable:
This will allow you to toggle Debug.Print on and off globally in your app.
Step 2: Configuration Table
Create a system configuration table, tblSystemConfig, with a field DebugEnabled (Yes/No). This table will store the setting for whether Debug.Print is active.
Step 3: Initialize on Startup
At the start of your application, pull the DebugEnabled value into the global variable:
Step 4: Conditional Debug.Print
Wherever you use Debug.Print, wrap it in a conditional statement:
Step 5: Real-Time Debugging Control
You can toggle the DebugEnabled flag in your config table to turn debugging on or off, and then refresh gDebugEnabled—no need to restart the application. This gives you up to a 30% performance boost during production while retaining the ability to debug when necessary.
By following this approach, you get both better debugging and improved performance. At Help4Access, we implement strategies like this to ensure that your Access applications run faster and more efficiently.
Hello Microsoft Community, I’m Sasha Froyland, and I run an MS Access consultancy where we focus on optimizing performance while maintaining flexibility in debugging. I’ve recently developed a strategy for dynamically controlling Debug.Print to gain up to a 30% performance boost, which we use in our projects. What follows is this performance best practice that has helped us improve efficiency. Would a post like this be of interest to the community? If this isn’t the appropriate place for such content, please accept my apologies in advance. My only goal is to facilitate communication and knowledge-sharing of best practices across the Access development space. Looking forward to hearing your thoughts! Below, please find the details of the best practice: At Help4Access, we know how important it is to balance performance with debugging. MS Access developers rely on Debug.Print to track their code, but excessive use can slow your application—sometimes by as much as 30%. To solve this, we’ve designed a dynamic method to enable or disable Debug.Print, giving you a performance boost without sacrificing debugging flexibility.Step 1: Global Variable for ControlStart by adding a global variable: vbaCopy codePublic gDebugEnabled As Boolean This will allow you to toggle Debug.Print on and off globally in your app.Step 2: Configuration TableCreate a system configuration table, tblSystemConfig, with a field DebugEnabled (Yes/No). This table will store the setting for whether Debug.Print is active.Step 3: Initialize on StartupAt the start of your application, pull the DebugEnabled value into the global variable: vbaCopy codegDebugEnabled = DLookup(“DebugEnabled”, “tblSystemConfig”) Step 4: Conditional Debug.PrintWherever you use Debug.Print, wrap it in a conditional statement: vbaCopy codeIf gDebugEnabled Then Debug.Print “Your debug message” Step 5: Real-Time Debugging ControlYou can toggle the DebugEnabled flag in your config table to turn debugging on or off, and then refresh gDebugEnabled—no need to restart the application. This gives you up to a 30% performance boost during production while retaining the ability to debug when necessary.By following this approach, you get both better debugging and improved performance. At Help4Access, we implement strategies like this to ensure that your Access applications run faster and more efficiently. Read More
OneDrive Photos on iPad does not detect or upload iPad Screen recordings
OneDrive Photos on iPad does not detect or upload iPad Screen recordings saved in iPadOS Photos App.
However it detects and uploads all other type of videos and screen recordings from iPhones.
Anyone else?
OneDrive Photos on iPad does not detect or upload iPad Screen recordings saved in iPadOS Photos App.However it detects and uploads all other type of videos and screen recordings from iPhones.Anyone else? Read More
Assistance with Load Flow Analysis in IEEE 34 Distribution Network on MATLAB-Simulink
Hello,
I am working with the IEEE 34-bus distribution network in MATLAB-Simulink. When running the load flow analysis after setting up the buses, I encountered the following error message:
"Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.218374e-17."
Given that this is an unbalanced system, could you please advise on the potential causes of this issue?How to solve it? Additionally, are there alternative methods or tools within MATLAB-Simulink to handle load flow analysis for such systems?
Thank you for your assistance.
Best regards,Hello,
I am working with the IEEE 34-bus distribution network in MATLAB-Simulink. When running the load flow analysis after setting up the buses, I encountered the following error message:
"Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.218374e-17."
Given that this is an unbalanced system, could you please advise on the potential causes of this issue?How to solve it? Additionally, are there alternative methods or tools within MATLAB-Simulink to handle load flow analysis for such systems?
Thank you for your assistance.
Best regards, Hello,
I am working with the IEEE 34-bus distribution network in MATLAB-Simulink. When running the load flow analysis after setting up the buses, I encountered the following error message:
"Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.218374e-17."
Given that this is an unbalanced system, could you please advise on the potential causes of this issue?How to solve it? Additionally, are there alternative methods or tools within MATLAB-Simulink to handle load flow analysis for such systems?
Thank you for your assistance.
Best regards, ieee 34, load flow, matlab, simulink, unbalanced s MATLAB Answers — New Questions
Can I communicate through Modbus protocol from MATLAB/Simulink?
I want to know if MathWorks offers any products that I can use to communicate through Modbus® protocol.I want to know if MathWorks offers any products that I can use to communicate through Modbus® protocol. I want to know if MathWorks offers any products that I can use to communicate through Modbus® protocol. MATLAB Answers — New Questions
How to speed up vectorized operations for dynamic programming
I would like to speed up the following code which solves a discrete dynamic programming problem using the method of successive approximations, as described e.g. in Bertsekas.
The algorithm is made of two steps. In step 1, I precompute the payoff array R(a’,a,z) where a’ is the action and (a,z) are the states. In step 2 I compute the value function using the method of successive approximations: I guess V0, then I compute an updated V1 and finally I check if ||V1-V0|| is less than a tolerance level. If it is, I stop, otherwise I set V0=V1 and go on.
I profiled the code (see below a MWE) and the two most time-consuming lines are the following ones:
(1) RHS = Ret+beta*permute(EV,[1,3,2]);
(2) [max_val,max_ind] = max(RHS,[],1);
Line (1) takes up 63% of the total running time, line (2) takes 32%. As you can see I have already vectorized all loops.
I would be very grateful for any suggestion. I post below a MWE.
%% Solve income fluctuation problem CPU
clear;clc;close all
%% Economic parameters
sigma = 2;
r = 0.03;
beta = 0.96;
PZ = [0.60 0.40;
0.05 0.95];
z_grid = [0.5 1.0]’;
n_z = length(z_grid);
b = 0; %lower bound for asset holdings a
grid_max = 4;
n_a = 500; % IN PRACTICE THIS IS EQUAL TO 5000-10000
R = 1+r;
a_grid = linspace(-b,grid_max,n_a)’;
if sigma==1
fun_u = @(c) log(c);
else
fun_u = @(c) c.^(1-sigma)/(1-sigma);
end
%% Computational parameters
verbose = 0;
tiny = 1e-8; %very small positive number
tol = 1e-6; %tolerance for VFI and TI
max_iter = 500; %maximum num. of iterations for both VFI and TI
%% Start timing
tic
%% STEP 1- Precompute current payoff array R(a’,a,z)
a_tomorrow = a_grid; %(a’,1,1)
a_today = a_grid’; %(1,a,1)
z_today = shiftdim(z_grid,-2); %(1,1,z)
cons = (1+r)*a_today+z_today-a_tomorrow;
Ret = fun_u(cons); %size: [n_a,n_a,n_z]
Ret(cons<=0) = -inf;
%% STEP 2 – Value function iteration
iter = 1;
err = tol+1;
V0 = zeros(n_a,n_z);
while err>tol && iter<=max_iter
EV = V0*PZ’; %(a’,z)
RHS = Ret+beta*permute(EV,[1,3,2]);
[max_val,max_ind] = max(RHS,[],1);
V1 = squeeze(max_val);
pol_ind_ap = squeeze(max_ind);
err = max(abs(V0(:)-V1(:)));
if verbose==1
fprintf(‘iter = %d, err = %f n’,iter,err)
end
iter = iter+1;
V0 = V1;
end
if err>tol
error(‘VFI did not converge!’)
else
fprintf(‘VFI converged after = %d iterations n’,iter)
end
pol_ap = a_grid(pol_ind_ap);
pol_c = (1+r)*a_grid+z_grid’-pol_ap;
%% End timing
toc
%% Figures
figure
plot(a_grid,pol_c(:,1),’linewidth’,2)
hold on
plot(a_grid,pol_c(:,2),’linewidth’,2)
legend(‘Low shock’,’High shock’,’Location’,’NorthWest’)
xlabel(‘asset level’)
ylabel(‘consumption’)
title(‘Consumption Policy Function’)
figure
plot(a_grid,a_grid,’–‘,’linewidth’,2)
hold on
plot(a_grid,pol_ap(:,1),’linewidth’,2)
hold on
plot(a_grid,pol_ap(:,2),’linewidth’,2)
legend(’45 line’,’Low shock’,’High shock’,’Location’,’NorthWest’)
xlabel(‘Current period assets’)
ylabel(‘Next-period assets’)
title(‘Assets Policy Function’)I would like to speed up the following code which solves a discrete dynamic programming problem using the method of successive approximations, as described e.g. in Bertsekas.
The algorithm is made of two steps. In step 1, I precompute the payoff array R(a’,a,z) where a’ is the action and (a,z) are the states. In step 2 I compute the value function using the method of successive approximations: I guess V0, then I compute an updated V1 and finally I check if ||V1-V0|| is less than a tolerance level. If it is, I stop, otherwise I set V0=V1 and go on.
I profiled the code (see below a MWE) and the two most time-consuming lines are the following ones:
(1) RHS = Ret+beta*permute(EV,[1,3,2]);
(2) [max_val,max_ind] = max(RHS,[],1);
Line (1) takes up 63% of the total running time, line (2) takes 32%. As you can see I have already vectorized all loops.
I would be very grateful for any suggestion. I post below a MWE.
%% Solve income fluctuation problem CPU
clear;clc;close all
%% Economic parameters
sigma = 2;
r = 0.03;
beta = 0.96;
PZ = [0.60 0.40;
0.05 0.95];
z_grid = [0.5 1.0]’;
n_z = length(z_grid);
b = 0; %lower bound for asset holdings a
grid_max = 4;
n_a = 500; % IN PRACTICE THIS IS EQUAL TO 5000-10000
R = 1+r;
a_grid = linspace(-b,grid_max,n_a)’;
if sigma==1
fun_u = @(c) log(c);
else
fun_u = @(c) c.^(1-sigma)/(1-sigma);
end
%% Computational parameters
verbose = 0;
tiny = 1e-8; %very small positive number
tol = 1e-6; %tolerance for VFI and TI
max_iter = 500; %maximum num. of iterations for both VFI and TI
%% Start timing
tic
%% STEP 1- Precompute current payoff array R(a’,a,z)
a_tomorrow = a_grid; %(a’,1,1)
a_today = a_grid’; %(1,a,1)
z_today = shiftdim(z_grid,-2); %(1,1,z)
cons = (1+r)*a_today+z_today-a_tomorrow;
Ret = fun_u(cons); %size: [n_a,n_a,n_z]
Ret(cons<=0) = -inf;
%% STEP 2 – Value function iteration
iter = 1;
err = tol+1;
V0 = zeros(n_a,n_z);
while err>tol && iter<=max_iter
EV = V0*PZ’; %(a’,z)
RHS = Ret+beta*permute(EV,[1,3,2]);
[max_val,max_ind] = max(RHS,[],1);
V1 = squeeze(max_val);
pol_ind_ap = squeeze(max_ind);
err = max(abs(V0(:)-V1(:)));
if verbose==1
fprintf(‘iter = %d, err = %f n’,iter,err)
end
iter = iter+1;
V0 = V1;
end
if err>tol
error(‘VFI did not converge!’)
else
fprintf(‘VFI converged after = %d iterations n’,iter)
end
pol_ap = a_grid(pol_ind_ap);
pol_c = (1+r)*a_grid+z_grid’-pol_ap;
%% End timing
toc
%% Figures
figure
plot(a_grid,pol_c(:,1),’linewidth’,2)
hold on
plot(a_grid,pol_c(:,2),’linewidth’,2)
legend(‘Low shock’,’High shock’,’Location’,’NorthWest’)
xlabel(‘asset level’)
ylabel(‘consumption’)
title(‘Consumption Policy Function’)
figure
plot(a_grid,a_grid,’–‘,’linewidth’,2)
hold on
plot(a_grid,pol_ap(:,1),’linewidth’,2)
hold on
plot(a_grid,pol_ap(:,2),’linewidth’,2)
legend(’45 line’,’Low shock’,’High shock’,’Location’,’NorthWest’)
xlabel(‘Current period assets’)
ylabel(‘Next-period assets’)
title(‘Assets Policy Function’) I would like to speed up the following code which solves a discrete dynamic programming problem using the method of successive approximations, as described e.g. in Bertsekas.
The algorithm is made of two steps. In step 1, I precompute the payoff array R(a’,a,z) where a’ is the action and (a,z) are the states. In step 2 I compute the value function using the method of successive approximations: I guess V0, then I compute an updated V1 and finally I check if ||V1-V0|| is less than a tolerance level. If it is, I stop, otherwise I set V0=V1 and go on.
I profiled the code (see below a MWE) and the two most time-consuming lines are the following ones:
(1) RHS = Ret+beta*permute(EV,[1,3,2]);
(2) [max_val,max_ind] = max(RHS,[],1);
Line (1) takes up 63% of the total running time, line (2) takes 32%. As you can see I have already vectorized all loops.
I would be very grateful for any suggestion. I post below a MWE.
%% Solve income fluctuation problem CPU
clear;clc;close all
%% Economic parameters
sigma = 2;
r = 0.03;
beta = 0.96;
PZ = [0.60 0.40;
0.05 0.95];
z_grid = [0.5 1.0]’;
n_z = length(z_grid);
b = 0; %lower bound for asset holdings a
grid_max = 4;
n_a = 500; % IN PRACTICE THIS IS EQUAL TO 5000-10000
R = 1+r;
a_grid = linspace(-b,grid_max,n_a)’;
if sigma==1
fun_u = @(c) log(c);
else
fun_u = @(c) c.^(1-sigma)/(1-sigma);
end
%% Computational parameters
verbose = 0;
tiny = 1e-8; %very small positive number
tol = 1e-6; %tolerance for VFI and TI
max_iter = 500; %maximum num. of iterations for both VFI and TI
%% Start timing
tic
%% STEP 1- Precompute current payoff array R(a’,a,z)
a_tomorrow = a_grid; %(a’,1,1)
a_today = a_grid’; %(1,a,1)
z_today = shiftdim(z_grid,-2); %(1,1,z)
cons = (1+r)*a_today+z_today-a_tomorrow;
Ret = fun_u(cons); %size: [n_a,n_a,n_z]
Ret(cons<=0) = -inf;
%% STEP 2 – Value function iteration
iter = 1;
err = tol+1;
V0 = zeros(n_a,n_z);
while err>tol && iter<=max_iter
EV = V0*PZ’; %(a’,z)
RHS = Ret+beta*permute(EV,[1,3,2]);
[max_val,max_ind] = max(RHS,[],1);
V1 = squeeze(max_val);
pol_ind_ap = squeeze(max_ind);
err = max(abs(V0(:)-V1(:)));
if verbose==1
fprintf(‘iter = %d, err = %f n’,iter,err)
end
iter = iter+1;
V0 = V1;
end
if err>tol
error(‘VFI did not converge!’)
else
fprintf(‘VFI converged after = %d iterations n’,iter)
end
pol_ap = a_grid(pol_ind_ap);
pol_c = (1+r)*a_grid+z_grid’-pol_ap;
%% End timing
toc
%% Figures
figure
plot(a_grid,pol_c(:,1),’linewidth’,2)
hold on
plot(a_grid,pol_c(:,2),’linewidth’,2)
legend(‘Low shock’,’High shock’,’Location’,’NorthWest’)
xlabel(‘asset level’)
ylabel(‘consumption’)
title(‘Consumption Policy Function’)
figure
plot(a_grid,a_grid,’–‘,’linewidth’,2)
hold on
plot(a_grid,pol_ap(:,1),’linewidth’,2)
hold on
plot(a_grid,pol_ap(:,2),’linewidth’,2)
legend(’45 line’,’Low shock’,’High shock’,’Location’,’NorthWest’)
xlabel(‘Current period assets’)
ylabel(‘Next-period assets’)
title(‘Assets Policy Function’) vectorized, performance MATLAB Answers — New Questions