Month: March 2025
Model Info in Matlab 2023b Simulink does not start displaying from top
Jumped from Matlab 2019b to 2023b and now the model info block doesnt work as expected
See screenshot below
The first row says
"This row should be at the top"
And we expect that it is what you see in the preview box in yellow.Jumped from Matlab 2019b to 2023b and now the model info block doesnt work as expected
See screenshot below
The first row says
"This row should be at the top"
And we expect that it is what you see in the preview box in yellow. Jumped from Matlab 2019b to 2023b and now the model info block doesnt work as expected
See screenshot below
The first row says
"This row should be at the top"
And we expect that it is what you see in the preview box in yellow. model-info MATLAB Answers — New Questions
Is Renesas microcontroller RH850/F1KM-S1, 32 bit board, compatible with MATLAB 2022b?
Is Is Renesas microcontroller RH850/F1KM-S1, 32 bit board, compatible with MATLAB 2022b to perform battery management system implementation.Is Is Renesas microcontroller RH850/F1KM-S1, 32 bit board, compatible with MATLAB 2022b to perform battery management system implementation. Is Is Renesas microcontroller RH850/F1KM-S1, 32 bit board, compatible with MATLAB 2022b to perform battery management system implementation. 32 bit b, rh850/f1km-s1, matlab 2022b MATLAB Answers — New Questions
Hello, after logging into your account I get an error: Oops! This page is currently unavailable. Error Code: MHOD-4XX And she’s been out for over a week now, what should I do?
Hello, after logging into my Matlab Online account I get an error like: Oops! This page is currently unavailable.
We’re sorry, but you can’t access this page at the moment.
This might be due to:
The requested resource is unavailable
An incorrect URL was entered
Insufficient privileges
Content protection measures
Account restrictions
Here are some things you can try:
Make sure the web address is entered correctly.
Go to MATLAB Online and try again.
Clear your browser’s cache and cookies, then reload the page.
Try accessing the page using a different browser or device.
If you’re using a VPN or proxy, try disabling it and accessing the page directly.
Check if your internet connection is stable and working properly.
If you’ve tried these steps and are still experiencing issues, please don’t hesitate to contact MathWorks Support for further assistance.
Error Code: MHOD-4XX
And it’s been like this for more than a week. Please tell me what to do?Hello, after logging into my Matlab Online account I get an error like: Oops! This page is currently unavailable.
We’re sorry, but you can’t access this page at the moment.
This might be due to:
The requested resource is unavailable
An incorrect URL was entered
Insufficient privileges
Content protection measures
Account restrictions
Here are some things you can try:
Make sure the web address is entered correctly.
Go to MATLAB Online and try again.
Clear your browser’s cache and cookies, then reload the page.
Try accessing the page using a different browser or device.
If you’re using a VPN or proxy, try disabling it and accessing the page directly.
Check if your internet connection is stable and working properly.
If you’ve tried these steps and are still experiencing issues, please don’t hesitate to contact MathWorks Support for further assistance.
Error Code: MHOD-4XX
And it’s been like this for more than a week. Please tell me what to do? Hello, after logging into my Matlab Online account I get an error like: Oops! This page is currently unavailable.
We’re sorry, but you can’t access this page at the moment.
This might be due to:
The requested resource is unavailable
An incorrect URL was entered
Insufficient privileges
Content protection measures
Account restrictions
Here are some things you can try:
Make sure the web address is entered correctly.
Go to MATLAB Online and try again.
Clear your browser’s cache and cookies, then reload the page.
Try accessing the page using a different browser or device.
If you’re using a VPN or proxy, try disabling it and accessing the page directly.
Check if your internet connection is stable and working properly.
If you’ve tried these steps and are still experiencing issues, please don’t hesitate to contact MathWorks Support for further assistance.
Error Code: MHOD-4XX
And it’s been like this for more than a week. Please tell me what to do? matlab MATLAB Answers — New Questions
How i can graph in 3 dimension, dependent of the temperature?
Good day for everyone, i have a simple question. I have matlab R2019a. My question is..
How i can graph this equation:
T = – 3 (x^2+y^2+z^2)^(1/2) + 300
is a room that is dependent of temperature in all directions
I tried this, but doesn’t appear the graph
syms x y z
T0 = 300
f = -3*sqrt((x^2+y^2+z^2))+ T0;
fimplicit3(f, [0 0 0])
Thank you so much for your valious time.Good day for everyone, i have a simple question. I have matlab R2019a. My question is..
How i can graph this equation:
T = – 3 (x^2+y^2+z^2)^(1/2) + 300
is a room that is dependent of temperature in all directions
I tried this, but doesn’t appear the graph
syms x y z
T0 = 300
f = -3*sqrt((x^2+y^2+z^2))+ T0;
fimplicit3(f, [0 0 0])
Thank you so much for your valious time. Good day for everyone, i have a simple question. I have matlab R2019a. My question is..
How i can graph this equation:
T = – 3 (x^2+y^2+z^2)^(1/2) + 300
is a room that is dependent of temperature in all directions
I tried this, but doesn’t appear the graph
syms x y z
T0 = 300
f = -3*sqrt((x^2+y^2+z^2))+ T0;
fimplicit3(f, [0 0 0])
Thank you so much for your valious time. 3d plots, plot, temperature, room MATLAB Answers — New Questions
Microsoft Graph PowerShell SDK V2.26.1 Remains Flawed
Microsoft Graph PowerShell SDK Problems Means that Reputation Won’t be Easily Fixed
On February 25, 2025, I described how bugs in V2.26 of the Microsoft Graph PowerShell SDK made the software unusable. Late the same day, Microsoft pushed out V2.26.1. After a week’s testing, the signs are that the new version solved some of the problems seen in V2.26. However, bugs are still present in V2.26.1, including licensing failires and a nasty “invalid JWT access token” issue encountered when running the Connect-MgGraph cmdlet in an Azure Automation runbook. This error means that Connect-MgGraph failed to authenticate with Entra ID to secure an access token to allow the runbook to access data. It’s a pretty fundamental problem that’s accompanied by other issues reported on the Microsoft Graph PowerShell SDK GitHub issues page.

Given the current state, my advice is to stay on V2.25 until we know that a solid newer version of the Microsoft Graph PowerShell SDK is available.
On the surface, progress in squashing bugs is happening, and we can carry on using the SDK to generate automation solutions for Entra ID and Microsoft 365 as normal. Alas, that’s not a great plan At least, if Microsoft continues to develop the Microsoft Graph PowerShell SDK as before, exactly the same problems will appear in future versions. Lack of testing and poor communication will lead to more bugs and heightened customer dissatisfaction as Microsoft replays what happened with V2.14, V2.17/18, and now V2.26.
The Question of Testing to find Microsoft Graph PowerShell SDK Problems
Customers who experienced problems after installing V2.26 can justifiably ask what testing happens during the release cycle for a new version of the Microsoft Graph PowerShell SDK. I’m sure that some testing happens. The problem is that the testing has proven ineffective at picking up problems with heavily-used cmdlets like New-MgGroupMember and Send-MgUserMail, both of which were obviously flawed in V2.26.
It’s hard to test PowerShell cmdlets. Your use of a cmdlet might not be the way I use a cmdlet (the flexibility of PowerShell can be its own worst enemy at times). One method might be to test each cmdlet using the examples in the documentation. This sounds feasible, but it’s not. First, not all cmdlets have documented examples. Second, when examples exist, the code invariably reflects the simplest use of the cmdlet. For instance, the Send-MgUserMail cmdlet would have passed a test in V2.26 in terms of being able to send a simple message; its problems were revealed with moderately complex HTML body parts and attachments.
Third, there are just too many cmdlets to test. For V2.26.1, the number is 39,878 cmdlets (11,445 production (V1.0) and 28,433 beta). The SDK spans 38 sub-modules for the production cmdlets and 43 for beta cmdlets. These numbers grow over time as new Graph APIs appear.
Remember that the Microsoft Graph PowerShell SDK cmdlets are created by the Autorest process, which reads the Graph API schema and metadata to discover the resources and methods used to access data. The result is a cmdlet for every API. Some cmdlets or their documentation are flawed due to errors in the Graph metadata.
The challenge is to improve the quality of SDK cmdlets and documentation by making sure that the foundation (metadata) is right, and the cmdlets work the way that they should for every release. Developers don’t like surprises, and they especially don’t like when code that works with one version fails in another.
The Need for Crystal Clear Communication about Microsoft Graph PowerShell SDK Problems
The engineering group for the Microsoft Graph PowerShell SDK needs to improve its communication dramatically. Apart from some brief release notes (probably not read by many people), the bomb that lay within V2.26 was not discussed. The bomb was the impact on Azure Automation runbook due to the retirement of support for .NET6 and .NET7.
The release notes for V2.26.1 are equally terse. It’s possible to understand that the SDK rolled back to support .NET6 to address the Azure Automation issue, but not even the full changelog adds much value for anyone who’s not a professional developer, familiar with the SDK structure, and knows how to manage GitHub repositories.
The thing that seems to be forgotten is that many Microsoft 365 tenant administrators use the Microsoft Graph PowerShell SDK. Usage of the SDK is going up due to the imminent retirement of the MSOL and Azure AD modules.
V2.25 of the Microsoft Graph PowerShell SDK clocked up 3.6 million downloads compared to 1.18 million for V2.24. These are higher download numbers than for the Exchange Online management, Teams, SharePoint Online, or Entra modules and should be enough to prove the popularity of the SDK.
Tenant administrators are not developers. Most will have a passing knowledge of GitHub, and few will be able to trace the development of a new version through a GitHub changelog. What’s needed is clear, concise, and explicit explanations of what has changed in a new version, what impact this might have on existing code (if any), and any steps a tenant administrator must take to ensure that their code will continue to work.
It’s not too much to ask for people who create code that’s used by millions of people to communicate clearly with their audience. The temptation to use GitHub to generate release notes from change logs might be overpowering, but it’s simply not good enough. Context is everything, and bald statements that such and such a component was updated to fix bug number 3133 is never going to be an example of good communication.
Learning from Coping with Many Microsoft Graph PowerShell SDK Problems
I hope Microsoft learns from the V2.26 fiasco. It was a debacle created from their own making due to perfectly avoidable circumstances. To their credit, the SDK developers scrambled quickly to fix problems and get V2.26.1 out the door, but that’s still no reason for inflicting so much heartache on what should be their most fervent admirers.
There’s no doubt that the Microsoft Graph PowerShell SDK is a great tool for Microsoft 365 automation, like creating SharePoint pages from an RSS feed (just one example). Being able to interact with multiple workloads through a single SDK makes the pain somewhat bearable, except when it happens frequently. Trust in the PowerShell SDK was degraded by the V2.26 experience. I hope we see progress to allow SDK fans to build that trust back again.
Need some assistance to write great PowerShell scripts for Microsoft 365? Get a copy of the Automating Microsoft 365 with PowerShell eBook, available standalone or as part of the Office 365 for IT Pros eBook bundle.
How does the UAV Toolbox interact with NuttX scheduling?
Does Matlab offer a scheduling interface for NuttX?
I would like to be able to schedule items in the PX4 work queue and control task priority.Does Matlab offer a scheduling interface for NuttX?
I would like to be able to schedule items in the PX4 work queue and control task priority. Does Matlab offer a scheduling interface for NuttX?
I would like to be able to schedule items in the PX4 work queue and control task priority. nuttx, px4, uavtoolbox, scheduling, priority MATLAB Answers — New Questions
How can I use complex numbers and non-finite number in PLC Coder?
Most of the functions that I am working on are polynomial solvers for a specific case of a problem. As such, ‘inf’ and ‘nan’ are possible outputs of these functions when there is no solution. Are there any typical workarounds for projection of that sort of thing?
I’m supposing that I can detect the case and the return a value that is impossible (in my case a negative number) or something like that, but I do wonder. I have to work with complex numbers as potential solutions, so I’m counting on the PLC coder to create the complex number structure in Structured Text, etc.
I am also using a Beckhoff PLC.Most of the functions that I am working on are polynomial solvers for a specific case of a problem. As such, ‘inf’ and ‘nan’ are possible outputs of these functions when there is no solution. Are there any typical workarounds for projection of that sort of thing?
I’m supposing that I can detect the case and the return a value that is impossible (in my case a negative number) or something like that, but I do wonder. I have to work with complex numbers as potential solutions, so I’m counting on the PLC coder to create the complex number structure in Structured Text, etc.
I am also using a Beckhoff PLC. Most of the functions that I am working on are polynomial solvers for a specific case of a problem. As such, ‘inf’ and ‘nan’ are possible outputs of these functions when there is no solution. Are there any typical workarounds for projection of that sort of thing?
I’m supposing that I can detect the case and the return a value that is impossible (in my case a negative number) or something like that, but I do wonder. I have to work with complex numbers as potential solutions, so I’m counting on the PLC coder to create the complex number structure in Structured Text, etc.
I am also using a Beckhoff PLC. nonfinitenumber, infinity, inf, nan, beckhoff, plc, complexnumbers, polynomialsolutions MATLAB Answers — New Questions
Getting error installing Matlab on Linux
I’m getting this error when trying to install Matlab on Linux, matlab_R2024b_Linux/bin/glnxa64/libexpat.so.1: file too shortI’m getting this error when trying to install Matlab on Linux, matlab_R2024b_Linux/bin/glnxa64/libexpat.so.1: file too short I’m getting this error when trying to install Matlab on Linux, matlab_R2024b_Linux/bin/glnxa64/libexpat.so.1: file too short installation MATLAB Answers — New Questions
lorentz attractors in matlab using online and clouds rf transmitters
hello i would like to generate lorentz attractors in matlab using online and clouds rf transmitters. are there any online and clouds rf transmitters that can be used to generate it. thanks a lot.hello i would like to generate lorentz attractors in matlab using online and clouds rf transmitters. are there any online and clouds rf transmitters that can be used to generate it. thanks a lot. hello i would like to generate lorentz attractors in matlab using online and clouds rf transmitters. are there any online and clouds rf transmitters that can be used to generate it. thanks a lot. lorentz, attractors, transmitters, matlab, simulink MATLAB Answers — New Questions
Office 365 for IT Pros March 2025 Update
Subscribers Can Download Files for Monthly Update #117 Now

The Office 365 for IT Pros author team is delighted to announce the availability of the March 2025 update for the Office 365 for IT Pros (2025 edition) eBook. This is monthly update #117. Readers can check the update number of the book on the inside front cover. Details of the update are available in our change log.
This update also includes update #9 for the Automating Microsoft 365 with PowerShell book, the most complete and comprehensive coverage of using PowerShell to create solutions based on Microsoft 365 data. Despite the recent quality problems for the Microsoft Graph PowerShell SDK, we still have strong faith in the usefulness of the PowerShell SDK and the ability it gives tenant administrators to access and use data across a wide range of workloads.
Subscribers can download the updated files from their Gumroad account or by using the download link in the receipt they received by email following their original purchase. The link in the receipt always accesses the latest files. See our FAQ for more information about how to download updates.
The Demise of Skype
The flux within the Microsoft ecosystem was dramatically illustrated by last Friday’s announcement that Microsoft will close down the Skype service on May 5, 2025. While the only impact on Microsoft 365 tenants will be the retirement of Skype interoperability with Teams (MC1019985, 28 February 2025), the demise of Skype is a sign of the ruthlessness that can happen when large corporations seek savings to invest elsewhere. Anything that doesn’t generate a good return is likely to be canned, which is what happened with Viva Goals late last year.
On a personal level, I don’t think I shall miss Skype too much. The app is installed on my PC and phone, but I don’t think I have made a Skype call in a year or more. Microsoft wants people to move to Teams personal (aka Teams for free), which I also have. However, I don’t use Teams personal for calling either because of the ubiquity of WhatsApp and the easy availability of low-cost data eSIMs around the world.
Some have pointed to the $8.5 billion price paid for Skype in 2011 and wondered if Microsoft got value for the purchase. I think that they did. The challenges of scaling up Teams to deal with the demand for online meetings when the pandemic happened were huge, and the experience of running the Skype backend was invaluable (according to Rish Tandon, who ran Teams engineering at the time). It can be argued that the pandemic made Teams and propelled its development to a point where it now supports 320 million monthly active users (the latest figure from October 2023). Without the success of Teams, would the Microsoft cloud now be at an annualized run rate of $163.6 billion? In that light, the investment in Skype seems like a rounding error.
Microsoft 365 Security for IT Pros
We are often asked about updates for the Microsoft 365 Security for IT Pros eBook. The facts are that we have nothing to do with this book. After sharing some of our processes and procedures to help the author team get up and running for the original edition in 2020, we have had no interaction with the book since. The latest edition appeared in 2023 and it seems like some difficulties have occurred in keeping the material updated.
We understand the book update challenge very well because publishing a monthly update takes a lot of time and effort. Muscle memory makes the task a little easier after 117 updates, but it’s still not as easy as some might think.
On to Update #118
Heading into March, we have started work on update #118. This will be the ninth update for Office 365 for IT Pros (2025 Edition), so it’s time to start thinking about the next edition. We typically publish a new edition on July 1 each year and I don’t anticipate any change to that cadence. But the writing team will get together at the Microsoft HQ in late March for the annual MVP summit and I am sure we’ll have a chat about the next version then. Stay tuned!
Stay updated with developments across the Microsoft 365 ecosystem by subscribing to the Office 365 for IT Pros eBook. We do the research to make sure that our readers understand the technology. The Office 365 book package includes the Automating Microsoft 365 with PowerShell eBook.
Python GUI doesn’t close after closing MATLAB
Hello Team
I am opening my python pyside6 GUI from MATLAB 2023b using pyrunfile command.
I have observed that if I close my MATLAB first, my python GUI still remains open for a very long time and I have to go to the task manager to end the task. Why is it so?
How does MATLAB handle the closing of applications?Hello Team
I am opening my python pyside6 GUI from MATLAB 2023b using pyrunfile command.
I have observed that if I close my MATLAB first, my python GUI still remains open for a very long time and I have to go to the task manager to end the task. Why is it so?
How does MATLAB handle the closing of applications? Hello Team
I am opening my python pyside6 GUI from MATLAB 2023b using pyrunfile command.
I have observed that if I close my MATLAB first, my python GUI still remains open for a very long time and I have to go to the task manager to end the task. Why is it so?
How does MATLAB handle the closing of applications? matlab, pyrunfile MATLAB Answers — New Questions
Grading multiple different but correct answers in MATLAB Grader
Hello,
I am using MATLAB grader to develop problems for my students. For some problems, there are multiple valid equations that can be used to correctly solve the problem which yield different answers. What would be a good way to set up the autograder so that it can check the learners’ submissions against multiple possible correct solutions? I saw this submission, and I liked the use of the try-catch but I want to avoid hardcoding numbers i.e x == 2 or x == -2; I want to leave the 2 or -2 in variable form so that if I make any changes to the parameters in the problem, the values to be checked updates automatically.
Hope this questions makes sense,
PrabhakarHello,
I am using MATLAB grader to develop problems for my students. For some problems, there are multiple valid equations that can be used to correctly solve the problem which yield different answers. What would be a good way to set up the autograder so that it can check the learners’ submissions against multiple possible correct solutions? I saw this submission, and I liked the use of the try-catch but I want to avoid hardcoding numbers i.e x == 2 or x == -2; I want to leave the 2 or -2 in variable form so that if I make any changes to the parameters in the problem, the values to be checked updates automatically.
Hope this questions makes sense,
Prabhakar Hello,
I am using MATLAB grader to develop problems for my students. For some problems, there are multiple valid equations that can be used to correctly solve the problem which yield different answers. What would be a good way to set up the autograder so that it can check the learners’ submissions against multiple possible correct solutions? I saw this submission, and I liked the use of the try-catch but I want to avoid hardcoding numbers i.e x == 2 or x == -2; I want to leave the 2 or -2 in variable form so that if I make any changes to the parameters in the problem, the values to be checked updates automatically.
Hope this questions makes sense,
Prabhakar matlab grader MATLAB Answers — New Questions
Give me images of the code bellow
* Item one
* Item twoclc; clear; close all;
% Given Parameters
M = 1000; % Mass (kg)
K = 36000; % Column stiffness (N/m)
C = 600; % Damping coefficient (Ns/m)
Ks = 10000; % Soil stiffness (N/m)
wn = 6; % Natural frequency (rad/sec)
tspan = [0 10]; % Time span for simulation
% LuGre friction model parameters
mu_s = 0.2; % Static friction coefficient
mu_c = 0.1; % Dynamic friction coefficient
vs = 0.1; % Stribeck velocity
sigma0 = 1000; % Stiffness coefficient of bristle deflection
sigma1 = 10; % Damping coefficient
sigma2 = 0; % Viscous damping (optional)
% Load Seismic Data (Modify to load your earthquake data)
load(‘seismic_data.mat’);
acc_eq = acc_eq * 9.81; % Convert to m/s² if needed
% Interpolate to match time step
t_interp = linspace(min(t_eq), max(t_eq), length(tspan));
acc_interp = interp1(t_eq, acc_eq, t_interp, ‘linear’);
% Define ODE function with seismic input
function dxdt = SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2)
y = x(1);
y_dot = x(2);
z = x(3);
acc_g = interp1(t_interp, acc_interp, t, ‘linear’, 0);
g_y = mu_c + (mu_s – mu_c) * exp(-(y_dot / vs)^2);
z_dot = y_dot – (abs(y_dot) / g_y) * z;
F_friction = sigma0 * z + sigma1 * z_dot + sigma2 * y_dot;
y_ddot = (-C/M) * y_dot – (K/M) * y + (Ks/M) * acc_g – (F_friction/M);
dxdt = [y_dot; y_ddot; z_dot];
end
% Initial conditions
y0 = [0; 0; 0];
% Solve using ODE45
[t, Y] = ode45(@(t, x) SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2), tspan, y0);
% Extract displacement and velocity
y_response = Y(:, 1);
y_velocity = Y(:, 2);
% FFT Analysis
Fs = 100;
L = length(y_response);
Y_fft = fft(y_response);
P2 = abs(Y_fft/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs * (0:(L/2)) / L;
% Plot and Save Waveform
figure;
plot(t, y_response, ‘b’, ‘LineWidth’, 1.5);
xlabel(‘Time (s)’); ylabel(‘Displacement (m)’);
title(‘Displacement Response under Seismic Excitation’);
grid on;
saveas(gcf, ‘displacement_waveform.png’);
% Plot and Save Phase Plot
figure;
plot(y_response, y_velocity, ‘r’, ‘LineWidth’, 1.5);
xlabel(‘Displacement (m)’); ylabel(‘Velocity (m/s)’);
title(‘Phase Plot: Velocity vs. Displacement’);
grid on;
saveas(gcf, ‘phase_plot.png’);
% Plot and Save FFT Analysis
figure;
plot(f, P1, ‘g’, ‘LineWidth’, 1.5);
xlabel(‘Frequency (Hz)’); ylabel(‘Magnitude’);
title(‘FFT Analysis of Displacement Response’);
grid on;
saveas(gcf, ‘fft_analysis.png’);
% Display maximum displacement
disp([‘Maximum Displacement: ‘, num2str(max(abs(y_response))), ‘ m’]);* Item one
* Item twoclc; clear; close all;
% Given Parameters
M = 1000; % Mass (kg)
K = 36000; % Column stiffness (N/m)
C = 600; % Damping coefficient (Ns/m)
Ks = 10000; % Soil stiffness (N/m)
wn = 6; % Natural frequency (rad/sec)
tspan = [0 10]; % Time span for simulation
% LuGre friction model parameters
mu_s = 0.2; % Static friction coefficient
mu_c = 0.1; % Dynamic friction coefficient
vs = 0.1; % Stribeck velocity
sigma0 = 1000; % Stiffness coefficient of bristle deflection
sigma1 = 10; % Damping coefficient
sigma2 = 0; % Viscous damping (optional)
% Load Seismic Data (Modify to load your earthquake data)
load(‘seismic_data.mat’);
acc_eq = acc_eq * 9.81; % Convert to m/s² if needed
% Interpolate to match time step
t_interp = linspace(min(t_eq), max(t_eq), length(tspan));
acc_interp = interp1(t_eq, acc_eq, t_interp, ‘linear’);
% Define ODE function with seismic input
function dxdt = SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2)
y = x(1);
y_dot = x(2);
z = x(3);
acc_g = interp1(t_interp, acc_interp, t, ‘linear’, 0);
g_y = mu_c + (mu_s – mu_c) * exp(-(y_dot / vs)^2);
z_dot = y_dot – (abs(y_dot) / g_y) * z;
F_friction = sigma0 * z + sigma1 * z_dot + sigma2 * y_dot;
y_ddot = (-C/M) * y_dot – (K/M) * y + (Ks/M) * acc_g – (F_friction/M);
dxdt = [y_dot; y_ddot; z_dot];
end
% Initial conditions
y0 = [0; 0; 0];
% Solve using ODE45
[t, Y] = ode45(@(t, x) SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2), tspan, y0);
% Extract displacement and velocity
y_response = Y(:, 1);
y_velocity = Y(:, 2);
% FFT Analysis
Fs = 100;
L = length(y_response);
Y_fft = fft(y_response);
P2 = abs(Y_fft/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs * (0:(L/2)) / L;
% Plot and Save Waveform
figure;
plot(t, y_response, ‘b’, ‘LineWidth’, 1.5);
xlabel(‘Time (s)’); ylabel(‘Displacement (m)’);
title(‘Displacement Response under Seismic Excitation’);
grid on;
saveas(gcf, ‘displacement_waveform.png’);
% Plot and Save Phase Plot
figure;
plot(y_response, y_velocity, ‘r’, ‘LineWidth’, 1.5);
xlabel(‘Displacement (m)’); ylabel(‘Velocity (m/s)’);
title(‘Phase Plot: Velocity vs. Displacement’);
grid on;
saveas(gcf, ‘phase_plot.png’);
% Plot and Save FFT Analysis
figure;
plot(f, P1, ‘g’, ‘LineWidth’, 1.5);
xlabel(‘Frequency (Hz)’); ylabel(‘Magnitude’);
title(‘FFT Analysis of Displacement Response’);
grid on;
saveas(gcf, ‘fft_analysis.png’);
% Display maximum displacement
disp([‘Maximum Displacement: ‘, num2str(max(abs(y_response))), ‘ m’]); * Item one
* Item twoclc; clear; close all;
% Given Parameters
M = 1000; % Mass (kg)
K = 36000; % Column stiffness (N/m)
C = 600; % Damping coefficient (Ns/m)
Ks = 10000; % Soil stiffness (N/m)
wn = 6; % Natural frequency (rad/sec)
tspan = [0 10]; % Time span for simulation
% LuGre friction model parameters
mu_s = 0.2; % Static friction coefficient
mu_c = 0.1; % Dynamic friction coefficient
vs = 0.1; % Stribeck velocity
sigma0 = 1000; % Stiffness coefficient of bristle deflection
sigma1 = 10; % Damping coefficient
sigma2 = 0; % Viscous damping (optional)
% Load Seismic Data (Modify to load your earthquake data)
load(‘seismic_data.mat’);
acc_eq = acc_eq * 9.81; % Convert to m/s² if needed
% Interpolate to match time step
t_interp = linspace(min(t_eq), max(t_eq), length(tspan));
acc_interp = interp1(t_eq, acc_eq, t_interp, ‘linear’);
% Define ODE function with seismic input
function dxdt = SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2)
y = x(1);
y_dot = x(2);
z = x(3);
acc_g = interp1(t_interp, acc_interp, t, ‘linear’, 0);
g_y = mu_c + (mu_s – mu_c) * exp(-(y_dot / vs)^2);
z_dot = y_dot – (abs(y_dot) / g_y) * z;
F_friction = sigma0 * z + sigma1 * z_dot + sigma2 * y_dot;
y_ddot = (-C/M) * y_dot – (K/M) * y + (Ks/M) * acc_g – (F_friction/M);
dxdt = [y_dot; y_ddot; z_dot];
end
% Initial conditions
y0 = [0; 0; 0];
% Solve using ODE45
[t, Y] = ode45(@(t, x) SDOF_LuGre_Seismic(t, x, M, C, K, Ks, acc_interp, t_interp, mu_s, mu_c, vs, sigma0, sigma1, sigma2), tspan, y0);
% Extract displacement and velocity
y_response = Y(:, 1);
y_velocity = Y(:, 2);
% FFT Analysis
Fs = 100;
L = length(y_response);
Y_fft = fft(y_response);
P2 = abs(Y_fft/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs * (0:(L/2)) / L;
% Plot and Save Waveform
figure;
plot(t, y_response, ‘b’, ‘LineWidth’, 1.5);
xlabel(‘Time (s)’); ylabel(‘Displacement (m)’);
title(‘Displacement Response under Seismic Excitation’);
grid on;
saveas(gcf, ‘displacement_waveform.png’);
% Plot and Save Phase Plot
figure;
plot(y_response, y_velocity, ‘r’, ‘LineWidth’, 1.5);
xlabel(‘Displacement (m)’); ylabel(‘Velocity (m/s)’);
title(‘Phase Plot: Velocity vs. Displacement’);
grid on;
saveas(gcf, ‘phase_plot.png’);
% Plot and Save FFT Analysis
figure;
plot(f, P1, ‘g’, ‘LineWidth’, 1.5);
xlabel(‘Frequency (Hz)’); ylabel(‘Magnitude’);
title(‘FFT Analysis of Displacement Response’);
grid on;
saveas(gcf, ‘fft_analysis.png’);
% Display maximum displacement
disp([‘Maximum Displacement: ‘, num2str(max(abs(y_response))), ‘ m’]); image processing MATLAB Answers — New Questions
Issue with Time-Domain Shifting Using Fourier Shift Property in MATLAB
I am trying to implement time-domain shifting using the Fourier shift property. Below is my MATLAB code:
% Parameter Setting
R = 618e3;
V = 7600;
lambda = 0.0313;
Fa = 5000;
N = 10000;
time_delay = 6.135e-5;
% Axis Setting
ta = ( -N/2 : N/2-1 )/Fa;
fa = ( -N/2 : N/2-1 )*( Fa/N );
s1 = exp(-1j*2*pi/lambda*(V^2*(ta + time_delay).^2)/R);
s2 = exp(-1j*2*pi/lambda*(V^2*(ta – time_delay).^2)/R);
% s1 Shifting
s1 = fftshift(fft(s1,N));
s1 = s1.*exp(-1j*2*pi.*fa.*time_delay);
s1 = ifft(ifftshift(s1),N);
% s2 Shifting
s2 = fftshift(fft(s2,N));
s2 = s2.*exp(1j*2*pi.*fa.*time_delay);
s2 = ifft(ifftshift(s2),N);
Result = s1 – s2;
figure(1);
plot(ta,abs(Result)); xlabel("t(s)");
title(‘After Substraction’);
According to the Fourier shift theorem, the signals s1 and s2 should be identical. However, the result shows that the values in the center region are small, while the values on both sides are unexpectedly large.
I am not sure which part of my implementation is incorrect. I would greatly appreciate any guidance or suggestions to help me resolve this issue.
Thanks!I am trying to implement time-domain shifting using the Fourier shift property. Below is my MATLAB code:
% Parameter Setting
R = 618e3;
V = 7600;
lambda = 0.0313;
Fa = 5000;
N = 10000;
time_delay = 6.135e-5;
% Axis Setting
ta = ( -N/2 : N/2-1 )/Fa;
fa = ( -N/2 : N/2-1 )*( Fa/N );
s1 = exp(-1j*2*pi/lambda*(V^2*(ta + time_delay).^2)/R);
s2 = exp(-1j*2*pi/lambda*(V^2*(ta – time_delay).^2)/R);
% s1 Shifting
s1 = fftshift(fft(s1,N));
s1 = s1.*exp(-1j*2*pi.*fa.*time_delay);
s1 = ifft(ifftshift(s1),N);
% s2 Shifting
s2 = fftshift(fft(s2,N));
s2 = s2.*exp(1j*2*pi.*fa.*time_delay);
s2 = ifft(ifftshift(s2),N);
Result = s1 – s2;
figure(1);
plot(ta,abs(Result)); xlabel("t(s)");
title(‘After Substraction’);
According to the Fourier shift theorem, the signals s1 and s2 should be identical. However, the result shows that the values in the center region are small, while the values on both sides are unexpectedly large.
I am not sure which part of my implementation is incorrect. I would greatly appreciate any guidance or suggestions to help me resolve this issue.
Thanks! I am trying to implement time-domain shifting using the Fourier shift property. Below is my MATLAB code:
% Parameter Setting
R = 618e3;
V = 7600;
lambda = 0.0313;
Fa = 5000;
N = 10000;
time_delay = 6.135e-5;
% Axis Setting
ta = ( -N/2 : N/2-1 )/Fa;
fa = ( -N/2 : N/2-1 )*( Fa/N );
s1 = exp(-1j*2*pi/lambda*(V^2*(ta + time_delay).^2)/R);
s2 = exp(-1j*2*pi/lambda*(V^2*(ta – time_delay).^2)/R);
% s1 Shifting
s1 = fftshift(fft(s1,N));
s1 = s1.*exp(-1j*2*pi.*fa.*time_delay);
s1 = ifft(ifftshift(s1),N);
% s2 Shifting
s2 = fftshift(fft(s2,N));
s2 = s2.*exp(1j*2*pi.*fa.*time_delay);
s2 = ifft(ifftshift(s2),N);
Result = s1 – s2;
figure(1);
plot(ta,abs(Result)); xlabel("t(s)");
title(‘After Substraction’);
According to the Fourier shift theorem, the signals s1 and s2 should be identical. However, the result shows that the values in the center region are small, while the values on both sides are unexpectedly large.
I am not sure which part of my implementation is incorrect. I would greatly appreciate any guidance or suggestions to help me resolve this issue.
Thanks! fft, fourier shifting property MATLAB Answers — New Questions
Is the generated symbol or schematic in Simscape Multi-Winding Transformer misrepresented?
Hello,
This is probably not a functional problem with the model block but perhaps an aesthetical one. When exploring the Multi-Winding Transformer block from the Simscape Specialized Power Systems blockset the block seems to reaaragne the coil configuration in a symbol that renderes the symbol a bit confusing from the top level view. For example for a dual transformer it shows one coil on the left and three on the right. It maintains the symbol even after changing the number of coils and just continues to add ports. Something like this:
Should probably look more like this for whatever its worth:Hello,
This is probably not a functional problem with the model block but perhaps an aesthetical one. When exploring the Multi-Winding Transformer block from the Simscape Specialized Power Systems blockset the block seems to reaaragne the coil configuration in a symbol that renderes the symbol a bit confusing from the top level view. For example for a dual transformer it shows one coil on the left and three on the right. It maintains the symbol even after changing the number of coils and just continues to add ports. Something like this:
Should probably look more like this for whatever its worth: Hello,
This is probably not a functional problem with the model block but perhaps an aesthetical one. When exploring the Multi-Winding Transformer block from the Simscape Specialized Power Systems blockset the block seems to reaaragne the coil configuration in a symbol that renderes the symbol a bit confusing from the top level view. For example for a dual transformer it shows one coil on the left and three on the right. It maintains the symbol even after changing the number of coils and just continues to add ports. Something like this:
Should probably look more like this for whatever its worth: simscape MATLAB Answers — New Questions
How do I print a sentence “Hello world!” n number of times?
n is the value you would enter to display it that number of times, for example:
n = 3
the answer would be
1) Hello world!
2) Hello world!
3) Hello world!
Thanksn is the value you would enter to display it that number of times, for example:
n = 3
the answer would be
1) Hello world!
2) Hello world!
3) Hello world!
Thanks n is the value you would enter to display it that number of times, for example:
n = 3
the answer would be
1) Hello world!
2) Hello world!
3) Hello world!
Thanks fprintf, for, input, script, homework MATLAB Answers — New Questions
How can I create a singleton object that is processed in parallel threads and processes?
What I wanted to achieve
I would like to create a singleton-class (I called it Logger) to record logs to a file and output them into the command window.
What exactly did I want to achieve:
1. Reduce the number of input parameters for functions. Therefore, the Logger must be initialized once during the project startup process.:
Logger.setLogger("someLogFile.txt");
Further, from any place in the code (from any function, nested function, class, etc.), the text of the message should be written to the file as follows:
Logger.write("Some log message");
2. The Logger class should allow logs to be written to a file both from the main process and in the case of a call inside parallel threads or processes.
3. The class should prevent competition between processes/threads when writing to a file.
What I tried
During the implementation process, I found out that parallelization in MATLAB does not support saving persistent variables when passing a class object to processes/threads.
Also, MATLAB parallelization does not support singleton-objects implemented using the construct:
classdef SingletonClass < handle
properties (Constant)
instance = SingletonClass();
end
…
Since the save-load process, implemented when transferring an object to parallel threads/processes, does not save the values of Constant properties. As a result, the values of the passed class are loaded first, and then it is reset to empty as a result of Constant-property instance initialization.
I also tried writing a handle to the logging parallel.pool.DataQuery to a global variable, but I didn’t like this approach.
I also used to create an environment variable for a log file via setenv and write data there simply from a function, but this does not solve the issue of competing processes.
What was done
As a result, I was able to create this code:
classdef Logger < handle
properties (Constant)
instance = Logger();
end
properties (SetAccess = private)
filepath = strings(0);
dataQueueListener
initialized = false;
end
methods (Static)
function setLogger(filepath, dataQueryListener)
arguments
filepath
dataQueryListener
end
loggerObj = Logger.instance;
loggerObj.filepath = filepath;
loggerObj.dataQueueListener = dataQueryListener;
if ~(parallel.internal.pool.isPoolThreadWorker || ~isempty(getCurrentJob))
afterEach(loggerObj.dataQueueListener, @(input) loggerObj.writeLogs(input{:}));
end
loggerObj.initialized = true;
end
function write(logMessage)
arguments
logMessage
end
loggerObj = Logger.instance;
if loggerObj.initialized
send(loggerObj.dataQueueListener, {logMessage, loggerObj.filepath});
else
error("Logger:write:UninitializedObjectCall", …
"Logger не инициализированn");
end
end
function writeLogs(logMessage, filepath)
arguments
logMessage
filepath
end
logMessage = sprintf(logMessage);
disp(char(logMessage));
fid = fopen(filepath, ‘a’);
fprintf(fid, logMessage);
fclose(fid);
end
end
methods (Access = private)
function obj = Logger()
end
end
end
Then it’s called like this (`anotherFileFunction` – is a function in another file):
% Variables
dQL = parallel.pool.DataQueue;
defPath = "examplelogs.txt";
% Initialize Logger
Logger.setLogger(defPath, dQL);
Logger.write("Logger initializedn");
% Example call Logger in another file-function
anotherFileFunction();
% Example of logging in different types of parallelization
parpool(‘Threads’);
parallelLogging(defPath, dQL);
delete(gcp(‘nocreate’));
parpool(‘Processes’);
parallelLogging(defPath, dQL);
function parallelLogging(defPath, dQL)
% This is a function with it’s own workspace and parallel processeing in it
Logger.write("I’m in example of parallel Loggingn")
parfor idx = 1:10
pauseSec = rand().*2;
anotherFunction(pauseSec)
Logger.write(sprintf("Thread/Process %d has been paused for %.3f seconds", idx, pauseSec));
end
end
function anotherFunction(pauseSec)
% This is a function which called in parfor-loop
pause(pauseSec)
Logger.write("Pausingn")
end
function anotherFileFunction()
% This is a function in different file
Logger.write("I’m writing it from another filen")
end
And it works. Logging is successful. The output to the console is also happening. But this does not fully satisfy my first requirement: I will still be forced to pass the path to the log file and a handle to the data pool in the parallelization function.
Questionы
How can I create a singleton-object that is processed in parallel threads and processes?
Is there a way to do better than I did?
How to meet all the requirements that I described above?What I wanted to achieve
I would like to create a singleton-class (I called it Logger) to record logs to a file and output them into the command window.
What exactly did I want to achieve:
1. Reduce the number of input parameters for functions. Therefore, the Logger must be initialized once during the project startup process.:
Logger.setLogger("someLogFile.txt");
Further, from any place in the code (from any function, nested function, class, etc.), the text of the message should be written to the file as follows:
Logger.write("Some log message");
2. The Logger class should allow logs to be written to a file both from the main process and in the case of a call inside parallel threads or processes.
3. The class should prevent competition between processes/threads when writing to a file.
What I tried
During the implementation process, I found out that parallelization in MATLAB does not support saving persistent variables when passing a class object to processes/threads.
Also, MATLAB parallelization does not support singleton-objects implemented using the construct:
classdef SingletonClass < handle
properties (Constant)
instance = SingletonClass();
end
…
Since the save-load process, implemented when transferring an object to parallel threads/processes, does not save the values of Constant properties. As a result, the values of the passed class are loaded first, and then it is reset to empty as a result of Constant-property instance initialization.
I also tried writing a handle to the logging parallel.pool.DataQuery to a global variable, but I didn’t like this approach.
I also used to create an environment variable for a log file via setenv and write data there simply from a function, but this does not solve the issue of competing processes.
What was done
As a result, I was able to create this code:
classdef Logger < handle
properties (Constant)
instance = Logger();
end
properties (SetAccess = private)
filepath = strings(0);
dataQueueListener
initialized = false;
end
methods (Static)
function setLogger(filepath, dataQueryListener)
arguments
filepath
dataQueryListener
end
loggerObj = Logger.instance;
loggerObj.filepath = filepath;
loggerObj.dataQueueListener = dataQueryListener;
if ~(parallel.internal.pool.isPoolThreadWorker || ~isempty(getCurrentJob))
afterEach(loggerObj.dataQueueListener, @(input) loggerObj.writeLogs(input{:}));
end
loggerObj.initialized = true;
end
function write(logMessage)
arguments
logMessage
end
loggerObj = Logger.instance;
if loggerObj.initialized
send(loggerObj.dataQueueListener, {logMessage, loggerObj.filepath});
else
error("Logger:write:UninitializedObjectCall", …
"Logger не инициализированn");
end
end
function writeLogs(logMessage, filepath)
arguments
logMessage
filepath
end
logMessage = sprintf(logMessage);
disp(char(logMessage));
fid = fopen(filepath, ‘a’);
fprintf(fid, logMessage);
fclose(fid);
end
end
methods (Access = private)
function obj = Logger()
end
end
end
Then it’s called like this (`anotherFileFunction` – is a function in another file):
% Variables
dQL = parallel.pool.DataQueue;
defPath = "examplelogs.txt";
% Initialize Logger
Logger.setLogger(defPath, dQL);
Logger.write("Logger initializedn");
% Example call Logger in another file-function
anotherFileFunction();
% Example of logging in different types of parallelization
parpool(‘Threads’);
parallelLogging(defPath, dQL);
delete(gcp(‘nocreate’));
parpool(‘Processes’);
parallelLogging(defPath, dQL);
function parallelLogging(defPath, dQL)
% This is a function with it’s own workspace and parallel processeing in it
Logger.write("I’m in example of parallel Loggingn")
parfor idx = 1:10
pauseSec = rand().*2;
anotherFunction(pauseSec)
Logger.write(sprintf("Thread/Process %d has been paused for %.3f seconds", idx, pauseSec));
end
end
function anotherFunction(pauseSec)
% This is a function which called in parfor-loop
pause(pauseSec)
Logger.write("Pausingn")
end
function anotherFileFunction()
% This is a function in different file
Logger.write("I’m writing it from another filen")
end
And it works. Logging is successful. The output to the console is also happening. But this does not fully satisfy my first requirement: I will still be forced to pass the path to the log file and a handle to the data pool in the parallelization function.
Questionы
How can I create a singleton-object that is processed in parallel threads and processes?
Is there a way to do better than I did?
How to meet all the requirements that I described above? What I wanted to achieve
I would like to create a singleton-class (I called it Logger) to record logs to a file and output them into the command window.
What exactly did I want to achieve:
1. Reduce the number of input parameters for functions. Therefore, the Logger must be initialized once during the project startup process.:
Logger.setLogger("someLogFile.txt");
Further, from any place in the code (from any function, nested function, class, etc.), the text of the message should be written to the file as follows:
Logger.write("Some log message");
2. The Logger class should allow logs to be written to a file both from the main process and in the case of a call inside parallel threads or processes.
3. The class should prevent competition between processes/threads when writing to a file.
What I tried
During the implementation process, I found out that parallelization in MATLAB does not support saving persistent variables when passing a class object to processes/threads.
Also, MATLAB parallelization does not support singleton-objects implemented using the construct:
classdef SingletonClass < handle
properties (Constant)
instance = SingletonClass();
end
…
Since the save-load process, implemented when transferring an object to parallel threads/processes, does not save the values of Constant properties. As a result, the values of the passed class are loaded first, and then it is reset to empty as a result of Constant-property instance initialization.
I also tried writing a handle to the logging parallel.pool.DataQuery to a global variable, but I didn’t like this approach.
I also used to create an environment variable for a log file via setenv and write data there simply from a function, but this does not solve the issue of competing processes.
What was done
As a result, I was able to create this code:
classdef Logger < handle
properties (Constant)
instance = Logger();
end
properties (SetAccess = private)
filepath = strings(0);
dataQueueListener
initialized = false;
end
methods (Static)
function setLogger(filepath, dataQueryListener)
arguments
filepath
dataQueryListener
end
loggerObj = Logger.instance;
loggerObj.filepath = filepath;
loggerObj.dataQueueListener = dataQueryListener;
if ~(parallel.internal.pool.isPoolThreadWorker || ~isempty(getCurrentJob))
afterEach(loggerObj.dataQueueListener, @(input) loggerObj.writeLogs(input{:}));
end
loggerObj.initialized = true;
end
function write(logMessage)
arguments
logMessage
end
loggerObj = Logger.instance;
if loggerObj.initialized
send(loggerObj.dataQueueListener, {logMessage, loggerObj.filepath});
else
error("Logger:write:UninitializedObjectCall", …
"Logger не инициализированn");
end
end
function writeLogs(logMessage, filepath)
arguments
logMessage
filepath
end
logMessage = sprintf(logMessage);
disp(char(logMessage));
fid = fopen(filepath, ‘a’);
fprintf(fid, logMessage);
fclose(fid);
end
end
methods (Access = private)
function obj = Logger()
end
end
end
Then it’s called like this (`anotherFileFunction` – is a function in another file):
% Variables
dQL = parallel.pool.DataQueue;
defPath = "examplelogs.txt";
% Initialize Logger
Logger.setLogger(defPath, dQL);
Logger.write("Logger initializedn");
% Example call Logger in another file-function
anotherFileFunction();
% Example of logging in different types of parallelization
parpool(‘Threads’);
parallelLogging(defPath, dQL);
delete(gcp(‘nocreate’));
parpool(‘Processes’);
parallelLogging(defPath, dQL);
function parallelLogging(defPath, dQL)
% This is a function with it’s own workspace and parallel processeing in it
Logger.write("I’m in example of parallel Loggingn")
parfor idx = 1:10
pauseSec = rand().*2;
anotherFunction(pauseSec)
Logger.write(sprintf("Thread/Process %d has been paused for %.3f seconds", idx, pauseSec));
end
end
function anotherFunction(pauseSec)
% This is a function which called in parfor-loop
pause(pauseSec)
Logger.write("Pausingn")
end
function anotherFileFunction()
% This is a function in different file
Logger.write("I’m writing it from another filen")
end
And it works. Logging is successful. The output to the console is also happening. But this does not fully satisfy my first requirement: I will still be forced to pass the path to the log file and a handle to the data pool in the parallelization function.
Questionы
How can I create a singleton-object that is processed in parallel threads and processes?
Is there a way to do better than I did?
How to meet all the requirements that I described above? singleton, parallel computing, parallel computing toolbox, handles MATLAB Answers — New Questions
Group Dela of Linkwitz Riley High-, Low, and Bandpass Filter
Hello,
I am an electrical engineering student currently working on analog filters, specifically cascaded Butterworth filter approximations, also known as Linkwitz-Riley filters.
In my MATLAB code, I generate bandpass filters from individual high-pass and low-pass filters, which together form a crossover network.
I want to plot the group delay of the high-pass and low-pass filters, as well as the total group delay of the crossover network.
However, when implementing this, only the group delay plot of the high-pass filter seems to make sense.
My calculations for the high-pass and low-pass filters are as follows.
Lowpass:
Groupdelay:
Highpass:
Groupdelay
After calculating the individual filters, I combined them into a crossover network, as shown in the following MATLAB code.
In my opinion, the group delay plot of the bandpass should look like this:
(from https://www.rfcafe.com/references/electrical/butterworth-highpass-bandpass-bandstop-filter-gain-phase-group-delay-equations.htm)
My calculations result in the following Bode diagram and the corresponding group delay plot.
What am I doing wrong?
Thanks in advance for any help!
Matlab Code:
omega_r1 = 2.*pi.*30;
omega_r2 = 2.*pi.*150;
omega_r3 = 2.*pi.*800;
omega_r4 = 2.*pi.*4E3;
omega_r5 = 2.*pi.*20E3;
Q = 0.7101 ;
f = logspace(-1, 5, 1000);
omega = 2 * pi * f;
s=1i.*omega;
%LRTP1 = LInkwitz Riley Lowpass 1
C_1 = 10E-6;
C_2 = 20.0164E-6;
R_1 = 1/(omega_r2*sqrt(C_1*C_2));
H_tp1 = 1 ./ (1 – (omega.^2 ./ omega_r2^2) + (s ./ (Q .* omega_r2)));
H_tp2 = 1 ./ (1 – (omega.^2 ./ omega_r2^2) + (s ./ (Q .* omega_r2)));
magnitude_LRTP1 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r2.^2)).^2 + (omega ./ (Q .* omega_r2)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r2.^2)).^2 + (omega ./ (Q .* omega_r2)).^2);
phase_LRTP1 = -atan2(omega./(Q.*omega_r2),1-(omega.^2./omega_r2.^2))-atan2(omega./(Q.*omega_r2),1-(omega.^2./omega_r2.^2));
norm_groupdelay_LRTP1 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r2.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r2.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r2.^2) + Q.^2);
groupdelay_LRTP1= (2 .* Q .* omega_r2 .* (omega.^2 + omega_r2.^2)) ./ (Q.^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r2.^2 .* omega.^2 + Q.^2 .* omega_r2.^4);
%LRTP2 = LInkwitz Riley Lowpass 2
C_4 = 10E-6;
C_5 = 20.0164E-6;
R_4 = 1/(omega_r3*sqrt(C_4*C_5));
H_tp3 = 1 ./ (1 – (omega.^2 ./ omega_r3^2) + (s ./ (Q .* omega_r3)));
H_tp4 = 1 ./ (1 – (omega.^2 ./ omega_r3^2) + (s ./ (Q .* omega_r3)));
magnitude_LRTP2 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r3.^2)).^2 + (omega ./ (Q .* omega_r3)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r3.^2)).^2 + (omega ./ (Q .* omega_r3)).^2);
phase_LRTP2 = -atan2(omega./(Q.*omega_r3),1-(omega.^2./omega_r3.^2))-atan2(omega./(Q.*omega_r3),1-(omega.^2./omega_r3.^2));
norm_groupdelay_LRTP2 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r3.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r3.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r3.^2) + Q.^2);
groupdelay_LRTP2= (2 .* Q .* omega_r3 .* (omega.^2 + omega_r3.^2)) ./ (Q.^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r3.^2 .* omega.^2 + Q.^2 .* omega_r3.^4);
%LRTP3 = LInkwitz Riley Lowpass 3
C_7 = 10E-6;
C_8 = 20.0164E-6;
R_7 = 1/(omega_r4*sqrt(C_7*C_8));
H_tp5 = 1 ./ (1 – (omega.^2 ./ omega_r4^2) + (s ./ (Q .* omega_r4)));
H_tp6 = 1 ./ (1 – (omega.^2 ./ omega_r4^2) + (s ./ (Q .* omega_r4)));
magnitude_LRTP3 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r4.^2)).^2 + (omega ./ (Q .* omega_r4)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r4.^2)).^2 + (omega ./ (Q .* omega_r4)).^2);
phase_LRTP3 = -atan2(omega./(Q.*omega_r4),1-(omega.^2./omega_r4.^2))-atan2(omega./(Q.*omega_r4),1-(omega.^2./omega_r4.^2));
norm_groupdelay_LRTP3 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r4.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r4.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r4.^2) + Q.^2);
groupdelay_LRTP3= (2 .* Q .* omega_r4 .* (omega.^2 + omega_r4.^2)) ./ (Q^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r4.^2 .* omega.^2 + Q.^2 .* omega_r4.^4);
%LRTP4 = LInkwitz Riley Lowpass 4
C_10 = 10E-6;
C_11 = 20.0164E-6;
R_10 = 1/(omega_r5*sqrt(C_10*C_11));
H_tp7 = 1 ./ (1 – (omega.^2 ./ omega_r5^2) + (s ./ (Q .* omega_r5)));
H_tp8 = 1 ./ (1 – (omega.^2 ./ omega_r5^2) + (s ./ (Q .* omega_r5)));
magnitude_LRTP4 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r5.^2)).^2 + (omega ./ (Q .* omega_r5)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r5.^2)).^2 + (omega ./ (Q .* omega_r5)).^2);
phase_LRTP4 = -atan2(omega./(Q.*omega_r5),1-(omega.^2./omega_r5.^2))-atan2(omega./(Q.*omega_r5),1-(omega.^2./omega_r5.^2));
norm_groupdelay_LRTP4 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r5.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r5.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r5.^2) + Q.^2);
groupdelay_LRTP4= (2 .* Q .* omega_r5 .* (omega.^2 + omega_r5.^2)) ./ (Q.^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r5.^2 .* omega.^2 + Q.^2 .* omega_r5.^4);
figure;
subplot(2, 1, 1);
semilogx(f, 20*log10(magnitude_LRTP1));
hold on
semilogx(f, 20*log10(magnitude_LRTP2));
semilogx(f, 20*log10(magnitude_LRTP3));
semilogx(f, 20*log10(magnitude_LRTP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Amplitude’);
title(‘LRTP’, ‘Interpreter’, ‘latex’);
subplot(2, 1, 2);
semilogx(f, rad2deg(phase_LRTP1));
hold on
semilogx(f, rad2deg(phase_LRTP2));
semilogx(f, rad2deg(phase_LRTP3));
semilogx(f, rad2deg(phase_LRTP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Phase (Grad)’);
figure;
semilogx(f, groupdelay_LRTP1);
hold on
semilogx(f, groupdelay_LRTP2);
semilogx(f, groupdelay_LRTP3);
semilogx(f, groupdelay_LRTP4);
grid on;
xlabel(‘$omega$’, ‘Interpreter’, ‘latex’);
ylabel(‘groupdelay’);
title(‘LRTP’, ‘Interpreter’, ‘latex’);
%LRHP1 = LInkwitz Riley Highpass 1
R_2 = 10E3;
R_3 = 20.0164E3;
C_3 = 1/(omega_r1*sqrt(R_2*R_3));
H_hp1 = (Q .* (s ./ omega_r1)) ./ (1 + Q .* ((s ./ omega_r1) + (omega_r1 ./ s)));
H_hp2 = (Q .* (s ./ omega_r1)) ./ (1 + Q .* ((s ./ omega_r1) + (omega_r1 ./ s)));
magnitude_LRHP1 = (Q .* (omega ./ omega_r1)) ./ sqrt(1 + (Q .* ((omega ./ omega_r1) – (omega_r1 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r1)) ./ sqrt(1 + (Q .* ((omega ./ omega_r1) – (omega_r1 ./ omega))).^2);
phase_LRHP1 = -atan2(Q.*omega./omega_r1-Q.*omega_r1./omega,1)+pi./2-atan2(Q.*omega./omega_r1-Q.*omega_r1./omega,1)+pi./2;
norm_groupdelay_LRHP1 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r1).^2 + Q)) ./ ((Q .* (omega ./ omega_r1) – Q ./ (omega ./ omega_r1)).^2 + 1);
groupdelay_LRHP1= (2 .* (Q .* omega_r1 ./ omega.^2 + Q ./ omega_r1)) ./ ((Q .* omega ./ omega_r1 – Q .* omega_r1 ./ omega).^2 + 1);
%LRHP2 = LInkwitz Riley Highpass 2
R_5 = 10E3;
R_6 = 20.0164E3;
C_6 = 1/(omega_r2*sqrt(R_5*R_6));
H_hp3 = (Q .* (s ./ omega_r2)) ./ (1 + Q .* ((s ./ omega_r2) + (omega_r2 ./ s)));
H_hp4 = (Q .* (s ./ omega_r2)) ./ (1 + Q .* ((s ./ omega_r2) + (omega_r2 ./ s)));
magnitude_LRHP2 = (Q .* (omega ./ omega_r2)) ./ sqrt(1 + (Q .* ((omega ./ omega_r2) – (omega_r2 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r2)) ./ sqrt(1 + (Q .* ((omega ./ omega_r2) – (omega_r2 ./ omega))).^2);
phase_LRHP2 = -atan2(Q.*omega./omega_r2-Q.*omega_r2./omega,1)+pi./2-atan2(Q.*omega./omega_r2-Q.*omega_r2./omega,1)+pi./2;
norm_groupdelay_LRHP2 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r2).^2 + Q)) ./ ((Q .* (omega ./ omega_r2) – Q ./ (omega ./ omega_r2)).^2 + 1);
groupdelay_LRHP2= (2 .* (Q .* omega_r2 ./ omega.^2 + Q ./ omega_r2)) ./ ((Q .* omega ./ omega_r2 – Q .* omega_r2 ./ omega).^2 + 1);
%LRHP3 = LInkwitz Riley Highpass 3
R_8 = 10E3;
R_9 = 20.0164E3;
C_9 = 1/(omega_r3*sqrt(R_8*R_9));
H_hp5 = (Q .* (s ./ omega_r3)) ./ (1 + Q .* ((s ./ omega_r3) + (omega_r3 ./ s)));
H_hp6 = (Q .* (s ./ omega_r3)) ./ (1 + Q .* ((s ./ omega_r3) + (omega_r3 ./ s)));
magnitude_LRHP3 = (Q .* (omega ./ omega_r3)) ./ sqrt(1 + (Q .* ((omega ./ omega_r3) – (omega_r3 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r3)) ./ sqrt(1 + (Q .* ((omega ./ omega_r3) – (omega_r3 ./ omega))).^2);
phase_LRHP3 = -atan2(Q.*omega./omega_r3-Q.*omega_r3./omega,1)+pi./2-atan2(Q.*omega./omega_r3-Q.*omega_r3./omega,1)+pi./2;
norm_groupdelay_LRHP3 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r3).^2 + Q)) ./ ((Q .* (omega ./ omega_r3) – Q ./ (omega ./ omega_r3)).^2 + 1);
groupdelay_LRHP3= (2 .* (Q .* omega_r3 ./ omega.^2 + Q ./ omega_r3)) ./ ((Q .* omega ./ omega_r3 – Q .* omega_r3 ./ omega).^2 + 1);
%LRHP4 = LInkwitz Riley Highpass 4
R_11 = 10E3;
R_12 = 20.0164E3;
C_12 = 1/(omega_r4*sqrt(R_11*R_12));
H_hp7 = (Q .* (s ./ omega_r4)) ./ (1 + Q .* ((s ./ omega_r4) + (omega_r4 ./ s)));
H_hp8 = (Q .* (s ./ omega_r4)) ./ (1 + Q .* ((s ./ omega_r4) + (omega_r4 ./ s)));
magnitude_LRHP4 = (Q .* (omega ./ omega_r4)) ./ sqrt(1 + (Q .* ((omega ./ omega_r4) – (omega_r4 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r4)) ./ sqrt(1 + (Q .* ((omega ./ omega_r4) – (omega_r4 ./ omega))).^2);
phase_LRHP4 = -atan2(Q.*omega./omega_r4-Q.*omega_r4./omega,1)+pi./2-atan2(Q.*omega./omega_r4-Q.*omega_r4./omega,1)+pi./2;
norm_groupdelay_LRHP4 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r4).^2 + Q)) ./ ((Q .* (omega ./ omega_r4) – Q ./ (omega ./ omega_r4)).^2 + 1);
groupdelay_LRHP4= (2 .* (Q .* omega_r4 ./ omega.^2 + Q ./ omega_r4)) ./ ((Q .* omega ./ omega_r4 – Q .* omega_r4 ./ omega).^2 + 1);
figure;
subplot(2, 1, 1);
semilogx(f, 20*log10(magnitude_LRHP1));
hold on
semilogx(f, 20*log10(magnitude_LRHP2));
semilogx(f, 20*log10(magnitude_LRHP3));
semilogx(f, 20*log10(magnitude_LRHP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Amplitude’);
title(‘LRHP’, ‘Interpreter’, ‘latex’);
% Plot für die Phase (in Grad)
subplot(2, 1, 2);
semilogx(f, rad2deg(phase_LRHP1));
hold on
semilogx(f, rad2deg(phase_LRHP2));
semilogx(f, rad2deg(phase_LRHP3));
semilogx(f, rad2deg(phase_LRHP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Phase (Grad)’);
figure;
% Plot für die groupdelay
semilogx(f, groupdelay_LRHP1);
hold on
semilogx(f, groupdelay_LRHP2);
semilogx(f, groupdelay_LRHP3);
semilogx(f, groupdelay_LRHP4);
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘groupdelay’);
title(‘LRHP’, ‘Interpreter’, ‘latex’);
%LRBP1 = LInkwitz Riley Bandpass 1
magnitude_LRBP1 = magnitude_LRHP1.*magnitude_LRTP1;
phase_LRBP1 = phase_LRHP1+phase_LRTP1;
groupdelay_LRBP1 = groupdelay_LRTP1+groupdelay_LRHP1;
%Same result:
%groupdelay_LRBP1 = -gradient(phase_LRBP1) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass 2
magnitude_LRBP2 = magnitude_LRHP2.*magnitude_LRTP2;
phase_LRBP2 = phase_LRHP2+phase_LRTP2;
groupdelay_LRBP2 = groupdelay_LRTP2+groupdelay_LRHP2;
%Same result:
%groupdelay_LRBP2 = -gradient(phase_LRBP2) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass 3
magnitude_LRBP3 = magnitude_LRHP3.*magnitude_LRTP3;
phase_LRBP3 = phase_LRHP3+phase_LRTP3;
groupdelay_LRBP3 = groupdelay_LRTP3+groupdelay_LRHP3;
%Same result:
%groupdelay_LRBP3 = -gradient(phase_LRBP3) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass 4
magnitude_LRBP4 = magnitude_LRHP4.*magnitude_LRTP4;
phase_LRBP4 = phase_LRHP4+phase_LRTP4;
groupdelay_LRBP4 = groupdelay_LRTP4+groupdelay_LRHP4;
%Same result:
%groupdelay_LRBP4 = -gradient(phase_LRBP4) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass_ges
magnitude_LRBP_ges = magnitude_LRBP1+magnitude_LRBP2+magnitude_LRBP3+magnitude_LRBP4;
phase_LRBP_ges = phase_LRBP1+phase_LRBP2+phase_LRBP3+phase_LRBP4;
groupdelay_LRBP_ges = groupdelay_LRTP1+groupdelay_LRHP1+groupdelay_LRTP2+groupdelay_LRHP2…
+groupdelay_LRTP3+groupdelay_LRHP3+groupdelay_LRTP4+groupdelay_LRHP4;
%Same result:
%groupdelay_LRBP_ges = -gradient(phase_LRBP2) ./ gradient(omega);
figure;
subplot(2, 1, 1);
semilogx(f, 20*log10(magnitude_LRBP1));
hold on
semilogx(f, 20*log10(magnitude_LRBP2));
semilogx(f, 20*log10(magnitude_LRBP3));
semilogx(f, 20*log10(magnitude_LRBP4));
semilogx(f, 20*log10(magnitude_LRBP_ges));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Amplitude’);
title(‘LRBP’, ‘Interpreter’, ‘latex’);
% Plot für die Phase (in Grad)
subplot(2, 1, 2);
semilogx(f, rad2deg(phase_LRBP1));
hold on
semilogx(f, rad2deg(phase_LRBP2));
semilogx(f, rad2deg(phase_LRBP3));
semilogx(f, rad2deg(phase_LRBP4));
semilogx(f, rad2deg(phase_LRBP_ges));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Phase (Grad)’);
figure;
% Plot für die groupdelay
semilogx(f, groupdelay_LRBP1);
hold on
semilogx(f, groupdelay_LRBP2);
semilogx(f, groupdelay_LRBP3);
semilogx(f, groupdelay_LRBP4);
semilogx(f, groupdelay_LRBP_ges);
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘groupdelay’);
title(‘LRBP’, ‘Interpreter’, ‘latex’);Hello,
I am an electrical engineering student currently working on analog filters, specifically cascaded Butterworth filter approximations, also known as Linkwitz-Riley filters.
In my MATLAB code, I generate bandpass filters from individual high-pass and low-pass filters, which together form a crossover network.
I want to plot the group delay of the high-pass and low-pass filters, as well as the total group delay of the crossover network.
However, when implementing this, only the group delay plot of the high-pass filter seems to make sense.
My calculations for the high-pass and low-pass filters are as follows.
Lowpass:
Groupdelay:
Highpass:
Groupdelay
After calculating the individual filters, I combined them into a crossover network, as shown in the following MATLAB code.
In my opinion, the group delay plot of the bandpass should look like this:
(from https://www.rfcafe.com/references/electrical/butterworth-highpass-bandpass-bandstop-filter-gain-phase-group-delay-equations.htm)
My calculations result in the following Bode diagram and the corresponding group delay plot.
What am I doing wrong?
Thanks in advance for any help!
Matlab Code:
omega_r1 = 2.*pi.*30;
omega_r2 = 2.*pi.*150;
omega_r3 = 2.*pi.*800;
omega_r4 = 2.*pi.*4E3;
omega_r5 = 2.*pi.*20E3;
Q = 0.7101 ;
f = logspace(-1, 5, 1000);
omega = 2 * pi * f;
s=1i.*omega;
%LRTP1 = LInkwitz Riley Lowpass 1
C_1 = 10E-6;
C_2 = 20.0164E-6;
R_1 = 1/(omega_r2*sqrt(C_1*C_2));
H_tp1 = 1 ./ (1 – (omega.^2 ./ omega_r2^2) + (s ./ (Q .* omega_r2)));
H_tp2 = 1 ./ (1 – (omega.^2 ./ omega_r2^2) + (s ./ (Q .* omega_r2)));
magnitude_LRTP1 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r2.^2)).^2 + (omega ./ (Q .* omega_r2)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r2.^2)).^2 + (omega ./ (Q .* omega_r2)).^2);
phase_LRTP1 = -atan2(omega./(Q.*omega_r2),1-(omega.^2./omega_r2.^2))-atan2(omega./(Q.*omega_r2),1-(omega.^2./omega_r2.^2));
norm_groupdelay_LRTP1 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r2.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r2.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r2.^2) + Q.^2);
groupdelay_LRTP1= (2 .* Q .* omega_r2 .* (omega.^2 + omega_r2.^2)) ./ (Q.^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r2.^2 .* omega.^2 + Q.^2 .* omega_r2.^4);
%LRTP2 = LInkwitz Riley Lowpass 2
C_4 = 10E-6;
C_5 = 20.0164E-6;
R_4 = 1/(omega_r3*sqrt(C_4*C_5));
H_tp3 = 1 ./ (1 – (omega.^2 ./ omega_r3^2) + (s ./ (Q .* omega_r3)));
H_tp4 = 1 ./ (1 – (omega.^2 ./ omega_r3^2) + (s ./ (Q .* omega_r3)));
magnitude_LRTP2 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r3.^2)).^2 + (omega ./ (Q .* omega_r3)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r3.^2)).^2 + (omega ./ (Q .* omega_r3)).^2);
phase_LRTP2 = -atan2(omega./(Q.*omega_r3),1-(omega.^2./omega_r3.^2))-atan2(omega./(Q.*omega_r3),1-(omega.^2./omega_r3.^2));
norm_groupdelay_LRTP2 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r3.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r3.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r3.^2) + Q.^2);
groupdelay_LRTP2= (2 .* Q .* omega_r3 .* (omega.^2 + omega_r3.^2)) ./ (Q.^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r3.^2 .* omega.^2 + Q.^2 .* omega_r3.^4);
%LRTP3 = LInkwitz Riley Lowpass 3
C_7 = 10E-6;
C_8 = 20.0164E-6;
R_7 = 1/(omega_r4*sqrt(C_7*C_8));
H_tp5 = 1 ./ (1 – (omega.^2 ./ omega_r4^2) + (s ./ (Q .* omega_r4)));
H_tp6 = 1 ./ (1 – (omega.^2 ./ omega_r4^2) + (s ./ (Q .* omega_r4)));
magnitude_LRTP3 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r4.^2)).^2 + (omega ./ (Q .* omega_r4)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r4.^2)).^2 + (omega ./ (Q .* omega_r4)).^2);
phase_LRTP3 = -atan2(omega./(Q.*omega_r4),1-(omega.^2./omega_r4.^2))-atan2(omega./(Q.*omega_r4),1-(omega.^2./omega_r4.^2));
norm_groupdelay_LRTP3 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r4.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r4.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r4.^2) + Q.^2);
groupdelay_LRTP3= (2 .* Q .* omega_r4 .* (omega.^2 + omega_r4.^2)) ./ (Q^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r4.^2 .* omega.^2 + Q.^2 .* omega_r4.^4);
%LRTP4 = LInkwitz Riley Lowpass 4
C_10 = 10E-6;
C_11 = 20.0164E-6;
R_10 = 1/(omega_r5*sqrt(C_10*C_11));
H_tp7 = 1 ./ (1 – (omega.^2 ./ omega_r5^2) + (s ./ (Q .* omega_r5)));
H_tp8 = 1 ./ (1 – (omega.^2 ./ omega_r5^2) + (s ./ (Q .* omega_r5)));
magnitude_LRTP4 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r5.^2)).^2 + (omega ./ (Q .* omega_r5)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r5.^2)).^2 + (omega ./ (Q .* omega_r5)).^2);
phase_LRTP4 = -atan2(omega./(Q.*omega_r5),1-(omega.^2./omega_r5.^2))-atan2(omega./(Q.*omega_r5),1-(omega.^2./omega_r5.^2));
norm_groupdelay_LRTP4 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r5.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r5.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r5.^2) + Q.^2);
groupdelay_LRTP4= (2 .* Q .* omega_r5 .* (omega.^2 + omega_r5.^2)) ./ (Q.^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r5.^2 .* omega.^2 + Q.^2 .* omega_r5.^4);
figure;
subplot(2, 1, 1);
semilogx(f, 20*log10(magnitude_LRTP1));
hold on
semilogx(f, 20*log10(magnitude_LRTP2));
semilogx(f, 20*log10(magnitude_LRTP3));
semilogx(f, 20*log10(magnitude_LRTP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Amplitude’);
title(‘LRTP’, ‘Interpreter’, ‘latex’);
subplot(2, 1, 2);
semilogx(f, rad2deg(phase_LRTP1));
hold on
semilogx(f, rad2deg(phase_LRTP2));
semilogx(f, rad2deg(phase_LRTP3));
semilogx(f, rad2deg(phase_LRTP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Phase (Grad)’);
figure;
semilogx(f, groupdelay_LRTP1);
hold on
semilogx(f, groupdelay_LRTP2);
semilogx(f, groupdelay_LRTP3);
semilogx(f, groupdelay_LRTP4);
grid on;
xlabel(‘$omega$’, ‘Interpreter’, ‘latex’);
ylabel(‘groupdelay’);
title(‘LRTP’, ‘Interpreter’, ‘latex’);
%LRHP1 = LInkwitz Riley Highpass 1
R_2 = 10E3;
R_3 = 20.0164E3;
C_3 = 1/(omega_r1*sqrt(R_2*R_3));
H_hp1 = (Q .* (s ./ omega_r1)) ./ (1 + Q .* ((s ./ omega_r1) + (omega_r1 ./ s)));
H_hp2 = (Q .* (s ./ omega_r1)) ./ (1 + Q .* ((s ./ omega_r1) + (omega_r1 ./ s)));
magnitude_LRHP1 = (Q .* (omega ./ omega_r1)) ./ sqrt(1 + (Q .* ((omega ./ omega_r1) – (omega_r1 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r1)) ./ sqrt(1 + (Q .* ((omega ./ omega_r1) – (omega_r1 ./ omega))).^2);
phase_LRHP1 = -atan2(Q.*omega./omega_r1-Q.*omega_r1./omega,1)+pi./2-atan2(Q.*omega./omega_r1-Q.*omega_r1./omega,1)+pi./2;
norm_groupdelay_LRHP1 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r1).^2 + Q)) ./ ((Q .* (omega ./ omega_r1) – Q ./ (omega ./ omega_r1)).^2 + 1);
groupdelay_LRHP1= (2 .* (Q .* omega_r1 ./ omega.^2 + Q ./ omega_r1)) ./ ((Q .* omega ./ omega_r1 – Q .* omega_r1 ./ omega).^2 + 1);
%LRHP2 = LInkwitz Riley Highpass 2
R_5 = 10E3;
R_6 = 20.0164E3;
C_6 = 1/(omega_r2*sqrt(R_5*R_6));
H_hp3 = (Q .* (s ./ omega_r2)) ./ (1 + Q .* ((s ./ omega_r2) + (omega_r2 ./ s)));
H_hp4 = (Q .* (s ./ omega_r2)) ./ (1 + Q .* ((s ./ omega_r2) + (omega_r2 ./ s)));
magnitude_LRHP2 = (Q .* (omega ./ omega_r2)) ./ sqrt(1 + (Q .* ((omega ./ omega_r2) – (omega_r2 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r2)) ./ sqrt(1 + (Q .* ((omega ./ omega_r2) – (omega_r2 ./ omega))).^2);
phase_LRHP2 = -atan2(Q.*omega./omega_r2-Q.*omega_r2./omega,1)+pi./2-atan2(Q.*omega./omega_r2-Q.*omega_r2./omega,1)+pi./2;
norm_groupdelay_LRHP2 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r2).^2 + Q)) ./ ((Q .* (omega ./ omega_r2) – Q ./ (omega ./ omega_r2)).^2 + 1);
groupdelay_LRHP2= (2 .* (Q .* omega_r2 ./ omega.^2 + Q ./ omega_r2)) ./ ((Q .* omega ./ omega_r2 – Q .* omega_r2 ./ omega).^2 + 1);
%LRHP3 = LInkwitz Riley Highpass 3
R_8 = 10E3;
R_9 = 20.0164E3;
C_9 = 1/(omega_r3*sqrt(R_8*R_9));
H_hp5 = (Q .* (s ./ omega_r3)) ./ (1 + Q .* ((s ./ omega_r3) + (omega_r3 ./ s)));
H_hp6 = (Q .* (s ./ omega_r3)) ./ (1 + Q .* ((s ./ omega_r3) + (omega_r3 ./ s)));
magnitude_LRHP3 = (Q .* (omega ./ omega_r3)) ./ sqrt(1 + (Q .* ((omega ./ omega_r3) – (omega_r3 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r3)) ./ sqrt(1 + (Q .* ((omega ./ omega_r3) – (omega_r3 ./ omega))).^2);
phase_LRHP3 = -atan2(Q.*omega./omega_r3-Q.*omega_r3./omega,1)+pi./2-atan2(Q.*omega./omega_r3-Q.*omega_r3./omega,1)+pi./2;
norm_groupdelay_LRHP3 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r3).^2 + Q)) ./ ((Q .* (omega ./ omega_r3) – Q ./ (omega ./ omega_r3)).^2 + 1);
groupdelay_LRHP3= (2 .* (Q .* omega_r3 ./ omega.^2 + Q ./ omega_r3)) ./ ((Q .* omega ./ omega_r3 – Q .* omega_r3 ./ omega).^2 + 1);
%LRHP4 = LInkwitz Riley Highpass 4
R_11 = 10E3;
R_12 = 20.0164E3;
C_12 = 1/(omega_r4*sqrt(R_11*R_12));
H_hp7 = (Q .* (s ./ omega_r4)) ./ (1 + Q .* ((s ./ omega_r4) + (omega_r4 ./ s)));
H_hp8 = (Q .* (s ./ omega_r4)) ./ (1 + Q .* ((s ./ omega_r4) + (omega_r4 ./ s)));
magnitude_LRHP4 = (Q .* (omega ./ omega_r4)) ./ sqrt(1 + (Q .* ((omega ./ omega_r4) – (omega_r4 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r4)) ./ sqrt(1 + (Q .* ((omega ./ omega_r4) – (omega_r4 ./ omega))).^2);
phase_LRHP4 = -atan2(Q.*omega./omega_r4-Q.*omega_r4./omega,1)+pi./2-atan2(Q.*omega./omega_r4-Q.*omega_r4./omega,1)+pi./2;
norm_groupdelay_LRHP4 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r4).^2 + Q)) ./ ((Q .* (omega ./ omega_r4) – Q ./ (omega ./ omega_r4)).^2 + 1);
groupdelay_LRHP4= (2 .* (Q .* omega_r4 ./ omega.^2 + Q ./ omega_r4)) ./ ((Q .* omega ./ omega_r4 – Q .* omega_r4 ./ omega).^2 + 1);
figure;
subplot(2, 1, 1);
semilogx(f, 20*log10(magnitude_LRHP1));
hold on
semilogx(f, 20*log10(magnitude_LRHP2));
semilogx(f, 20*log10(magnitude_LRHP3));
semilogx(f, 20*log10(magnitude_LRHP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Amplitude’);
title(‘LRHP’, ‘Interpreter’, ‘latex’);
% Plot für die Phase (in Grad)
subplot(2, 1, 2);
semilogx(f, rad2deg(phase_LRHP1));
hold on
semilogx(f, rad2deg(phase_LRHP2));
semilogx(f, rad2deg(phase_LRHP3));
semilogx(f, rad2deg(phase_LRHP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Phase (Grad)’);
figure;
% Plot für die groupdelay
semilogx(f, groupdelay_LRHP1);
hold on
semilogx(f, groupdelay_LRHP2);
semilogx(f, groupdelay_LRHP3);
semilogx(f, groupdelay_LRHP4);
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘groupdelay’);
title(‘LRHP’, ‘Interpreter’, ‘latex’);
%LRBP1 = LInkwitz Riley Bandpass 1
magnitude_LRBP1 = magnitude_LRHP1.*magnitude_LRTP1;
phase_LRBP1 = phase_LRHP1+phase_LRTP1;
groupdelay_LRBP1 = groupdelay_LRTP1+groupdelay_LRHP1;
%Same result:
%groupdelay_LRBP1 = -gradient(phase_LRBP1) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass 2
magnitude_LRBP2 = magnitude_LRHP2.*magnitude_LRTP2;
phase_LRBP2 = phase_LRHP2+phase_LRTP2;
groupdelay_LRBP2 = groupdelay_LRTP2+groupdelay_LRHP2;
%Same result:
%groupdelay_LRBP2 = -gradient(phase_LRBP2) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass 3
magnitude_LRBP3 = magnitude_LRHP3.*magnitude_LRTP3;
phase_LRBP3 = phase_LRHP3+phase_LRTP3;
groupdelay_LRBP3 = groupdelay_LRTP3+groupdelay_LRHP3;
%Same result:
%groupdelay_LRBP3 = -gradient(phase_LRBP3) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass 4
magnitude_LRBP4 = magnitude_LRHP4.*magnitude_LRTP4;
phase_LRBP4 = phase_LRHP4+phase_LRTP4;
groupdelay_LRBP4 = groupdelay_LRTP4+groupdelay_LRHP4;
%Same result:
%groupdelay_LRBP4 = -gradient(phase_LRBP4) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass_ges
magnitude_LRBP_ges = magnitude_LRBP1+magnitude_LRBP2+magnitude_LRBP3+magnitude_LRBP4;
phase_LRBP_ges = phase_LRBP1+phase_LRBP2+phase_LRBP3+phase_LRBP4;
groupdelay_LRBP_ges = groupdelay_LRTP1+groupdelay_LRHP1+groupdelay_LRTP2+groupdelay_LRHP2…
+groupdelay_LRTP3+groupdelay_LRHP3+groupdelay_LRTP4+groupdelay_LRHP4;
%Same result:
%groupdelay_LRBP_ges = -gradient(phase_LRBP2) ./ gradient(omega);
figure;
subplot(2, 1, 1);
semilogx(f, 20*log10(magnitude_LRBP1));
hold on
semilogx(f, 20*log10(magnitude_LRBP2));
semilogx(f, 20*log10(magnitude_LRBP3));
semilogx(f, 20*log10(magnitude_LRBP4));
semilogx(f, 20*log10(magnitude_LRBP_ges));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Amplitude’);
title(‘LRBP’, ‘Interpreter’, ‘latex’);
% Plot für die Phase (in Grad)
subplot(2, 1, 2);
semilogx(f, rad2deg(phase_LRBP1));
hold on
semilogx(f, rad2deg(phase_LRBP2));
semilogx(f, rad2deg(phase_LRBP3));
semilogx(f, rad2deg(phase_LRBP4));
semilogx(f, rad2deg(phase_LRBP_ges));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Phase (Grad)’);
figure;
% Plot für die groupdelay
semilogx(f, groupdelay_LRBP1);
hold on
semilogx(f, groupdelay_LRBP2);
semilogx(f, groupdelay_LRBP3);
semilogx(f, groupdelay_LRBP4);
semilogx(f, groupdelay_LRBP_ges);
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘groupdelay’);
title(‘LRBP’, ‘Interpreter’, ‘latex’); Hello,
I am an electrical engineering student currently working on analog filters, specifically cascaded Butterworth filter approximations, also known as Linkwitz-Riley filters.
In my MATLAB code, I generate bandpass filters from individual high-pass and low-pass filters, which together form a crossover network.
I want to plot the group delay of the high-pass and low-pass filters, as well as the total group delay of the crossover network.
However, when implementing this, only the group delay plot of the high-pass filter seems to make sense.
My calculations for the high-pass and low-pass filters are as follows.
Lowpass:
Groupdelay:
Highpass:
Groupdelay
After calculating the individual filters, I combined them into a crossover network, as shown in the following MATLAB code.
In my opinion, the group delay plot of the bandpass should look like this:
(from https://www.rfcafe.com/references/electrical/butterworth-highpass-bandpass-bandstop-filter-gain-phase-group-delay-equations.htm)
My calculations result in the following Bode diagram and the corresponding group delay plot.
What am I doing wrong?
Thanks in advance for any help!
Matlab Code:
omega_r1 = 2.*pi.*30;
omega_r2 = 2.*pi.*150;
omega_r3 = 2.*pi.*800;
omega_r4 = 2.*pi.*4E3;
omega_r5 = 2.*pi.*20E3;
Q = 0.7101 ;
f = logspace(-1, 5, 1000);
omega = 2 * pi * f;
s=1i.*omega;
%LRTP1 = LInkwitz Riley Lowpass 1
C_1 = 10E-6;
C_2 = 20.0164E-6;
R_1 = 1/(omega_r2*sqrt(C_1*C_2));
H_tp1 = 1 ./ (1 – (omega.^2 ./ omega_r2^2) + (s ./ (Q .* omega_r2)));
H_tp2 = 1 ./ (1 – (omega.^2 ./ omega_r2^2) + (s ./ (Q .* omega_r2)));
magnitude_LRTP1 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r2.^2)).^2 + (omega ./ (Q .* omega_r2)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r2.^2)).^2 + (omega ./ (Q .* omega_r2)).^2);
phase_LRTP1 = -atan2(omega./(Q.*omega_r2),1-(omega.^2./omega_r2.^2))-atan2(omega./(Q.*omega_r2),1-(omega.^2./omega_r2.^2));
norm_groupdelay_LRTP1 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r2.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r2.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r2.^2) + Q.^2);
groupdelay_LRTP1= (2 .* Q .* omega_r2 .* (omega.^2 + omega_r2.^2)) ./ (Q.^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r2.^2 .* omega.^2 + Q.^2 .* omega_r2.^4);
%LRTP2 = LInkwitz Riley Lowpass 2
C_4 = 10E-6;
C_5 = 20.0164E-6;
R_4 = 1/(omega_r3*sqrt(C_4*C_5));
H_tp3 = 1 ./ (1 – (omega.^2 ./ omega_r3^2) + (s ./ (Q .* omega_r3)));
H_tp4 = 1 ./ (1 – (omega.^2 ./ omega_r3^2) + (s ./ (Q .* omega_r3)));
magnitude_LRTP2 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r3.^2)).^2 + (omega ./ (Q .* omega_r3)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r3.^2)).^2 + (omega ./ (Q .* omega_r3)).^2);
phase_LRTP2 = -atan2(omega./(Q.*omega_r3),1-(omega.^2./omega_r3.^2))-atan2(omega./(Q.*omega_r3),1-(omega.^2./omega_r3.^2));
norm_groupdelay_LRTP2 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r3.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r3.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r3.^2) + Q.^2);
groupdelay_LRTP2= (2 .* Q .* omega_r3 .* (omega.^2 + omega_r3.^2)) ./ (Q.^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r3.^2 .* omega.^2 + Q.^2 .* omega_r3.^4);
%LRTP3 = LInkwitz Riley Lowpass 3
C_7 = 10E-6;
C_8 = 20.0164E-6;
R_7 = 1/(omega_r4*sqrt(C_7*C_8));
H_tp5 = 1 ./ (1 – (omega.^2 ./ omega_r4^2) + (s ./ (Q .* omega_r4)));
H_tp6 = 1 ./ (1 – (omega.^2 ./ omega_r4^2) + (s ./ (Q .* omega_r4)));
magnitude_LRTP3 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r4.^2)).^2 + (omega ./ (Q .* omega_r4)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r4.^2)).^2 + (omega ./ (Q .* omega_r4)).^2);
phase_LRTP3 = -atan2(omega./(Q.*omega_r4),1-(omega.^2./omega_r4.^2))-atan2(omega./(Q.*omega_r4),1-(omega.^2./omega_r4.^2));
norm_groupdelay_LRTP3 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r4.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r4.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r4.^2) + Q.^2);
groupdelay_LRTP3= (2 .* Q .* omega_r4 .* (omega.^2 + omega_r4.^2)) ./ (Q^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r4.^2 .* omega.^2 + Q.^2 .* omega_r4.^4);
%LRTP4 = LInkwitz Riley Lowpass 4
C_10 = 10E-6;
C_11 = 20.0164E-6;
R_10 = 1/(omega_r5*sqrt(C_10*C_11));
H_tp7 = 1 ./ (1 – (omega.^2 ./ omega_r5^2) + (s ./ (Q .* omega_r5)));
H_tp8 = 1 ./ (1 – (omega.^2 ./ omega_r5^2) + (s ./ (Q .* omega_r5)));
magnitude_LRTP4 = 1 ./ sqrt((1 – (omega.^2 ./ omega_r5.^2)).^2 + (omega ./ (Q .* omega_r5)).^2)…
.*1 ./ sqrt((1 – (omega.^2 ./ omega_r5.^2)).^2 + (omega ./ (Q .* omega_r5)).^2);
phase_LRTP4 = -atan2(omega./(Q.*omega_r5),1-(omega.^2./omega_r5.^2))-atan2(omega./(Q.*omega_r5),1-(omega.^2./omega_r5.^2));
norm_groupdelay_LRTP4 = 1/(2*pi).*(2 * Q * (omega.^2 ./ omega_r5.^2 + 1)) ./ (Q.^2 .* (omega.^4 ./ omega_r5.^4) + (1 – 2 * Q.^2) .* (omega.^2 ./ omega_r5.^2) + Q.^2);
groupdelay_LRTP4= (2 .* Q .* omega_r5 .* (omega.^2 + omega_r5.^2)) ./ (Q.^2 .* omega.^4 + (1 – 2 .* Q.^2) .* omega_r5.^2 .* omega.^2 + Q.^2 .* omega_r5.^4);
figure;
subplot(2, 1, 1);
semilogx(f, 20*log10(magnitude_LRTP1));
hold on
semilogx(f, 20*log10(magnitude_LRTP2));
semilogx(f, 20*log10(magnitude_LRTP3));
semilogx(f, 20*log10(magnitude_LRTP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Amplitude’);
title(‘LRTP’, ‘Interpreter’, ‘latex’);
subplot(2, 1, 2);
semilogx(f, rad2deg(phase_LRTP1));
hold on
semilogx(f, rad2deg(phase_LRTP2));
semilogx(f, rad2deg(phase_LRTP3));
semilogx(f, rad2deg(phase_LRTP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Phase (Grad)’);
figure;
semilogx(f, groupdelay_LRTP1);
hold on
semilogx(f, groupdelay_LRTP2);
semilogx(f, groupdelay_LRTP3);
semilogx(f, groupdelay_LRTP4);
grid on;
xlabel(‘$omega$’, ‘Interpreter’, ‘latex’);
ylabel(‘groupdelay’);
title(‘LRTP’, ‘Interpreter’, ‘latex’);
%LRHP1 = LInkwitz Riley Highpass 1
R_2 = 10E3;
R_3 = 20.0164E3;
C_3 = 1/(omega_r1*sqrt(R_2*R_3));
H_hp1 = (Q .* (s ./ omega_r1)) ./ (1 + Q .* ((s ./ omega_r1) + (omega_r1 ./ s)));
H_hp2 = (Q .* (s ./ omega_r1)) ./ (1 + Q .* ((s ./ omega_r1) + (omega_r1 ./ s)));
magnitude_LRHP1 = (Q .* (omega ./ omega_r1)) ./ sqrt(1 + (Q .* ((omega ./ omega_r1) – (omega_r1 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r1)) ./ sqrt(1 + (Q .* ((omega ./ omega_r1) – (omega_r1 ./ omega))).^2);
phase_LRHP1 = -atan2(Q.*omega./omega_r1-Q.*omega_r1./omega,1)+pi./2-atan2(Q.*omega./omega_r1-Q.*omega_r1./omega,1)+pi./2;
norm_groupdelay_LRHP1 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r1).^2 + Q)) ./ ((Q .* (omega ./ omega_r1) – Q ./ (omega ./ omega_r1)).^2 + 1);
groupdelay_LRHP1= (2 .* (Q .* omega_r1 ./ omega.^2 + Q ./ omega_r1)) ./ ((Q .* omega ./ omega_r1 – Q .* omega_r1 ./ omega).^2 + 1);
%LRHP2 = LInkwitz Riley Highpass 2
R_5 = 10E3;
R_6 = 20.0164E3;
C_6 = 1/(omega_r2*sqrt(R_5*R_6));
H_hp3 = (Q .* (s ./ omega_r2)) ./ (1 + Q .* ((s ./ omega_r2) + (omega_r2 ./ s)));
H_hp4 = (Q .* (s ./ omega_r2)) ./ (1 + Q .* ((s ./ omega_r2) + (omega_r2 ./ s)));
magnitude_LRHP2 = (Q .* (omega ./ omega_r2)) ./ sqrt(1 + (Q .* ((omega ./ omega_r2) – (omega_r2 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r2)) ./ sqrt(1 + (Q .* ((omega ./ omega_r2) – (omega_r2 ./ omega))).^2);
phase_LRHP2 = -atan2(Q.*omega./omega_r2-Q.*omega_r2./omega,1)+pi./2-atan2(Q.*omega./omega_r2-Q.*omega_r2./omega,1)+pi./2;
norm_groupdelay_LRHP2 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r2).^2 + Q)) ./ ((Q .* (omega ./ omega_r2) – Q ./ (omega ./ omega_r2)).^2 + 1);
groupdelay_LRHP2= (2 .* (Q .* omega_r2 ./ omega.^2 + Q ./ omega_r2)) ./ ((Q .* omega ./ omega_r2 – Q .* omega_r2 ./ omega).^2 + 1);
%LRHP3 = LInkwitz Riley Highpass 3
R_8 = 10E3;
R_9 = 20.0164E3;
C_9 = 1/(omega_r3*sqrt(R_8*R_9));
H_hp5 = (Q .* (s ./ omega_r3)) ./ (1 + Q .* ((s ./ omega_r3) + (omega_r3 ./ s)));
H_hp6 = (Q .* (s ./ omega_r3)) ./ (1 + Q .* ((s ./ omega_r3) + (omega_r3 ./ s)));
magnitude_LRHP3 = (Q .* (omega ./ omega_r3)) ./ sqrt(1 + (Q .* ((omega ./ omega_r3) – (omega_r3 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r3)) ./ sqrt(1 + (Q .* ((omega ./ omega_r3) – (omega_r3 ./ omega))).^2);
phase_LRHP3 = -atan2(Q.*omega./omega_r3-Q.*omega_r3./omega,1)+pi./2-atan2(Q.*omega./omega_r3-Q.*omega_r3./omega,1)+pi./2;
norm_groupdelay_LRHP3 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r3).^2 + Q)) ./ ((Q .* (omega ./ omega_r3) – Q ./ (omega ./ omega_r3)).^2 + 1);
groupdelay_LRHP3= (2 .* (Q .* omega_r3 ./ omega.^2 + Q ./ omega_r3)) ./ ((Q .* omega ./ omega_r3 – Q .* omega_r3 ./ omega).^2 + 1);
%LRHP4 = LInkwitz Riley Highpass 4
R_11 = 10E3;
R_12 = 20.0164E3;
C_12 = 1/(omega_r4*sqrt(R_11*R_12));
H_hp7 = (Q .* (s ./ omega_r4)) ./ (1 + Q .* ((s ./ omega_r4) + (omega_r4 ./ s)));
H_hp8 = (Q .* (s ./ omega_r4)) ./ (1 + Q .* ((s ./ omega_r4) + (omega_r4 ./ s)));
magnitude_LRHP4 = (Q .* (omega ./ omega_r4)) ./ sqrt(1 + (Q .* ((omega ./ omega_r4) – (omega_r4 ./ omega))).^2)…
.*(Q .* (omega ./ omega_r4)) ./ sqrt(1 + (Q .* ((omega ./ omega_r4) – (omega_r4 ./ omega))).^2);
phase_LRHP4 = -atan2(Q.*omega./omega_r4-Q.*omega_r4./omega,1)+pi./2-atan2(Q.*omega./omega_r4-Q.*omega_r4./omega,1)+pi./2;
norm_groupdelay_LRHP4 = 1/(2*pi) .* (2 .* (Q ./ (omega ./ omega_r4).^2 + Q)) ./ ((Q .* (omega ./ omega_r4) – Q ./ (omega ./ omega_r4)).^2 + 1);
groupdelay_LRHP4= (2 .* (Q .* omega_r4 ./ omega.^2 + Q ./ omega_r4)) ./ ((Q .* omega ./ omega_r4 – Q .* omega_r4 ./ omega).^2 + 1);
figure;
subplot(2, 1, 1);
semilogx(f, 20*log10(magnitude_LRHP1));
hold on
semilogx(f, 20*log10(magnitude_LRHP2));
semilogx(f, 20*log10(magnitude_LRHP3));
semilogx(f, 20*log10(magnitude_LRHP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Amplitude’);
title(‘LRHP’, ‘Interpreter’, ‘latex’);
% Plot für die Phase (in Grad)
subplot(2, 1, 2);
semilogx(f, rad2deg(phase_LRHP1));
hold on
semilogx(f, rad2deg(phase_LRHP2));
semilogx(f, rad2deg(phase_LRHP3));
semilogx(f, rad2deg(phase_LRHP4));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Phase (Grad)’);
figure;
% Plot für die groupdelay
semilogx(f, groupdelay_LRHP1);
hold on
semilogx(f, groupdelay_LRHP2);
semilogx(f, groupdelay_LRHP3);
semilogx(f, groupdelay_LRHP4);
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘groupdelay’);
title(‘LRHP’, ‘Interpreter’, ‘latex’);
%LRBP1 = LInkwitz Riley Bandpass 1
magnitude_LRBP1 = magnitude_LRHP1.*magnitude_LRTP1;
phase_LRBP1 = phase_LRHP1+phase_LRTP1;
groupdelay_LRBP1 = groupdelay_LRTP1+groupdelay_LRHP1;
%Same result:
%groupdelay_LRBP1 = -gradient(phase_LRBP1) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass 2
magnitude_LRBP2 = magnitude_LRHP2.*magnitude_LRTP2;
phase_LRBP2 = phase_LRHP2+phase_LRTP2;
groupdelay_LRBP2 = groupdelay_LRTP2+groupdelay_LRHP2;
%Same result:
%groupdelay_LRBP2 = -gradient(phase_LRBP2) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass 3
magnitude_LRBP3 = magnitude_LRHP3.*magnitude_LRTP3;
phase_LRBP3 = phase_LRHP3+phase_LRTP3;
groupdelay_LRBP3 = groupdelay_LRTP3+groupdelay_LRHP3;
%Same result:
%groupdelay_LRBP3 = -gradient(phase_LRBP3) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass 4
magnitude_LRBP4 = magnitude_LRHP4.*magnitude_LRTP4;
phase_LRBP4 = phase_LRHP4+phase_LRTP4;
groupdelay_LRBP4 = groupdelay_LRTP4+groupdelay_LRHP4;
%Same result:
%groupdelay_LRBP4 = -gradient(phase_LRBP4) ./ gradient(omega);
%LRBP1 = LInkwitz Riley Bandpass_ges
magnitude_LRBP_ges = magnitude_LRBP1+magnitude_LRBP2+magnitude_LRBP3+magnitude_LRBP4;
phase_LRBP_ges = phase_LRBP1+phase_LRBP2+phase_LRBP3+phase_LRBP4;
groupdelay_LRBP_ges = groupdelay_LRTP1+groupdelay_LRHP1+groupdelay_LRTP2+groupdelay_LRHP2…
+groupdelay_LRTP3+groupdelay_LRHP3+groupdelay_LRTP4+groupdelay_LRHP4;
%Same result:
%groupdelay_LRBP_ges = -gradient(phase_LRBP2) ./ gradient(omega);
figure;
subplot(2, 1, 1);
semilogx(f, 20*log10(magnitude_LRBP1));
hold on
semilogx(f, 20*log10(magnitude_LRBP2));
semilogx(f, 20*log10(magnitude_LRBP3));
semilogx(f, 20*log10(magnitude_LRBP4));
semilogx(f, 20*log10(magnitude_LRBP_ges));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Amplitude’);
title(‘LRBP’, ‘Interpreter’, ‘latex’);
% Plot für die Phase (in Grad)
subplot(2, 1, 2);
semilogx(f, rad2deg(phase_LRBP1));
hold on
semilogx(f, rad2deg(phase_LRBP2));
semilogx(f, rad2deg(phase_LRBP3));
semilogx(f, rad2deg(phase_LRBP4));
semilogx(f, rad2deg(phase_LRBP_ges));
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘Phase (Grad)’);
figure;
% Plot für die groupdelay
semilogx(f, groupdelay_LRBP1);
hold on
semilogx(f, groupdelay_LRBP2);
semilogx(f, groupdelay_LRBP3);
semilogx(f, groupdelay_LRBP4);
semilogx(f, groupdelay_LRBP_ges);
grid on;
xlabel(‘$f$’, ‘Interpreter’, ‘latex’);
ylabel(‘groupdelay’);
title(‘LRBP’, ‘Interpreter’, ‘latex’); group delay, higpass, lowpass, bandpass, crossover, groupdelay MATLAB Answers — New Questions