Tag Archives: matlab
Entering the mechanical and volumetric efficiency of a fixed displacement pump
I want to enter the mechanical and volumetric efficiency values of a fixed displacement pump in a hydraulic system within SIMScape MATLAB. I have activated the mechanical and volumetric efficiency ports from the pump’s mass variables, but I have not found a way to enter the efficiency values into those ports… I need help to adjust the efficiency values for the pumpI want to enter the mechanical and volumetric efficiency values of a fixed displacement pump in a hydraulic system within SIMScape MATLAB. I have activated the mechanical and volumetric efficiency ports from the pump’s mass variables, but I have not found a way to enter the efficiency values into those ports… I need help to adjust the efficiency values for the pump I want to enter the mechanical and volumetric efficiency values of a fixed displacement pump in a hydraulic system within SIMScape MATLAB. I have activated the mechanical and volumetric efficiency ports from the pump’s mass variables, but I have not found a way to enter the efficiency values into those ports… I need help to adjust the efficiency values for the pump efficiency control MATLAB Answers — New Questions
CRS mismatch or I do not know
I am working onI am working on I am working on notag MATLAB Answers — New Questions
Error evaluating parameter ‘Mass’ , Unable to resolve the name smiData.Solid.
I am getting error when i am, importing assembly from the invent. I am having error at the joints and also the parts imported doesn’t import data regarding inertia or geometry. When i run the simulation, I am getting this error
Caused by:
Error evaluating parameter ‘Mass’ in
Unable to resolve the name smiData.Solid.
Error evaluating parameter ‘CenterOfMass’ in ‘NewTestAssembly
Thank you
Sorry i have to hide few names due to some technical issueI am getting error when i am, importing assembly from the invent. I am having error at the joints and also the parts imported doesn’t import data regarding inertia or geometry. When i run the simulation, I am getting this error
Caused by:
Error evaluating parameter ‘Mass’ in
Unable to resolve the name smiData.Solid.
Error evaluating parameter ‘CenterOfMass’ in ‘NewTestAssembly
Thank you
Sorry i have to hide few names due to some technical issue I am getting error when i am, importing assembly from the invent. I am having error at the joints and also the parts imported doesn’t import data regarding inertia or geometry. When i run the simulation, I am getting this error
Caused by:
Error evaluating parameter ‘Mass’ in
Unable to resolve the name smiData.Solid.
Error evaluating parameter ‘CenterOfMass’ in ‘NewTestAssembly
Thank you
Sorry i have to hide few names due to some technical issue error evaluating, mass MATLAB Answers — New Questions
error when using segment function
I get these errors when running this snippet of code that references another script (script attached as a matlab file)
[filt_in, data_in_segs_corrected, segment_params]=segment_filt_v2(data_to_segment,[],[],params.genome_build);
params.segment_params=segment_params;
Warning: The data contains more columns (number of channels) than rows (number of samples). Check that the data is not transposed inadvertently.
> In ctrlMsgUtils.warning (line 25)
In segment (line 76)
In segment_filt_v2>seg_fun (line 145)
In segment_filt_v2 (line 101)
Unrecognized function or variable ‘jmax’.
Error in segment (line 236)
hh=hist(:,jmax);
Error in segment_filt_v2>seg_fun (line 145)
thm=segment([data_in(idx+1:end),ones(length(data_in)-idx,1)],[0 1 1],R2);
Error in segment_filt_v2 (line 101)
data_in_segs_corrected{Chr}(in,c-4)=seg_fun(Data{Chr}(in,c), R2);I get these errors when running this snippet of code that references another script (script attached as a matlab file)
[filt_in, data_in_segs_corrected, segment_params]=segment_filt_v2(data_to_segment,[],[],params.genome_build);
params.segment_params=segment_params;
Warning: The data contains more columns (number of channels) than rows (number of samples). Check that the data is not transposed inadvertently.
> In ctrlMsgUtils.warning (line 25)
In segment (line 76)
In segment_filt_v2>seg_fun (line 145)
In segment_filt_v2 (line 101)
Unrecognized function or variable ‘jmax’.
Error in segment (line 236)
hh=hist(:,jmax);
Error in segment_filt_v2>seg_fun (line 145)
thm=segment([data_in(idx+1:end),ones(length(data_in)-idx,1)],[0 1 1],R2);
Error in segment_filt_v2 (line 101)
data_in_segs_corrected{Chr}(in,c-4)=seg_fun(Data{Chr}(in,c), R2); I get these errors when running this snippet of code that references another script (script attached as a matlab file)
[filt_in, data_in_segs_corrected, segment_params]=segment_filt_v2(data_to_segment,[],[],params.genome_build);
params.segment_params=segment_params;
Warning: The data contains more columns (number of channels) than rows (number of samples). Check that the data is not transposed inadvertently.
> In ctrlMsgUtils.warning (line 25)
In segment (line 76)
In segment_filt_v2>seg_fun (line 145)
In segment_filt_v2 (line 101)
Unrecognized function or variable ‘jmax’.
Error in segment (line 236)
hh=hist(:,jmax);
Error in segment_filt_v2>seg_fun (line 145)
thm=segment([data_in(idx+1:end),ones(length(data_in)-idx,1)],[0 1 1],R2);
Error in segment_filt_v2 (line 101)
data_in_segs_corrected{Chr}(in,c-4)=seg_fun(Data{Chr}(in,c), R2); segment MATLAB Answers — New Questions
trying to use the command hinfsyn on a rotary inverted pendulum for stabilization analysis
Hello
I am trying to follow this paper
http://ietresearch.onlinelibrary.wiley.com/doi/epdf/10.1049/tje2.12078
I have made following code for making the system looking like this
The code is given below
A=[0 0 1 0;
0 0 0 1;
0 39.32 -14.52 0;
0 81.78 -13.98 0;];
B=[0;0;25.54;24.59];
C=[1 0 0 0;
0 1 0 0];
D=[0;0;];
sys=ss(A,B,C,D);
sys.InputName={‘u’};
sys.OutputName={‘theta’,’alpha’};
s=tf(‘s’);
Wact=0.002*(s+0.01)/(s+10);
Wact.u=’u’; Wact.y=’e1′;
Wn1=ss(0.05);
Wn1.u=’d1′; Wn1.y=’wn1′;
Wn2=ss(0.0275);
Wn2.u=’d2′; Wn2.y=’wn2′;
Wx1=151.5/(s+50.5);
Wx1.u=’theta’; Wx1.y=’e2′;
Wx2=202/(s+50.5);
Wx2.u=’alpha’; Wx2.y=’e3′;
sdmeas=sumblk(‘y1 = theta+wn1’);
abmeas=sumblk(‘y2 = alpha+wn2’);
ICinputs={‘d1′,’d2′,’u’};
ICoutputs={‘e1′,’e2′,’e3′,’y1′,’y2’};
qsys=connect(sys,Wact,Wn1,Wn2,Wx1,Wx2,sdmeas,abmeas,ICinputs,ICoutputs);
When I am running the command hinfsyn I get following gamma
[~,~,gamma]=hinfsyn(qsys,2,1)
while in the paper they have
gamma=0.6951 in section 3.1 H-infinty controll. Where is my mistake or any solution to get the same answer as in the paper ?
Thanks for all answers
Tor Erik HaavikHello
I am trying to follow this paper
http://ietresearch.onlinelibrary.wiley.com/doi/epdf/10.1049/tje2.12078
I have made following code for making the system looking like this
The code is given below
A=[0 0 1 0;
0 0 0 1;
0 39.32 -14.52 0;
0 81.78 -13.98 0;];
B=[0;0;25.54;24.59];
C=[1 0 0 0;
0 1 0 0];
D=[0;0;];
sys=ss(A,B,C,D);
sys.InputName={‘u’};
sys.OutputName={‘theta’,’alpha’};
s=tf(‘s’);
Wact=0.002*(s+0.01)/(s+10);
Wact.u=’u’; Wact.y=’e1′;
Wn1=ss(0.05);
Wn1.u=’d1′; Wn1.y=’wn1′;
Wn2=ss(0.0275);
Wn2.u=’d2′; Wn2.y=’wn2′;
Wx1=151.5/(s+50.5);
Wx1.u=’theta’; Wx1.y=’e2′;
Wx2=202/(s+50.5);
Wx2.u=’alpha’; Wx2.y=’e3′;
sdmeas=sumblk(‘y1 = theta+wn1’);
abmeas=sumblk(‘y2 = alpha+wn2’);
ICinputs={‘d1′,’d2′,’u’};
ICoutputs={‘e1′,’e2′,’e3′,’y1′,’y2’};
qsys=connect(sys,Wact,Wn1,Wn2,Wx1,Wx2,sdmeas,abmeas,ICinputs,ICoutputs);
When I am running the command hinfsyn I get following gamma
[~,~,gamma]=hinfsyn(qsys,2,1)
while in the paper they have
gamma=0.6951 in section 3.1 H-infinty controll. Where is my mistake or any solution to get the same answer as in the paper ?
Thanks for all answers
Tor Erik Haavik Hello
I am trying to follow this paper
http://ietresearch.onlinelibrary.wiley.com/doi/epdf/10.1049/tje2.12078
I have made following code for making the system looking like this
The code is given below
A=[0 0 1 0;
0 0 0 1;
0 39.32 -14.52 0;
0 81.78 -13.98 0;];
B=[0;0;25.54;24.59];
C=[1 0 0 0;
0 1 0 0];
D=[0;0;];
sys=ss(A,B,C,D);
sys.InputName={‘u’};
sys.OutputName={‘theta’,’alpha’};
s=tf(‘s’);
Wact=0.002*(s+0.01)/(s+10);
Wact.u=’u’; Wact.y=’e1′;
Wn1=ss(0.05);
Wn1.u=’d1′; Wn1.y=’wn1′;
Wn2=ss(0.0275);
Wn2.u=’d2′; Wn2.y=’wn2′;
Wx1=151.5/(s+50.5);
Wx1.u=’theta’; Wx1.y=’e2′;
Wx2=202/(s+50.5);
Wx2.u=’alpha’; Wx2.y=’e3′;
sdmeas=sumblk(‘y1 = theta+wn1’);
abmeas=sumblk(‘y2 = alpha+wn2’);
ICinputs={‘d1′,’d2′,’u’};
ICoutputs={‘e1′,’e2′,’e3′,’y1′,’y2’};
qsys=connect(sys,Wact,Wn1,Wn2,Wx1,Wx2,sdmeas,abmeas,ICinputs,ICoutputs);
When I am running the command hinfsyn I get following gamma
[~,~,gamma]=hinfsyn(qsys,2,1)
while in the paper they have
gamma=0.6951 in section 3.1 H-infinty controll. Where is my mistake or any solution to get the same answer as in the paper ?
Thanks for all answers
Tor Erik Haavik matlab code, control system, roboust control system MATLAB Answers — New Questions
tiledlayout doesn’t behave as it should
Followed the example of https://www.mathworks.com/help/matlab/ref/tiledlayout.html with ‘TileSpacing’, ‘none’option. The output is as image shown with huge gap in rows.
row = 8;
col = 5;
figure
tiledlayout(row,col,’TileSpacing’,’none’);
for ns = 1:nums
nexttile
imagesc(images(:,:,ns));colormap gray;axis off; axis square
endFollowed the example of https://www.mathworks.com/help/matlab/ref/tiledlayout.html with ‘TileSpacing’, ‘none’option. The output is as image shown with huge gap in rows.
row = 8;
col = 5;
figure
tiledlayout(row,col,’TileSpacing’,’none’);
for ns = 1:nums
nexttile
imagesc(images(:,:,ns));colormap gray;axis off; axis square
end Followed the example of https://www.mathworks.com/help/matlab/ref/tiledlayout.html with ‘TileSpacing’, ‘none’option. The output is as image shown with huge gap in rows.
row = 8;
col = 5;
figure
tiledlayout(row,col,’TileSpacing’,’none’);
for ns = 1:nums
nexttile
imagesc(images(:,:,ns));colormap gray;axis off; axis square
end tiledlayout, matlab MATLAB Answers — New Questions
How do I reconnect USB serial that gets lost programatically.
MatLab R2024b using AppDesigner on Windows 10 Enterprise
My GUI app connects to an Arduino which sometimes looses it’s connection or reboots itself.
I’m trying to detect when connection is lost and reconnect, but after getting an error message in the Command Window:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
My program (at least interacting with it in the CW is hung until I Ctrl-C.
I have set a dummy breakpoint so I can see variables from the Command Window (It doesn’t seem to know anything about my app until I break, but at least the program still runs after the break button is pushed)
So here’s what happens in CW with my comments added in bold and extra blank lines removed:
2513 pause(0.5); Pressed the Break Button
K>> app.PicoCom Look at my Serial Port connection
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
NumBytesAvailable: 0
etc… Now I reboot my Arduino and get:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
K>> app.PicoCom Try to look at serial port (or do ANYTHING)
[CW hangs until I hit Ctrl-C – WHY?
Operation terminated by user during MouseOdor61/RunOneTrial (line 1131)
In MouseOdor61/DoSession (line 1238)
etc
In matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 60)
newCallback = @(source, event)executeCallback(ams, …
^^^^^^^^^^^^^^^^^^^^^^^^
Interrupt while evaluating Button PrivateButtonPushedFcn.
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter
{0}.
Now I can try to see the handle again.
K>> app.PicoCom
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for
parameter {0}.
Not very helpful. At this point I can see:
K>> serialportlist()
ans =
1×2 string array
"COM1" "COM11"
To recover this seems to work:
K>> delete(app.PicoCom)
Let’s check
K>> app.PicoCom
ans =
handle to deleted Serialport
Reconnect
K>> app.PicoCom = serialport
[ shows every object in app! If I don’t add the ;]
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
Tag: ""
NumBytesAvailable: 0
OK, it’s back, all I need to add, it appears is the callback
K>> configureCallback(app.PicoCom,"terminator",@app.PicoInput)
I’ve tried putting things in my callback for input (like try … catch) but it never gets there.
It’s stuck in matlab.apps.AppBase not my code
I also added checks in the output routine to the Arduino, but it doesn’t seem to be helpful. That thread is stuck! I can press another button in the app the forces a reconnect but I want it to happen without user intervention.
How can I detect and trap the loss of COM in my program? (Obviously I want to stop the Pico from rebooting, but meanwhile my users need some decent work around).MatLab R2024b using AppDesigner on Windows 10 Enterprise
My GUI app connects to an Arduino which sometimes looses it’s connection or reboots itself.
I’m trying to detect when connection is lost and reconnect, but after getting an error message in the Command Window:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
My program (at least interacting with it in the CW is hung until I Ctrl-C.
I have set a dummy breakpoint so I can see variables from the Command Window (It doesn’t seem to know anything about my app until I break, but at least the program still runs after the break button is pushed)
So here’s what happens in CW with my comments added in bold and extra blank lines removed:
2513 pause(0.5); Pressed the Break Button
K>> app.PicoCom Look at my Serial Port connection
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
NumBytesAvailable: 0
etc… Now I reboot my Arduino and get:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
K>> app.PicoCom Try to look at serial port (or do ANYTHING)
[CW hangs until I hit Ctrl-C – WHY?
Operation terminated by user during MouseOdor61/RunOneTrial (line 1131)
In MouseOdor61/DoSession (line 1238)
etc
In matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 60)
newCallback = @(source, event)executeCallback(ams, …
^^^^^^^^^^^^^^^^^^^^^^^^
Interrupt while evaluating Button PrivateButtonPushedFcn.
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter
{0}.
Now I can try to see the handle again.
K>> app.PicoCom
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for
parameter {0}.
Not very helpful. At this point I can see:
K>> serialportlist()
ans =
1×2 string array
"COM1" "COM11"
To recover this seems to work:
K>> delete(app.PicoCom)
Let’s check
K>> app.PicoCom
ans =
handle to deleted Serialport
Reconnect
K>> app.PicoCom = serialport
[ shows every object in app! If I don’t add the ;]
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
Tag: ""
NumBytesAvailable: 0
OK, it’s back, all I need to add, it appears is the callback
K>> configureCallback(app.PicoCom,"terminator",@app.PicoInput)
I’ve tried putting things in my callback for input (like try … catch) but it never gets there.
It’s stuck in matlab.apps.AppBase not my code
I also added checks in the output routine to the Arduino, but it doesn’t seem to be helpful. That thread is stuck! I can press another button in the app the forces a reconnect but I want it to happen without user intervention.
How can I detect and trap the loss of COM in my program? (Obviously I want to stop the Pico from rebooting, but meanwhile my users need some decent work around). MatLab R2024b using AppDesigner on Windows 10 Enterprise
My GUI app connects to an Arduino which sometimes looses it’s connection or reboots itself.
I’m trying to detect when connection is lost and reconnect, but after getting an error message in the Command Window:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
My program (at least interacting with it in the CW is hung until I Ctrl-C.
I have set a dummy breakpoint so I can see variables from the Command Window (It doesn’t seem to know anything about my app until I break, but at least the program still runs after the break button is pushed)
So here’s what happens in CW with my comments added in bold and extra blank lines removed:
2513 pause(0.5); Pressed the Break Button
K>> app.PicoCom Look at my Serial Port connection
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
NumBytesAvailable: 0
etc… Now I reboot my Arduino and get:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
K>> app.PicoCom Try to look at serial port (or do ANYTHING)
[CW hangs until I hit Ctrl-C – WHY?
Operation terminated by user during MouseOdor61/RunOneTrial (line 1131)
In MouseOdor61/DoSession (line 1238)
etc
In matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 60)
newCallback = @(source, event)executeCallback(ams, …
^^^^^^^^^^^^^^^^^^^^^^^^
Interrupt while evaluating Button PrivateButtonPushedFcn.
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter
{0}.
Now I can try to see the handle again.
K>> app.PicoCom
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for
parameter {0}.
Not very helpful. At this point I can see:
K>> serialportlist()
ans =
1×2 string array
"COM1" "COM11"
To recover this seems to work:
K>> delete(app.PicoCom)
Let’s check
K>> app.PicoCom
ans =
handle to deleted Serialport
Reconnect
K>> app.PicoCom = serialport
[ shows every object in app! If I don’t add the ;]
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
Tag: ""
NumBytesAvailable: 0
OK, it’s back, all I need to add, it appears is the callback
K>> configureCallback(app.PicoCom,"terminator",@app.PicoInput)
I’ve tried putting things in my callback for input (like try … catch) but it never gets there.
It’s stuck in matlab.apps.AppBase not my code
I also added checks in the output routine to the Arduino, but it doesn’t seem to be helpful. That thread is stuck! I can press another button in the app the forces a reconnect but I want it to happen without user intervention.
How can I detect and trap the loss of COM in my program? (Obviously I want to stop the Pico from rebooting, but meanwhile my users need some decent work around). reconnect usb MATLAB Answers — New Questions
Matlab editor has low quality compared to simulink and other windows on Arch linux
Using matlab on arch linux leads to very low quality graphics, I tried following "matlab support high dpi screends on linux", however it did not fix my issue
I tried changing the fonts to make it more readible, but that doesn’t completely work.
Even stranger, the editor seems perfectly fine, it’s just everything else that is low quality
Simulink looks much nicer, and it is readable, might have to zoom in to compare the two pictures
Could the issue be that I am using wayland instead of xorg, which is why the other tutorial wasn’t working?Using matlab on arch linux leads to very low quality graphics, I tried following "matlab support high dpi screends on linux", however it did not fix my issue
I tried changing the fonts to make it more readible, but that doesn’t completely work.
Even stranger, the editor seems perfectly fine, it’s just everything else that is low quality
Simulink looks much nicer, and it is readable, might have to zoom in to compare the two pictures
Could the issue be that I am using wayland instead of xorg, which is why the other tutorial wasn’t working? Using matlab on arch linux leads to very low quality graphics, I tried following "matlab support high dpi screends on linux", however it did not fix my issue
I tried changing the fonts to make it more readible, but that doesn’t completely work.
Even stranger, the editor seems perfectly fine, it’s just everything else that is low quality
Simulink looks much nicer, and it is readable, might have to zoom in to compare the two pictures
Could the issue be that I am using wayland instead of xorg, which is why the other tutorial wasn’t working? linux, display MATLAB Answers — New Questions
MATLAB Coder Onramp Issue – Section 4 Call C Code from MATLAB
Hi all,
I am currently running through some of the learning materails online for both MATLAB and Simulink. I have started going over the MATLAB Coder Onramp which goes through the mecanisms for generating C code from MATLAB. This is using the website based version of the courses and as such the MATLAB environement is within the web browser itself.
However, I seem to be stuck at section 4 "Call C Code From MATLAB – Verify Generated Code". The task asks the following,
To generate a MEX function, you don’t need to specify a configuration because the codegen function generates MEX by default.
codegen fcn -args {var} -report
If your function has input arguments and you want a code generation report, you can continue using ‑args and ‑report.
Task
Generate MEX code for the detectpH function. Use I2 as the example input.
The code may take up to ten seconds to generate.
Now I have added my result and compared this to the "See Solution" and it is the same
codegen detectpH -args {I2} -report
However, when I select Submit, I get an error using Codegen. I have cleared my entry, closed and reopened the course and even copied and pasted the result from the "See Solution" too to make sure there were no spelling mistakes but still no luck.
I am wondering if this is an issue to do with the in browser environment perhaps?
I did have issues with generating the C code earlier in the course, but as the training allowed me to continune, I assumed this was going to be dealt with in the next sections.
Hopefully I am doing something daft and its a simple fix.
I have attached the Build Log for additional infromation.
Thanks,
JasonHi all,
I am currently running through some of the learning materails online for both MATLAB and Simulink. I have started going over the MATLAB Coder Onramp which goes through the mecanisms for generating C code from MATLAB. This is using the website based version of the courses and as such the MATLAB environement is within the web browser itself.
However, I seem to be stuck at section 4 "Call C Code From MATLAB – Verify Generated Code". The task asks the following,
To generate a MEX function, you don’t need to specify a configuration because the codegen function generates MEX by default.
codegen fcn -args {var} -report
If your function has input arguments and you want a code generation report, you can continue using ‑args and ‑report.
Task
Generate MEX code for the detectpH function. Use I2 as the example input.
The code may take up to ten seconds to generate.
Now I have added my result and compared this to the "See Solution" and it is the same
codegen detectpH -args {I2} -report
However, when I select Submit, I get an error using Codegen. I have cleared my entry, closed and reopened the course and even copied and pasted the result from the "See Solution" too to make sure there were no spelling mistakes but still no luck.
I am wondering if this is an issue to do with the in browser environment perhaps?
I did have issues with generating the C code earlier in the course, but as the training allowed me to continune, I assumed this was going to be dealt with in the next sections.
Hopefully I am doing something daft and its a simple fix.
I have attached the Build Log for additional infromation.
Thanks,
Jason Hi all,
I am currently running through some of the learning materails online for both MATLAB and Simulink. I have started going over the MATLAB Coder Onramp which goes through the mecanisms for generating C code from MATLAB. This is using the website based version of the courses and as such the MATLAB environement is within the web browser itself.
However, I seem to be stuck at section 4 "Call C Code From MATLAB – Verify Generated Code". The task asks the following,
To generate a MEX function, you don’t need to specify a configuration because the codegen function generates MEX by default.
codegen fcn -args {var} -report
If your function has input arguments and you want a code generation report, you can continue using ‑args and ‑report.
Task
Generate MEX code for the detectpH function. Use I2 as the example input.
The code may take up to ten seconds to generate.
Now I have added my result and compared this to the "See Solution" and it is the same
codegen detectpH -args {I2} -report
However, when I select Submit, I get an error using Codegen. I have cleared my entry, closed and reopened the course and even copied and pasted the result from the "See Solution" too to make sure there were no spelling mistakes but still no luck.
I am wondering if this is an issue to do with the in browser environment perhaps?
I did have issues with generating the C code earlier in the course, but as the training allowed me to continune, I assumed this was going to be dealt with in the next sections.
Hopefully I am doing something daft and its a simple fix.
I have attached the Build Log for additional infromation.
Thanks,
Jason onramp, matlab coder, codegen, code generation MATLAB Answers — New Questions
I want to use a low-pass filter to cut off frequencies above the cutoff frequency.
I am trying to cut frequencies above the cutoff frequency using the lowpass function, but it is not working.
I am trying to cut the frequency by applying a lowpass filter to the tunnel current z multiplied by the reference signal sin(wt).
The cutoff frequency is set at 500 Hz, so when I graph the FFT, the peaks at frequencies higher than 500 Hz should disappear, but they do not.
%Parameter Setting
pixel_image = 256; %Input the number of pixels in the image obtained by raster scanning (input 2^n)
dr = 1/(2*sqrt(3)); %Enter dither circle radius [grid].
a_fast_grid = 10; %fast axis scanning range [grid]
a_slow_grid = 10; %Slow axis scanning range [grid]
fm=5000; %Dither circle modulation frequency [Hz]
fs= fm*240 ; %Sampling frequency [Hz]
f_fast = 10.2; %Input scanning frequency [Hz] (1 line scanning count in 1[s])
start_point_x = 0; %Input x-coordinate of scanning start point (input 1 if you want to move by 1[grid])
start_point_y = 0; %Input y-coordinate of scanning start point (input 1 if you want to move by 1[grid])
%Parameter setting for fast-axis triangular wave
amplitude_fast = a_fast_grid/2; %fast axis amplitude
%Parameter setting for slow-axis triangular wave
amplitude_slow = a_slow_grid/2; %slow axis amplitude
f_slow = (f_fast)/(2*pixel_image); %Slow axis triangular wave frequency
% Generation of time vectors
total_time=256/f_fast; %Total Scan Time
t = linspace(0, total_time, fs * total_time);
x_raster = start_point_x + amplitude_fast*(2/pi)*acos(cos(2*pi*f_fast*t));
y_raster = start_point_y + amplitude_slow*(2/pi)*acos(cos(2*pi*f_slow*t));
x_dither = dr*cos(2*pi*fm*t);
y_dither = dr*sin(2*pi*fm*t);
x = x_raster + x_dither;
y = y_raster + y_dither;
z1 = cos(2*pi*((x-y)/(sqrt(3))));
z2 = cos(2*pi*(2*y/(sqrt(3))));
z3 = cos(2*pi*((x+y)/(sqrt(3))));
z = (z1 + z2 + z3);
%Reference Signal Creation
w = 2*pi*fm ;
phi = 0 ;
reference_signal = sin(w*t+phi) ;
%Mixing signal creation
mixising_signal = z.* reference_signal ;
%Applying a low-pass filter
f_cutoff = 500 ; %Cutoff frequency [Hz] setting
lowpass_signal = lowpass(mixising_signal,f_cutoff,fs) ;
%The result of FFT.——————————————-
n = length(t); % Number of samples
f = (0:n-1)*(fs/n); % Frequency axis [Hz]
half_n = floor(n/2); % Half of data
fft_z = abs(fft(z) / n);
fft_mixising_signal = abs(fft(mixising_signal) / n);
fft_lowpass_signal = abs(fft(lowpass_signal) / n);
figure;
tiledlayout(3,1)
nexttile
plot(f(1:half_n), fft_z(1:half_n));
title(‘FFT of tunnel current’); xlabel(‘Frequency [Hz]’); ylabel(‘Amplitude’);
xlim([0 20000]),ylim([0 0.3]);
nexttile
plot(f(1:half_n), fft_mixising_signal(1:half_n));
title(‘FFT of mixing signal’); xlabel(‘Frequency [Hz]’); ylabel(‘Amplitude’);
xlim([0 20000]),ylim([0 0.3]);
nexttile
plot(f(1:half_n), fft_lowpass_signal(1:half_n));
title(‘FFT after applying low-pass’); xlabel(‘Frequency [Hz]’); ylabel(‘Amplitude’);
xlim([0 20000]),ylim([0 0.3]);I am trying to cut frequencies above the cutoff frequency using the lowpass function, but it is not working.
I am trying to cut the frequency by applying a lowpass filter to the tunnel current z multiplied by the reference signal sin(wt).
The cutoff frequency is set at 500 Hz, so when I graph the FFT, the peaks at frequencies higher than 500 Hz should disappear, but they do not.
%Parameter Setting
pixel_image = 256; %Input the number of pixels in the image obtained by raster scanning (input 2^n)
dr = 1/(2*sqrt(3)); %Enter dither circle radius [grid].
a_fast_grid = 10; %fast axis scanning range [grid]
a_slow_grid = 10; %Slow axis scanning range [grid]
fm=5000; %Dither circle modulation frequency [Hz]
fs= fm*240 ; %Sampling frequency [Hz]
f_fast = 10.2; %Input scanning frequency [Hz] (1 line scanning count in 1[s])
start_point_x = 0; %Input x-coordinate of scanning start point (input 1 if you want to move by 1[grid])
start_point_y = 0; %Input y-coordinate of scanning start point (input 1 if you want to move by 1[grid])
%Parameter setting for fast-axis triangular wave
amplitude_fast = a_fast_grid/2; %fast axis amplitude
%Parameter setting for slow-axis triangular wave
amplitude_slow = a_slow_grid/2; %slow axis amplitude
f_slow = (f_fast)/(2*pixel_image); %Slow axis triangular wave frequency
% Generation of time vectors
total_time=256/f_fast; %Total Scan Time
t = linspace(0, total_time, fs * total_time);
x_raster = start_point_x + amplitude_fast*(2/pi)*acos(cos(2*pi*f_fast*t));
y_raster = start_point_y + amplitude_slow*(2/pi)*acos(cos(2*pi*f_slow*t));
x_dither = dr*cos(2*pi*fm*t);
y_dither = dr*sin(2*pi*fm*t);
x = x_raster + x_dither;
y = y_raster + y_dither;
z1 = cos(2*pi*((x-y)/(sqrt(3))));
z2 = cos(2*pi*(2*y/(sqrt(3))));
z3 = cos(2*pi*((x+y)/(sqrt(3))));
z = (z1 + z2 + z3);
%Reference Signal Creation
w = 2*pi*fm ;
phi = 0 ;
reference_signal = sin(w*t+phi) ;
%Mixing signal creation
mixising_signal = z.* reference_signal ;
%Applying a low-pass filter
f_cutoff = 500 ; %Cutoff frequency [Hz] setting
lowpass_signal = lowpass(mixising_signal,f_cutoff,fs) ;
%The result of FFT.——————————————-
n = length(t); % Number of samples
f = (0:n-1)*(fs/n); % Frequency axis [Hz]
half_n = floor(n/2); % Half of data
fft_z = abs(fft(z) / n);
fft_mixising_signal = abs(fft(mixising_signal) / n);
fft_lowpass_signal = abs(fft(lowpass_signal) / n);
figure;
tiledlayout(3,1)
nexttile
plot(f(1:half_n), fft_z(1:half_n));
title(‘FFT of tunnel current’); xlabel(‘Frequency [Hz]’); ylabel(‘Amplitude’);
xlim([0 20000]),ylim([0 0.3]);
nexttile
plot(f(1:half_n), fft_mixising_signal(1:half_n));
title(‘FFT of mixing signal’); xlabel(‘Frequency [Hz]’); ylabel(‘Amplitude’);
xlim([0 20000]),ylim([0 0.3]);
nexttile
plot(f(1:half_n), fft_lowpass_signal(1:half_n));
title(‘FFT after applying low-pass’); xlabel(‘Frequency [Hz]’); ylabel(‘Amplitude’);
xlim([0 20000]),ylim([0 0.3]); I am trying to cut frequencies above the cutoff frequency using the lowpass function, but it is not working.
I am trying to cut the frequency by applying a lowpass filter to the tunnel current z multiplied by the reference signal sin(wt).
The cutoff frequency is set at 500 Hz, so when I graph the FFT, the peaks at frequencies higher than 500 Hz should disappear, but they do not.
%Parameter Setting
pixel_image = 256; %Input the number of pixels in the image obtained by raster scanning (input 2^n)
dr = 1/(2*sqrt(3)); %Enter dither circle radius [grid].
a_fast_grid = 10; %fast axis scanning range [grid]
a_slow_grid = 10; %Slow axis scanning range [grid]
fm=5000; %Dither circle modulation frequency [Hz]
fs= fm*240 ; %Sampling frequency [Hz]
f_fast = 10.2; %Input scanning frequency [Hz] (1 line scanning count in 1[s])
start_point_x = 0; %Input x-coordinate of scanning start point (input 1 if you want to move by 1[grid])
start_point_y = 0; %Input y-coordinate of scanning start point (input 1 if you want to move by 1[grid])
%Parameter setting for fast-axis triangular wave
amplitude_fast = a_fast_grid/2; %fast axis amplitude
%Parameter setting for slow-axis triangular wave
amplitude_slow = a_slow_grid/2; %slow axis amplitude
f_slow = (f_fast)/(2*pixel_image); %Slow axis triangular wave frequency
% Generation of time vectors
total_time=256/f_fast; %Total Scan Time
t = linspace(0, total_time, fs * total_time);
x_raster = start_point_x + amplitude_fast*(2/pi)*acos(cos(2*pi*f_fast*t));
y_raster = start_point_y + amplitude_slow*(2/pi)*acos(cos(2*pi*f_slow*t));
x_dither = dr*cos(2*pi*fm*t);
y_dither = dr*sin(2*pi*fm*t);
x = x_raster + x_dither;
y = y_raster + y_dither;
z1 = cos(2*pi*((x-y)/(sqrt(3))));
z2 = cos(2*pi*(2*y/(sqrt(3))));
z3 = cos(2*pi*((x+y)/(sqrt(3))));
z = (z1 + z2 + z3);
%Reference Signal Creation
w = 2*pi*fm ;
phi = 0 ;
reference_signal = sin(w*t+phi) ;
%Mixing signal creation
mixising_signal = z.* reference_signal ;
%Applying a low-pass filter
f_cutoff = 500 ; %Cutoff frequency [Hz] setting
lowpass_signal = lowpass(mixising_signal,f_cutoff,fs) ;
%The result of FFT.——————————————-
n = length(t); % Number of samples
f = (0:n-1)*(fs/n); % Frequency axis [Hz]
half_n = floor(n/2); % Half of data
fft_z = abs(fft(z) / n);
fft_mixising_signal = abs(fft(mixising_signal) / n);
fft_lowpass_signal = abs(fft(lowpass_signal) / n);
figure;
tiledlayout(3,1)
nexttile
plot(f(1:half_n), fft_z(1:half_n));
title(‘FFT of tunnel current’); xlabel(‘Frequency [Hz]’); ylabel(‘Amplitude’);
xlim([0 20000]),ylim([0 0.3]);
nexttile
plot(f(1:half_n), fft_mixising_signal(1:half_n));
title(‘FFT of mixing signal’); xlabel(‘Frequency [Hz]’); ylabel(‘Amplitude’);
xlim([0 20000]),ylim([0 0.3]);
nexttile
plot(f(1:half_n), fft_lowpass_signal(1:half_n));
title(‘FFT after applying low-pass’); xlabel(‘Frequency [Hz]’); ylabel(‘Amplitude’);
xlim([0 20000]),ylim([0 0.3]); low pass filter, matlab, signal processing MATLAB Answers — New Questions
Menubar fonts unreadably small in Linux?
This is a question which has been asked before, but to which I haven’t been able to find a satisfactory response. I’m using Matlab R2016b on Linux, with a HiDPI screen (2560×1440) on a laptop – so a lot of pixels squeezed into a small space. And the standard menu fonts are tiny – so tiny that I have to squint carefully to read them.
I understand this to be in some way related to the Java system that Matlab uses for its GUI, but I have no idea how to increase the size of the menubar/toolbar fonts and icons. It’s not included in Matlab’s preferences; from my reading I believe that these are picked up somehow from the underlying OS. Or more accurately, from the underlying Java engine.
Currently, if I want to use Matlab with readable menus, I have to change my desktop resolution to a lower one, which of course affects every other application. So I’m hoping there’s a better way?
Thanks!This is a question which has been asked before, but to which I haven’t been able to find a satisfactory response. I’m using Matlab R2016b on Linux, with a HiDPI screen (2560×1440) on a laptop – so a lot of pixels squeezed into a small space. And the standard menu fonts are tiny – so tiny that I have to squint carefully to read them.
I understand this to be in some way related to the Java system that Matlab uses for its GUI, but I have no idea how to increase the size of the menubar/toolbar fonts and icons. It’s not included in Matlab’s preferences; from my reading I believe that these are picked up somehow from the underlying OS. Or more accurately, from the underlying Java engine.
Currently, if I want to use Matlab with readable menus, I have to change my desktop resolution to a lower one, which of course affects every other application. So I’m hoping there’s a better way?
Thanks! This is a question which has been asked before, but to which I haven’t been able to find a satisfactory response. I’m using Matlab R2016b on Linux, with a HiDPI screen (2560×1440) on a laptop – so a lot of pixels squeezed into a small space. And the standard menu fonts are tiny – so tiny that I have to squint carefully to read them.
I understand this to be in some way related to the Java system that Matlab uses for its GUI, but I have no idea how to increase the size of the menubar/toolbar fonts and icons. It’s not included in Matlab’s preferences; from my reading I believe that these are picked up somehow from the underlying OS. Or more accurately, from the underlying Java engine.
Currently, if I want to use Matlab with readable menus, I have to change my desktop resolution to a lower one, which of course affects every other application. So I’m hoping there’s a better way?
Thanks! desktop, menu fonts, icons, java MATLAB Answers — New Questions
Where I make a mistake with fminimax?
Dear colleagues,
I have problem with optimisation function fminimax, which I use as a variant for regression analyses made by Curve fitter.
In the attached file are the vectors for x, y and z = f(x,y).
My code is, as follow. Sorry, I don’t know how to paste it in appropriate format:
"x=x_vremetraene;
y=y_period_pretovarvane;
z=z_111;
f = @(p) abs(p(1)*(p(2)+y).^p(3)./(x+p(4)).^p(5) – z);
F = @(p) reshape(f(p),[],1);
p0 = [1 1 1 1 1];
F(p0)
ans =
1.0e+02 *
2.314576069270182
2.796122919180851
3.081916551260510
3.284514792242277
3.441464927295814
3.926826269823946
1.650257401771352
………………………..
%by this point everything is good
format long
[p,fval] = fminimax(F,p0)
Local minimum possible. Constraints satisfied.
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
satisfied to within the value of the constraint tolerance.
<stopping criteria details>
p =
1.0e+03 *
-0.320589519017169 -2.281076321933144 -0.703130918618337 -0.366998883941303 1.591728772382496
fval =
1.0e+02 *
2.317909402603515
2.801122919180851
3.088583217927177
………"
%The expected values for fval should be about 20. But they are as large as input z data.
Local minimum possible. Constraints satisfied.
I have tried p = lsqnonlin(F,p0) for preestimation of the parameters p
but it also gives me an error message.
Error using lsqncommon (line 38)
Objective function is returning Inf or NaN values at initial point. lsqnonlin cannot continue.
Error in lsqnonlin (line 264)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,caller,…
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Dear colleagues,
I have problem with optimisation function fminimax, which I use as a variant for regression analyses made by Curve fitter.
In the attached file are the vectors for x, y and z = f(x,y).
My code is, as follow. Sorry, I don’t know how to paste it in appropriate format:
"x=x_vremetraene;
y=y_period_pretovarvane;
z=z_111;
f = @(p) abs(p(1)*(p(2)+y).^p(3)./(x+p(4)).^p(5) – z);
F = @(p) reshape(f(p),[],1);
p0 = [1 1 1 1 1];
F(p0)
ans =
1.0e+02 *
2.314576069270182
2.796122919180851
3.081916551260510
3.284514792242277
3.441464927295814
3.926826269823946
1.650257401771352
………………………..
%by this point everything is good
format long
[p,fval] = fminimax(F,p0)
Local minimum possible. Constraints satisfied.
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
satisfied to within the value of the constraint tolerance.
<stopping criteria details>
p =
1.0e+03 *
-0.320589519017169 -2.281076321933144 -0.703130918618337 -0.366998883941303 1.591728772382496
fval =
1.0e+02 *
2.317909402603515
2.801122919180851
3.088583217927177
………"
%The expected values for fval should be about 20. But they are as large as input z data.
Local minimum possible. Constraints satisfied.
I have tried p = lsqnonlin(F,p0) for preestimation of the parameters p
but it also gives me an error message.
Error using lsqncommon (line 38)
Objective function is returning Inf or NaN values at initial point. lsqnonlin cannot continue.
Error in lsqnonlin (line 264)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,caller,…
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Dear colleagues,
I have problem with optimisation function fminimax, which I use as a variant for regression analyses made by Curve fitter.
In the attached file are the vectors for x, y and z = f(x,y).
My code is, as follow. Sorry, I don’t know how to paste it in appropriate format:
"x=x_vremetraene;
y=y_period_pretovarvane;
z=z_111;
f = @(p) abs(p(1)*(p(2)+y).^p(3)./(x+p(4)).^p(5) – z);
F = @(p) reshape(f(p),[],1);
p0 = [1 1 1 1 1];
F(p0)
ans =
1.0e+02 *
2.314576069270182
2.796122919180851
3.081916551260510
3.284514792242277
3.441464927295814
3.926826269823946
1.650257401771352
………………………..
%by this point everything is good
format long
[p,fval] = fminimax(F,p0)
Local minimum possible. Constraints satisfied.
fminimax stopped because the size of the current search direction is less than
twice the value of the step size tolerance and constraints are
satisfied to within the value of the constraint tolerance.
<stopping criteria details>
p =
1.0e+03 *
-0.320589519017169 -2.281076321933144 -0.703130918618337 -0.366998883941303 1.591728772382496
fval =
1.0e+02 *
2.317909402603515
2.801122919180851
3.088583217927177
………"
%The expected values for fval should be about 20. But they are as large as input z data.
Local minimum possible. Constraints satisfied.
I have tried p = lsqnonlin(F,p0) for preestimation of the parameters p
but it also gives me an error message.
Error using lsqncommon (line 38)
Objective function is returning Inf or NaN values at initial point. lsqnonlin cannot continue.
Error in lsqnonlin (line 264)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,caller,…
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ fminimax MATLAB Answers — New Questions
how can i write the follwoing matrix [0 1 2 3;0 1 2 3;3 2 1 0;3 2 1 0] as a code defined in the groub Z_4
.. . complete matlab code MATLAB Answers — New Questions
Find the bandwidth of a signal
How can I find the bandwidth of the signal in the attached picture?How can I find the bandwidth of the signal in the attached picture? How can I find the bandwidth of the signal in the attached picture? digital signal processing MATLAB Answers — New Questions
Hi guys. How can I have display a color from RGB coordinates?
What I’d like to do is to print a color starting from its RGB coordinates. Like MS Paint tool, more or less. There already exists a tool in Matlab? ThanksWhat I’d like to do is to print a color starting from its RGB coordinates. Like MS Paint tool, more or less. There already exists a tool in Matlab? Thanks What I’d like to do is to print a color starting from its RGB coordinates. Like MS Paint tool, more or less. There already exists a tool in Matlab? Thanks color, rgb MATLAB Answers — New Questions
How to visualise the colour with a given set of RGB values?
Hi,
I have one set of RGB values
RGB=[85 270 100];
How to represent/visualise the colour in a say, 80 by 80 pixel colour patch?Hi,
I have one set of RGB values
RGB=[85 270 100];
How to represent/visualise the colour in a say, 80 by 80 pixel colour patch? Hi,
I have one set of RGB values
RGB=[85 270 100];
How to represent/visualise the colour in a say, 80 by 80 pixel colour patch? single set rgb, rgb visualisation MATLAB Answers — New Questions
Hi, is there a matlab function to read .grib2 files (these are files similar to netcdf but Matlab nclibraries cant seem to be able to read them) thank you
Hi,
I need to read .grib2 files fast.
I m currently using a java toolbox (njvarget) to read them but it takes a lot of time as the files are many.
Is there a way to read them faster (changing function or reformatting them?)? thank youHi,
I need to read .grib2 files fast.
I m currently using a java toolbox (njvarget) to read them but it takes a lot of time as the files are many.
Is there a way to read them faster (changing function or reformatting them?)? thank you Hi,
I need to read .grib2 files fast.
I m currently using a java toolbox (njvarget) to read them but it takes a lot of time as the files are many.
Is there a way to read them faster (changing function or reformatting them?)? thank you .grib, grib2 MATLAB Answers — New Questions
Kramers Kronig versus Hilbert
Dear Matlab community,
A quick question about Kramers-Kronig.
I am aware that KK is used extensively in optics, but here the application is slightly different. I measure a complex impedance over a frequency range. Now I’d like to run the real part as well as the imaginary part of that impedance through KK and compare the calculate the error (residuals).
This is done to see if the measurement was in equilibrium and the values measured are sensible. There are some parts of code out there that I’ve tried but they all seem to fail at some point. I found that there is the built-in function ‘hilbert’ that might just do the trick with some adjustment, but it is exactly these adjustments, that I do not know.
As the original data I have an array with col1, col2, col3 being frequency, real part of the impedance, and imaginary part of the impedance, respectively.
Here is the KK result as plotted from a commercially available software …
When running my code I get:
blue: KK
red: original data
I tend to believe that the commercial SW is working properly 🙂
If that is true, then the overall shape of my results looks alright, but there seems to be a significant shift in the x-coordinate… (to lower values)
The two pieces of code are shown below.
Input values for the calculating the imKK value are:
the real part of the impedance, re
the angular frequency, omega (which is: freq. * 2 * pi())
Input values for the calculating the reKK value are:
the NEGATIVE imaginary part of the impedance, im (as over most of the frequency range ImZ<0)
the angular frequency, omega (which is: freq. * 2 * pi())
The imKK calc is done like this:
++++++++++++++++++++++++++++
function imkk = kkre2im(re,omega)
% Perform Kramers-Kronig transform of real data re and
% angular frequencies omega to get imaginary parts. Handle
% division by zero by letting integrand be the mean
% of the adjoining values.
imkk = zeros(size(re)); % set up vector for reconstructed imag parts
N = length(re); % number of data points
warning off Matlab:divideByZero % avoid warning, since division
% for each data point, do the transform
for k = 1:N;
rek = re(k);
omegak = omega(k);
% compute the integrand
inte = (re – rek)./(omega.^2 – omegak.^2);
% handle division by zero by taking mean and end-points
% by setting equal to adjoining point
switch k
case 1
inte(k) = inte(2);
case N
inte(k) = inte(N-1);
otherwise
inte(k) = ( inte(k-1) + inte(k+1) )/2;
end
% integrate
%intecur = integrate(omega,inte);
intecur = integrate(log10(omega),inte.*omega*log(10));
% scale by constant to get final imaginary parts
imkk(k) = 2*omegak/pi*intecur;
end
warning on Matlab:divideByZero
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
The reKK calc is done like this:
++++++++++++++++++++++++++++
function rekk = kkim2re(im,omega)
% Perform Kramers-Kronig transform of imaginary data im and
% angular frequencies omega to get real parts. Handle
% division by zero by letting integrand be the mean
% of the adjoining values.
rekk = zeros(size(im)); % set up vector for reconstructed real parts
N = length(im); % number of data points
warning off Matlab:divideByZero % avoid warning, since division
% for each data point, do the transform
for k = 1:N;
imk = im(k);
omegak = omega(k);
% compute the integrand
inte = (omega.*im – omegak*imk)./(omega.^2 – omegak.^2);
% handle division by zero by taking mean and end-points
% by setting equal to adjoining point
switch k
case 1
inte(k) = inte(2);
case N
inte(k) = inte(N-1);
otherwise
inte(k) = ( inte(k-1) + inte(k+1) )/2;
end
% integrate
intecur = integrate(log10(omega),inte.*omega*log(10));
% scale by constant to get final real parts
rekk(k) = -2/pi*intecur;
end
warning on Matlab:divideByZero
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
Any suggestions as to why the results are different and (in case you also believe the results shown by the commercial software) what am I doing wrong?
The original data is like this (Again, with col1, col2, col3 being frequency, real part of the impedance, and imaginary part of the impedance, respectively):
10078.1250000000 0.00130600000000000 0.00293600000000000
8296.87500000000 0.00128000000000000 0.00241600000000000
6755.51464800000 0.00125700000000000 0.00196100000000000
5671.87500000000 0.00124500000000000 0.00163200000000000
4641.54394500000 0.00123400000000000 0.00131700000000000
3814.33813500000 0.00121800000000000 0.00106100000000000
3170.95581100000 0.00120900000000000 0.000850000000000000
2619.48535200000 0.00120900000000000 0.000663000000000000
2159.92651400000 0.00118400000000000 0.000476000000000000
1792.27941900000 0.00123500000000000 0.000333000000000000
1459.31604000000 0.00125700000000000 0.000168000000000000
1216.94714400000 0.00128500000000000 9.50000000000000e-05
998.263855000000 0.00132900000000000 -1.70000000000000e-05
824.652771000000 0.00133600000000000 -9.50000000000000e-05
676.081726000000 0.00138800000000000 -0.000189000000000000
564.236084000000 0.00142800000000000 -0.000267000000000000
460.379456000000 0.00147600000000000 -0.000349000000000000
383.522705000000 0.00152400000000000 -0.000422000000000000
315.504822000000 0.00158000000000000 -0.000500000000000000
260.416656000000 0.00164300000000000 -0.000581000000000000
217.013885000000 0.00171000000000000 -0.000662000000000000
177.556824000000 0.00179700000000000 -0.000755000000000000
146.484375000000 0.00190100000000000 -0.000845000000000000
121.228455000000 0.00201500000000000 -0.000938000000000000
100.446426000000 0.00214900000000000 -0.00102400000000000
82.7205890000000 0.00230000000000000 -0.00110900000000000
68.2645650000000 0.00247300000000000 -0.00116800000000000
56.2500000000000 0.00265000000000000 -0.00122600000000000
46.8750000000000 0.00282800000000000 -0.00126100000000000
38.4221310000000 0.00301600000000000 -0.00128000000000000
31.6722980000000 0.00320600000000000 -0.00130800000000000
26.0416680000000 0.00339900000000000 -0.00132300000000000
21.7013890000000 0.00359200000000000 -0.00131800000000000
17.7556820000000 0.00376700000000000 -0.00129100000000000
14.7405660000000 0.00393000000000000 -0.00127200000000000
12.2070310000000 0.00409400000000000 -0.00122200000000000
9.93114500000000 0.00426600000000000 -0.00116900000000000
8.22368400000000 0.00440700000000000 -0.00110700000000000
6.85307000000000 0.00446700000000000 -0.00105100000000000
5.63401500000000 0.00462400000000000 -0.00100000000000000
4.68750000000000 0.00464700000000000 -0.000957000000000000
3.82965700000000 0.00471500000000000 -0.00101000000000000
3.15869300000000 0.00470100000000000 -0.00113200000000000
2.60127600000000 0.00484600000000000 -0.00126300000000000
2.14629100000000 0.00507800000000000 -0.00141500000000000
1.76753400000000 0.00525200000000000 -0.00152900000000000
1.45393900000000 0.00559300000000000 -0.00157000000000000
1.20936500000000 0.00589200000000000 -0.00159500000000000
0.999041000000000 0.00619300000000000 -0.00156500000000000
0.820641000000000 0.00652000000000000 -0.00129400000000000
0.675822000000000 0.00654400000000000 -0.00134600000000000
0.564759000000000 0.00680100000000000 -0.00107200000000000
0.468750000000000 0.00689900000000000 -0.000870000000000000
0.384221000000000 0.00717100000000000 -0.000851000000000000
0.316723000000000 0.00713500000000000 -0.000612000000000000
0.261872000000000 0.00715500000000000 -0.000508000000000000
0.216014000000000 0.00713200000000000 -0.000361000000000000
0.178232000000000 0.00721300000000000 -0.000297000000000000
0.146944000000000 0.00732800000000000 -0.000258000000000000
0.121438000000000 0.00730000000000000 -0.000120000000000000
0.100160000000000 0.00726600000000000 -7.70000000000000e-05Dear Matlab community,
A quick question about Kramers-Kronig.
I am aware that KK is used extensively in optics, but here the application is slightly different. I measure a complex impedance over a frequency range. Now I’d like to run the real part as well as the imaginary part of that impedance through KK and compare the calculate the error (residuals).
This is done to see if the measurement was in equilibrium and the values measured are sensible. There are some parts of code out there that I’ve tried but they all seem to fail at some point. I found that there is the built-in function ‘hilbert’ that might just do the trick with some adjustment, but it is exactly these adjustments, that I do not know.
As the original data I have an array with col1, col2, col3 being frequency, real part of the impedance, and imaginary part of the impedance, respectively.
Here is the KK result as plotted from a commercially available software …
When running my code I get:
blue: KK
red: original data
I tend to believe that the commercial SW is working properly 🙂
If that is true, then the overall shape of my results looks alright, but there seems to be a significant shift in the x-coordinate… (to lower values)
The two pieces of code are shown below.
Input values for the calculating the imKK value are:
the real part of the impedance, re
the angular frequency, omega (which is: freq. * 2 * pi())
Input values for the calculating the reKK value are:
the NEGATIVE imaginary part of the impedance, im (as over most of the frequency range ImZ<0)
the angular frequency, omega (which is: freq. * 2 * pi())
The imKK calc is done like this:
++++++++++++++++++++++++++++
function imkk = kkre2im(re,omega)
% Perform Kramers-Kronig transform of real data re and
% angular frequencies omega to get imaginary parts. Handle
% division by zero by letting integrand be the mean
% of the adjoining values.
imkk = zeros(size(re)); % set up vector for reconstructed imag parts
N = length(re); % number of data points
warning off Matlab:divideByZero % avoid warning, since division
% for each data point, do the transform
for k = 1:N;
rek = re(k);
omegak = omega(k);
% compute the integrand
inte = (re – rek)./(omega.^2 – omegak.^2);
% handle division by zero by taking mean and end-points
% by setting equal to adjoining point
switch k
case 1
inte(k) = inte(2);
case N
inte(k) = inte(N-1);
otherwise
inte(k) = ( inte(k-1) + inte(k+1) )/2;
end
% integrate
%intecur = integrate(omega,inte);
intecur = integrate(log10(omega),inte.*omega*log(10));
% scale by constant to get final imaginary parts
imkk(k) = 2*omegak/pi*intecur;
end
warning on Matlab:divideByZero
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
The reKK calc is done like this:
++++++++++++++++++++++++++++
function rekk = kkim2re(im,omega)
% Perform Kramers-Kronig transform of imaginary data im and
% angular frequencies omega to get real parts. Handle
% division by zero by letting integrand be the mean
% of the adjoining values.
rekk = zeros(size(im)); % set up vector for reconstructed real parts
N = length(im); % number of data points
warning off Matlab:divideByZero % avoid warning, since division
% for each data point, do the transform
for k = 1:N;
imk = im(k);
omegak = omega(k);
% compute the integrand
inte = (omega.*im – omegak*imk)./(omega.^2 – omegak.^2);
% handle division by zero by taking mean and end-points
% by setting equal to adjoining point
switch k
case 1
inte(k) = inte(2);
case N
inte(k) = inte(N-1);
otherwise
inte(k) = ( inte(k-1) + inte(k+1) )/2;
end
% integrate
intecur = integrate(log10(omega),inte.*omega*log(10));
% scale by constant to get final real parts
rekk(k) = -2/pi*intecur;
end
warning on Matlab:divideByZero
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
Any suggestions as to why the results are different and (in case you also believe the results shown by the commercial software) what am I doing wrong?
The original data is like this (Again, with col1, col2, col3 being frequency, real part of the impedance, and imaginary part of the impedance, respectively):
10078.1250000000 0.00130600000000000 0.00293600000000000
8296.87500000000 0.00128000000000000 0.00241600000000000
6755.51464800000 0.00125700000000000 0.00196100000000000
5671.87500000000 0.00124500000000000 0.00163200000000000
4641.54394500000 0.00123400000000000 0.00131700000000000
3814.33813500000 0.00121800000000000 0.00106100000000000
3170.95581100000 0.00120900000000000 0.000850000000000000
2619.48535200000 0.00120900000000000 0.000663000000000000
2159.92651400000 0.00118400000000000 0.000476000000000000
1792.27941900000 0.00123500000000000 0.000333000000000000
1459.31604000000 0.00125700000000000 0.000168000000000000
1216.94714400000 0.00128500000000000 9.50000000000000e-05
998.263855000000 0.00132900000000000 -1.70000000000000e-05
824.652771000000 0.00133600000000000 -9.50000000000000e-05
676.081726000000 0.00138800000000000 -0.000189000000000000
564.236084000000 0.00142800000000000 -0.000267000000000000
460.379456000000 0.00147600000000000 -0.000349000000000000
383.522705000000 0.00152400000000000 -0.000422000000000000
315.504822000000 0.00158000000000000 -0.000500000000000000
260.416656000000 0.00164300000000000 -0.000581000000000000
217.013885000000 0.00171000000000000 -0.000662000000000000
177.556824000000 0.00179700000000000 -0.000755000000000000
146.484375000000 0.00190100000000000 -0.000845000000000000
121.228455000000 0.00201500000000000 -0.000938000000000000
100.446426000000 0.00214900000000000 -0.00102400000000000
82.7205890000000 0.00230000000000000 -0.00110900000000000
68.2645650000000 0.00247300000000000 -0.00116800000000000
56.2500000000000 0.00265000000000000 -0.00122600000000000
46.8750000000000 0.00282800000000000 -0.00126100000000000
38.4221310000000 0.00301600000000000 -0.00128000000000000
31.6722980000000 0.00320600000000000 -0.00130800000000000
26.0416680000000 0.00339900000000000 -0.00132300000000000
21.7013890000000 0.00359200000000000 -0.00131800000000000
17.7556820000000 0.00376700000000000 -0.00129100000000000
14.7405660000000 0.00393000000000000 -0.00127200000000000
12.2070310000000 0.00409400000000000 -0.00122200000000000
9.93114500000000 0.00426600000000000 -0.00116900000000000
8.22368400000000 0.00440700000000000 -0.00110700000000000
6.85307000000000 0.00446700000000000 -0.00105100000000000
5.63401500000000 0.00462400000000000 -0.00100000000000000
4.68750000000000 0.00464700000000000 -0.000957000000000000
3.82965700000000 0.00471500000000000 -0.00101000000000000
3.15869300000000 0.00470100000000000 -0.00113200000000000
2.60127600000000 0.00484600000000000 -0.00126300000000000
2.14629100000000 0.00507800000000000 -0.00141500000000000
1.76753400000000 0.00525200000000000 -0.00152900000000000
1.45393900000000 0.00559300000000000 -0.00157000000000000
1.20936500000000 0.00589200000000000 -0.00159500000000000
0.999041000000000 0.00619300000000000 -0.00156500000000000
0.820641000000000 0.00652000000000000 -0.00129400000000000
0.675822000000000 0.00654400000000000 -0.00134600000000000
0.564759000000000 0.00680100000000000 -0.00107200000000000
0.468750000000000 0.00689900000000000 -0.000870000000000000
0.384221000000000 0.00717100000000000 -0.000851000000000000
0.316723000000000 0.00713500000000000 -0.000612000000000000
0.261872000000000 0.00715500000000000 -0.000508000000000000
0.216014000000000 0.00713200000000000 -0.000361000000000000
0.178232000000000 0.00721300000000000 -0.000297000000000000
0.146944000000000 0.00732800000000000 -0.000258000000000000
0.121438000000000 0.00730000000000000 -0.000120000000000000
0.100160000000000 0.00726600000000000 -7.70000000000000e-05 Dear Matlab community,
A quick question about Kramers-Kronig.
I am aware that KK is used extensively in optics, but here the application is slightly different. I measure a complex impedance over a frequency range. Now I’d like to run the real part as well as the imaginary part of that impedance through KK and compare the calculate the error (residuals).
This is done to see if the measurement was in equilibrium and the values measured are sensible. There are some parts of code out there that I’ve tried but they all seem to fail at some point. I found that there is the built-in function ‘hilbert’ that might just do the trick with some adjustment, but it is exactly these adjustments, that I do not know.
As the original data I have an array with col1, col2, col3 being frequency, real part of the impedance, and imaginary part of the impedance, respectively.
Here is the KK result as plotted from a commercially available software …
When running my code I get:
blue: KK
red: original data
I tend to believe that the commercial SW is working properly 🙂
If that is true, then the overall shape of my results looks alright, but there seems to be a significant shift in the x-coordinate… (to lower values)
The two pieces of code are shown below.
Input values for the calculating the imKK value are:
the real part of the impedance, re
the angular frequency, omega (which is: freq. * 2 * pi())
Input values for the calculating the reKK value are:
the NEGATIVE imaginary part of the impedance, im (as over most of the frequency range ImZ<0)
the angular frequency, omega (which is: freq. * 2 * pi())
The imKK calc is done like this:
++++++++++++++++++++++++++++
function imkk = kkre2im(re,omega)
% Perform Kramers-Kronig transform of real data re and
% angular frequencies omega to get imaginary parts. Handle
% division by zero by letting integrand be the mean
% of the adjoining values.
imkk = zeros(size(re)); % set up vector for reconstructed imag parts
N = length(re); % number of data points
warning off Matlab:divideByZero % avoid warning, since division
% for each data point, do the transform
for k = 1:N;
rek = re(k);
omegak = omega(k);
% compute the integrand
inte = (re – rek)./(omega.^2 – omegak.^2);
% handle division by zero by taking mean and end-points
% by setting equal to adjoining point
switch k
case 1
inte(k) = inte(2);
case N
inte(k) = inte(N-1);
otherwise
inte(k) = ( inte(k-1) + inte(k+1) )/2;
end
% integrate
%intecur = integrate(omega,inte);
intecur = integrate(log10(omega),inte.*omega*log(10));
% scale by constant to get final imaginary parts
imkk(k) = 2*omegak/pi*intecur;
end
warning on Matlab:divideByZero
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
The reKK calc is done like this:
++++++++++++++++++++++++++++
function rekk = kkim2re(im,omega)
% Perform Kramers-Kronig transform of imaginary data im and
% angular frequencies omega to get real parts. Handle
% division by zero by letting integrand be the mean
% of the adjoining values.
rekk = zeros(size(im)); % set up vector for reconstructed real parts
N = length(im); % number of data points
warning off Matlab:divideByZero % avoid warning, since division
% for each data point, do the transform
for k = 1:N;
imk = im(k);
omegak = omega(k);
% compute the integrand
inte = (omega.*im – omegak*imk)./(omega.^2 – omegak.^2);
% handle division by zero by taking mean and end-points
% by setting equal to adjoining point
switch k
case 1
inte(k) = inte(2);
case N
inte(k) = inte(N-1);
otherwise
inte(k) = ( inte(k-1) + inte(k+1) )/2;
end
% integrate
intecur = integrate(log10(omega),inte.*omega*log(10));
% scale by constant to get final real parts
rekk(k) = -2/pi*intecur;
end
warning on Matlab:divideByZero
++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
Any suggestions as to why the results are different and (in case you also believe the results shown by the commercial software) what am I doing wrong?
The original data is like this (Again, with col1, col2, col3 being frequency, real part of the impedance, and imaginary part of the impedance, respectively):
10078.1250000000 0.00130600000000000 0.00293600000000000
8296.87500000000 0.00128000000000000 0.00241600000000000
6755.51464800000 0.00125700000000000 0.00196100000000000
5671.87500000000 0.00124500000000000 0.00163200000000000
4641.54394500000 0.00123400000000000 0.00131700000000000
3814.33813500000 0.00121800000000000 0.00106100000000000
3170.95581100000 0.00120900000000000 0.000850000000000000
2619.48535200000 0.00120900000000000 0.000663000000000000
2159.92651400000 0.00118400000000000 0.000476000000000000
1792.27941900000 0.00123500000000000 0.000333000000000000
1459.31604000000 0.00125700000000000 0.000168000000000000
1216.94714400000 0.00128500000000000 9.50000000000000e-05
998.263855000000 0.00132900000000000 -1.70000000000000e-05
824.652771000000 0.00133600000000000 -9.50000000000000e-05
676.081726000000 0.00138800000000000 -0.000189000000000000
564.236084000000 0.00142800000000000 -0.000267000000000000
460.379456000000 0.00147600000000000 -0.000349000000000000
383.522705000000 0.00152400000000000 -0.000422000000000000
315.504822000000 0.00158000000000000 -0.000500000000000000
260.416656000000 0.00164300000000000 -0.000581000000000000
217.013885000000 0.00171000000000000 -0.000662000000000000
177.556824000000 0.00179700000000000 -0.000755000000000000
146.484375000000 0.00190100000000000 -0.000845000000000000
121.228455000000 0.00201500000000000 -0.000938000000000000
100.446426000000 0.00214900000000000 -0.00102400000000000
82.7205890000000 0.00230000000000000 -0.00110900000000000
68.2645650000000 0.00247300000000000 -0.00116800000000000
56.2500000000000 0.00265000000000000 -0.00122600000000000
46.8750000000000 0.00282800000000000 -0.00126100000000000
38.4221310000000 0.00301600000000000 -0.00128000000000000
31.6722980000000 0.00320600000000000 -0.00130800000000000
26.0416680000000 0.00339900000000000 -0.00132300000000000
21.7013890000000 0.00359200000000000 -0.00131800000000000
17.7556820000000 0.00376700000000000 -0.00129100000000000
14.7405660000000 0.00393000000000000 -0.00127200000000000
12.2070310000000 0.00409400000000000 -0.00122200000000000
9.93114500000000 0.00426600000000000 -0.00116900000000000
8.22368400000000 0.00440700000000000 -0.00110700000000000
6.85307000000000 0.00446700000000000 -0.00105100000000000
5.63401500000000 0.00462400000000000 -0.00100000000000000
4.68750000000000 0.00464700000000000 -0.000957000000000000
3.82965700000000 0.00471500000000000 -0.00101000000000000
3.15869300000000 0.00470100000000000 -0.00113200000000000
2.60127600000000 0.00484600000000000 -0.00126300000000000
2.14629100000000 0.00507800000000000 -0.00141500000000000
1.76753400000000 0.00525200000000000 -0.00152900000000000
1.45393900000000 0.00559300000000000 -0.00157000000000000
1.20936500000000 0.00589200000000000 -0.00159500000000000
0.999041000000000 0.00619300000000000 -0.00156500000000000
0.820641000000000 0.00652000000000000 -0.00129400000000000
0.675822000000000 0.00654400000000000 -0.00134600000000000
0.564759000000000 0.00680100000000000 -0.00107200000000000
0.468750000000000 0.00689900000000000 -0.000870000000000000
0.384221000000000 0.00717100000000000 -0.000851000000000000
0.316723000000000 0.00713500000000000 -0.000612000000000000
0.261872000000000 0.00715500000000000 -0.000508000000000000
0.216014000000000 0.00713200000000000 -0.000361000000000000
0.178232000000000 0.00721300000000000 -0.000297000000000000
0.146944000000000 0.00732800000000000 -0.000258000000000000
0.121438000000000 0.00730000000000000 -0.000120000000000000
0.100160000000000 0.00726600000000000 -7.70000000000000e-05 hilbert, kramers-kronig, kk, impedance spectroscopy MATLAB Answers — New Questions
if i change convolution encoder to 3/4 or 7/8 code rate can u tell BER shd improve wid comp to1/2 ?
i have implemented MODEM which has Convolution encoder. when i change 1/2 to 3/4 or 7/8 . My BER for 3/4 or 7/8 comes out to be zero …..with AWGN as 1 db for Eb/No .is it right ?plese give ur suggestioni have implemented MODEM which has Convolution encoder. when i change 1/2 to 3/4 or 7/8 . My BER for 3/4 or 7/8 comes out to be zero …..with AWGN as 1 db for Eb/No .is it right ?plese give ur suggestion i have implemented MODEM which has Convolution encoder. when i change 1/2 to 3/4 or 7/8 . My BER for 3/4 or 7/8 comes out to be zero …..with AWGN as 1 db for Eb/No .is it right ?plese give ur suggestion communication, modem, convolution encoder MATLAB Answers — New Questions
sqlread specific columns/variables from a MySQL table
I want to import to Matlab one or a couple specific columns from a table that is stored in MySQL database. sqlread(conn, tablename) would import the whole table. I tried playing around with opts. it didn’t work. Is there any way to make this work? Or should I try using sql query script? Thanks!
opts = databaseImportOptions(conn, tablename);
opts = setoptions(opts, ‘SelectedVaraibleNames’, {‘wanted_column’}); % error messageI want to import to Matlab one or a couple specific columns from a table that is stored in MySQL database. sqlread(conn, tablename) would import the whole table. I tried playing around with opts. it didn’t work. Is there any way to make this work? Or should I try using sql query script? Thanks!
opts = databaseImportOptions(conn, tablename);
opts = setoptions(opts, ‘SelectedVaraibleNames’, {‘wanted_column’}); % error message I want to import to Matlab one or a couple specific columns from a table that is stored in MySQL database. sqlread(conn, tablename) would import the whole table. I tried playing around with opts. it didn’t work. Is there any way to make this work? Or should I try using sql query script? Thanks!
opts = databaseImportOptions(conn, tablename);
opts = setoptions(opts, ‘SelectedVaraibleNames’, {‘wanted_column’}); % error message sqlread MATLAB Answers — New Questions