Category: Matlab
Category Archives: Matlab
how to plot a POINTING POINTER correctly
i’d like to add a ‘►’ in annotation like tihs:
figure(1) ; an = annotation(‘textbox’,[0.5,0.5,0.05,0.05],’String’,’ ►’,’FitBoxToText’,’on’);
and if such command is typed in command window, it works well like tihs
but ,when i run such a ‘.m’ file , the output become this likei’d like to add a ‘►’ in annotation like tihs:
figure(1) ; an = annotation(‘textbox’,[0.5,0.5,0.05,0.05],’String’,’ ►’,’FitBoxToText’,’on’);
and if such command is typed in command window, it works well like tihs
but ,when i run such a ‘.m’ file , the output become this like i’d like to add a ‘►’ in annotation like tihs:
figure(1) ; an = annotation(‘textbox’,[0.5,0.5,0.05,0.05],’String’,’ ►’,’FitBoxToText’,’on’);
and if such command is typed in command window, it works well like tihs
but ,when i run such a ‘.m’ file , the output become this like annotation, 字符显示 MATLAB Answers — New Questions
MATLAB Online not working
plz help!!
i am starting MATLAB Online but its not starting .
it shows a message "there is an issue with matlab. if problem persist contact technical support."plz help!!
i am starting MATLAB Online but its not starting .
it shows a message "there is an issue with matlab. if problem persist contact technical support." plz help!!
i am starting MATLAB Online but its not starting .
it shows a message "there is an issue with matlab. if problem persist contact technical support." matlab, matlab online MATLAB Answers — New Questions
How to display the matrix as not 10^3 but as 10^1 for the values in the matrix
Y11=-((482.34i*10^-6));
Y22=-1.99i;
Y33=-2.14i;
Y44=-4.222i;
Y55=-7.761i;
Y66=(416.67*10^-6)- ((57.81*10^-9)*i);
Y77=(166.6*10^-9)- ((166.6*10^-6)*i);
Y12=0;
Y13=0;
Y14=0;
Y15=0;
Y16=0;
Y17=0;
Y21=0;
Y23=0;
Y24=1.351i;
Y25=0.581i;
Y26=0;
Y27=0i;
Y31=0;
Y32=0;
Y34=0;
Y35=0;
Y36=0;
Y37=0;
Y41=0;
Y42=1.3551i;
Y43=Y34;
Y45=0.871i;
Y46=0;
Y47=0;
Y51=Y15;
Y52=Y25;
Y53=0;
Y54=Y45;
Y56=0;
Y57=0;
Y61=0;
Y62=0;
Y63=0;
Y64=0;
Y65=Y56;
Y67=0;
Y71=0;
Y72=0;
Y73=0;
Y74=0;
Y75=0;
Y76=0;
% Ybus matrix
Ybus0 = [Y11,Y12,Y13,Y14,Y15,Y16,Y17; Y21,Y22,Y23,Y24,Y25,Y26,Y27; Y31,Y32,Y33,Y34,Y35,Y36,Y37; Y41,Y42,Y43,Y44,Y45,Y46,Y47; Y51,Y52,Y53,Y54,Y55,Y56,Y57; Y61,Y62,Y63,Y64,Y65,Y66,Y67; Y71,Y72,Y73,Y74,Y75,Y76,Y77,]
%convert Ybus to Zbus
Zbus0=inv(Ybus0);
How to display the matrix as 10^1?Y11=-((482.34i*10^-6));
Y22=-1.99i;
Y33=-2.14i;
Y44=-4.222i;
Y55=-7.761i;
Y66=(416.67*10^-6)- ((57.81*10^-9)*i);
Y77=(166.6*10^-9)- ((166.6*10^-6)*i);
Y12=0;
Y13=0;
Y14=0;
Y15=0;
Y16=0;
Y17=0;
Y21=0;
Y23=0;
Y24=1.351i;
Y25=0.581i;
Y26=0;
Y27=0i;
Y31=0;
Y32=0;
Y34=0;
Y35=0;
Y36=0;
Y37=0;
Y41=0;
Y42=1.3551i;
Y43=Y34;
Y45=0.871i;
Y46=0;
Y47=0;
Y51=Y15;
Y52=Y25;
Y53=0;
Y54=Y45;
Y56=0;
Y57=0;
Y61=0;
Y62=0;
Y63=0;
Y64=0;
Y65=Y56;
Y67=0;
Y71=0;
Y72=0;
Y73=0;
Y74=0;
Y75=0;
Y76=0;
% Ybus matrix
Ybus0 = [Y11,Y12,Y13,Y14,Y15,Y16,Y17; Y21,Y22,Y23,Y24,Y25,Y26,Y27; Y31,Y32,Y33,Y34,Y35,Y36,Y37; Y41,Y42,Y43,Y44,Y45,Y46,Y47; Y51,Y52,Y53,Y54,Y55,Y56,Y57; Y61,Y62,Y63,Y64,Y65,Y66,Y67; Y71,Y72,Y73,Y74,Y75,Y76,Y77,]
%convert Ybus to Zbus
Zbus0=inv(Ybus0);
How to display the matrix as 10^1? Y11=-((482.34i*10^-6));
Y22=-1.99i;
Y33=-2.14i;
Y44=-4.222i;
Y55=-7.761i;
Y66=(416.67*10^-6)- ((57.81*10^-9)*i);
Y77=(166.6*10^-9)- ((166.6*10^-6)*i);
Y12=0;
Y13=0;
Y14=0;
Y15=0;
Y16=0;
Y17=0;
Y21=0;
Y23=0;
Y24=1.351i;
Y25=0.581i;
Y26=0;
Y27=0i;
Y31=0;
Y32=0;
Y34=0;
Y35=0;
Y36=0;
Y37=0;
Y41=0;
Y42=1.3551i;
Y43=Y34;
Y45=0.871i;
Y46=0;
Y47=0;
Y51=Y15;
Y52=Y25;
Y53=0;
Y54=Y45;
Y56=0;
Y57=0;
Y61=0;
Y62=0;
Y63=0;
Y64=0;
Y65=Y56;
Y67=0;
Y71=0;
Y72=0;
Y73=0;
Y74=0;
Y75=0;
Y76=0;
% Ybus matrix
Ybus0 = [Y11,Y12,Y13,Y14,Y15,Y16,Y17; Y21,Y22,Y23,Y24,Y25,Y26,Y27; Y31,Y32,Y33,Y34,Y35,Y36,Y37; Y41,Y42,Y43,Y44,Y45,Y46,Y47; Y51,Y52,Y53,Y54,Y55,Y56,Y57; Y61,Y62,Y63,Y64,Y65,Y66,Y67; Y71,Y72,Y73,Y74,Y75,Y76,Y77,]
%convert Ybus to Zbus
Zbus0=inv(Ybus0);
How to display the matrix as 10^1? matlab MATLAB Answers — New Questions
I want to do the same process with this code also
I asked a question at URL: https://www.mathworks.com/matlabcentral/answers/2113451-i-tried-this-code-but-it-gives-me-an-error.
@voss
You solved my problem. Now I want to solve it just like that but that was one dimensional problem i.e., only one angle "Theta" was associated with one far field source i.e., the angle of elevation only i.e., the two sources were having 2 angles. But its a two dimensional case. i.e., here each source has two angles i.e., angle of elevation and angle of azimuth i.e., the two sources have 4 angles now. If I take them in vecor u, it will be like this: u=[30 50 65 80]; where 1st two angles (i.e., 30 and 50) are for 1st far field source and the last two angles (i.e., 65 and 80) are for the 2nd far filed source. so the formula now has both Theta and Phi. So now I want to put them in those formulas given below and the number of antennas ara again 8. The 3D Array Factor formula is given in the attachment. I tried but in vain.
clear;clc
f=1e9;% frequency
c=3e8;% Speed of light
l=c/f;% lambda
k=(2*pi)/l;% wavenumber
N=8;% Number of antennas
n=0:N-1;
phi_n=2*pi*n/N;
phi=-pi:pi/18:pi;
theta=0:pi/18:pi/2;
u=[30 50 60 80];% four angles
M=length(u);%M=length(theta);
P=length(phi);
d_circular=l/2;% spacing b/w antennas
circumference = N*d_circular;
a=circumference/(2*pi);% radius
AF(m,p)=sum(exp(-i*k*a*sin(theta(m))*(cos(phi(p)-phi_n))));
x(m,p)=abs(AF(m,p))*sin(theta(m))*cos(phi(p));
y(m,p)=abs(AF(m,p))*sin(theta(m))*sin(phi(p));
z(m,p)=abs(AF(m,p))*cos(theta(m));I asked a question at URL: https://www.mathworks.com/matlabcentral/answers/2113451-i-tried-this-code-but-it-gives-me-an-error.
@voss
You solved my problem. Now I want to solve it just like that but that was one dimensional problem i.e., only one angle "Theta" was associated with one far field source i.e., the angle of elevation only i.e., the two sources were having 2 angles. But its a two dimensional case. i.e., here each source has two angles i.e., angle of elevation and angle of azimuth i.e., the two sources have 4 angles now. If I take them in vecor u, it will be like this: u=[30 50 65 80]; where 1st two angles (i.e., 30 and 50) are for 1st far field source and the last two angles (i.e., 65 and 80) are for the 2nd far filed source. so the formula now has both Theta and Phi. So now I want to put them in those formulas given below and the number of antennas ara again 8. The 3D Array Factor formula is given in the attachment. I tried but in vain.
clear;clc
f=1e9;% frequency
c=3e8;% Speed of light
l=c/f;% lambda
k=(2*pi)/l;% wavenumber
N=8;% Number of antennas
n=0:N-1;
phi_n=2*pi*n/N;
phi=-pi:pi/18:pi;
theta=0:pi/18:pi/2;
u=[30 50 60 80];% four angles
M=length(u);%M=length(theta);
P=length(phi);
d_circular=l/2;% spacing b/w antennas
circumference = N*d_circular;
a=circumference/(2*pi);% radius
AF(m,p)=sum(exp(-i*k*a*sin(theta(m))*(cos(phi(p)-phi_n))));
x(m,p)=abs(AF(m,p))*sin(theta(m))*cos(phi(p));
y(m,p)=abs(AF(m,p))*sin(theta(m))*sin(phi(p));
z(m,p)=abs(AF(m,p))*cos(theta(m)); I asked a question at URL: https://www.mathworks.com/matlabcentral/answers/2113451-i-tried-this-code-but-it-gives-me-an-error.
@voss
You solved my problem. Now I want to solve it just like that but that was one dimensional problem i.e., only one angle "Theta" was associated with one far field source i.e., the angle of elevation only i.e., the two sources were having 2 angles. But its a two dimensional case. i.e., here each source has two angles i.e., angle of elevation and angle of azimuth i.e., the two sources have 4 angles now. If I take them in vecor u, it will be like this: u=[30 50 65 80]; where 1st two angles (i.e., 30 and 50) are for 1st far field source and the last two angles (i.e., 65 and 80) are for the 2nd far filed source. so the formula now has both Theta and Phi. So now I want to put them in those formulas given below and the number of antennas ara again 8. The 3D Array Factor formula is given in the attachment. I tried but in vain.
clear;clc
f=1e9;% frequency
c=3e8;% Speed of light
l=c/f;% lambda
k=(2*pi)/l;% wavenumber
N=8;% Number of antennas
n=0:N-1;
phi_n=2*pi*n/N;
phi=-pi:pi/18:pi;
theta=0:pi/18:pi/2;
u=[30 50 60 80];% four angles
M=length(u);%M=length(theta);
P=length(phi);
d_circular=l/2;% spacing b/w antennas
circumference = N*d_circular;
a=circumference/(2*pi);% radius
AF(m,p)=sum(exp(-i*k*a*sin(theta(m))*(cos(phi(p)-phi_n))));
x(m,p)=abs(AF(m,p))*sin(theta(m))*cos(phi(p));
y(m,p)=abs(AF(m,p))*sin(theta(m))*sin(phi(p));
z(m,p)=abs(AF(m,p))*cos(theta(m)); want to do like previous one, how, homework MATLAB Answers — New Questions
derivative of two matrices 2 by 2
If I have a matrix P of size 2 by 2 and a matrix F of size 2 by 2, how do I find the derivative of P with respect to F? Note that P and F are matrices are real numbers.
Is this code is mathmatically correct?
syms F1 F2 F3 F4; % Define symbolic variables for the elements of matrix F
F = [F1, F2; F3, F4]; % Define matrix F
syms p1 p2 p3 p4; % Define symbolic variables for the elements of matrix p
p = [p1, p2; p3, p4]; % Define matrix p
% Calculate the derivative of p with respect to F
dpdF = jacobian(p(:), F(:));
disp(dpdF)
The out put is
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]If I have a matrix P of size 2 by 2 and a matrix F of size 2 by 2, how do I find the derivative of P with respect to F? Note that P and F are matrices are real numbers.
Is this code is mathmatically correct?
syms F1 F2 F3 F4; % Define symbolic variables for the elements of matrix F
F = [F1, F2; F3, F4]; % Define matrix F
syms p1 p2 p3 p4; % Define symbolic variables for the elements of matrix p
p = [p1, p2; p3, p4]; % Define matrix p
% Calculate the derivative of p with respect to F
dpdF = jacobian(p(:), F(:));
disp(dpdF)
The out put is
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0] If I have a matrix P of size 2 by 2 and a matrix F of size 2 by 2, how do I find the derivative of P with respect to F? Note that P and F are matrices are real numbers.
Is this code is mathmatically correct?
syms F1 F2 F3 F4; % Define symbolic variables for the elements of matrix F
F = [F1, F2; F3, F4]; % Define matrix F
syms p1 p2 p3 p4; % Define symbolic variables for the elements of matrix p
p = [p1, p2; p3, p4]; % Define matrix p
% Calculate the derivative of p with respect to F
dpdF = jacobian(p(:), F(:));
disp(dpdF)
The out put is
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0] derivative MATLAB Answers — New Questions
How to build a amplitude modulated tone?
Hello,
I would like to program a Amplitude modulated tone according to the formula:
stim = sqrt(2) * LvPa_ipsi * SoundEnv.*Carri_ipsi.*[2.*m.*(((1-cos(2.*pi.*fm))./2).^n-0.5)+1];
Since I am not an expert into math and signal processing, I only get an array of zeros. This formula will come in the last line before plotting. Can someone help me finding the bug in the code?
Best,
Paul
Here is my Code:
%% simulation parameters
clear
close all
clc
% stimulus sound parameters
Fq_ipsi = 2000; % [Hz] low-frequency stimulation
LvdB_ipsi = 80; % sound level [dBSPL]
LvPa_ipsi = 10^(LvdB_ipsi/20)*20e-6; % [Pa] calculated from dB SPL re 20 µPa
phase_ipsi = 0; % [rad] initial phase
Fq_contra = 2000; % [Hz] high-frequency stimulation
LvdB_contra = 80; % sound level [dBSPL]
LvPa_contra = 10^(LvdB_contra/20)*20e-6; % [Pa] calculated from dB SPL re 20 µPa
phase_contra = 0; % [rad] initial phase
% time steps
DTms = 0.01; % [ms] time step — 100kHz sampling rate
% time lengths
Tall = 50; % [ms] entire duration of simulation
Tinit = 15; % [ms] starting time of stimulus
Tstim = 25; % [ms] duration of entire stimulus
Tramp = 3.9;% [ms] duration of stimulus ramp
Tlast = 10; % [ms] time after stimulus
Nall = round(Tall /DTms);
Ninit = round(Tinit/DTms);
Nstim = round(Tstim/DTms);
Nramp = round(Tramp/DTms);
Nlast = round(Tlast/DTms);
tvms = (0:Nall-1)*DTms-Tinit; % time vector (stimulus starts at time zero)
lmain = logical( [zeros(1,Ninit),ones(1,Nstim),zeros(1,Nlast)] );
% constructing sound stimuli
disp(‘Making sound stimuli’);
% stimulus sound envelope (ramp)
SoundEnv = zeros(1,Nall);
% SoundEnv(Ninit+1 :Ninit+Nramp+1) = (0:Nramp)/Nramp; % upward ramp
SoundEnv(Ninit+1 :Ninit+Nstim+1) = 1; % stimulus
% SoundEnv(Ninit+Nstim-Nramp+1:Ninit+Nstim+1) = (Nramp:-1:0)/Nramp; % downward ramp
% Set-up for Amplitde modulated tone
fm = 128; % modulation frequency [Hz]
n = 1; % exponent
m = 1; % modulation depth
% stimulus sound waveforms
Carri_ipsi = sin( 2 * pi * Fq_ipsi * ((tvms-Tinit)/1000) + phase_ipsi); % carrier sine wave
Carri_contra = sin( 2 * pi * Fq_contra * ((tvms-Tinit)/1000) + phase_contra); % carrier sine wave
Sound_ipsi = sqrt(2) * LvPa_ipsi * SoundEnv .* Carri_ipsi; % apply ramp and scale to Pa
Sound_contra = sqrt(2) * LvPa_contra * SoundEnv .* Carri_contra; % apply ramp and scale to Pa
% Make the Signal Amplitude modulated tone
stim = sqrt(2) * LvPa_ipsi * SoundEnv.*Carri_ipsi.*[2.*m.*(((1-cos(2.*pi.*fm))./2).^n-0.5)+1];
figure()
subplot(2,1,1)
plot(tvms, stim)
subplot(2,1,2)
plot(tvms, Sound_contra)
title(‘Carrier’)
xlabel (‘Time / ms’)
ylabel(‘Amplitude’)Hello,
I would like to program a Amplitude modulated tone according to the formula:
stim = sqrt(2) * LvPa_ipsi * SoundEnv.*Carri_ipsi.*[2.*m.*(((1-cos(2.*pi.*fm))./2).^n-0.5)+1];
Since I am not an expert into math and signal processing, I only get an array of zeros. This formula will come in the last line before plotting. Can someone help me finding the bug in the code?
Best,
Paul
Here is my Code:
%% simulation parameters
clear
close all
clc
% stimulus sound parameters
Fq_ipsi = 2000; % [Hz] low-frequency stimulation
LvdB_ipsi = 80; % sound level [dBSPL]
LvPa_ipsi = 10^(LvdB_ipsi/20)*20e-6; % [Pa] calculated from dB SPL re 20 µPa
phase_ipsi = 0; % [rad] initial phase
Fq_contra = 2000; % [Hz] high-frequency stimulation
LvdB_contra = 80; % sound level [dBSPL]
LvPa_contra = 10^(LvdB_contra/20)*20e-6; % [Pa] calculated from dB SPL re 20 µPa
phase_contra = 0; % [rad] initial phase
% time steps
DTms = 0.01; % [ms] time step — 100kHz sampling rate
% time lengths
Tall = 50; % [ms] entire duration of simulation
Tinit = 15; % [ms] starting time of stimulus
Tstim = 25; % [ms] duration of entire stimulus
Tramp = 3.9;% [ms] duration of stimulus ramp
Tlast = 10; % [ms] time after stimulus
Nall = round(Tall /DTms);
Ninit = round(Tinit/DTms);
Nstim = round(Tstim/DTms);
Nramp = round(Tramp/DTms);
Nlast = round(Tlast/DTms);
tvms = (0:Nall-1)*DTms-Tinit; % time vector (stimulus starts at time zero)
lmain = logical( [zeros(1,Ninit),ones(1,Nstim),zeros(1,Nlast)] );
% constructing sound stimuli
disp(‘Making sound stimuli’);
% stimulus sound envelope (ramp)
SoundEnv = zeros(1,Nall);
% SoundEnv(Ninit+1 :Ninit+Nramp+1) = (0:Nramp)/Nramp; % upward ramp
SoundEnv(Ninit+1 :Ninit+Nstim+1) = 1; % stimulus
% SoundEnv(Ninit+Nstim-Nramp+1:Ninit+Nstim+1) = (Nramp:-1:0)/Nramp; % downward ramp
% Set-up for Amplitde modulated tone
fm = 128; % modulation frequency [Hz]
n = 1; % exponent
m = 1; % modulation depth
% stimulus sound waveforms
Carri_ipsi = sin( 2 * pi * Fq_ipsi * ((tvms-Tinit)/1000) + phase_ipsi); % carrier sine wave
Carri_contra = sin( 2 * pi * Fq_contra * ((tvms-Tinit)/1000) + phase_contra); % carrier sine wave
Sound_ipsi = sqrt(2) * LvPa_ipsi * SoundEnv .* Carri_ipsi; % apply ramp and scale to Pa
Sound_contra = sqrt(2) * LvPa_contra * SoundEnv .* Carri_contra; % apply ramp and scale to Pa
% Make the Signal Amplitude modulated tone
stim = sqrt(2) * LvPa_ipsi * SoundEnv.*Carri_ipsi.*[2.*m.*(((1-cos(2.*pi.*fm))./2).^n-0.5)+1];
figure()
subplot(2,1,1)
plot(tvms, stim)
subplot(2,1,2)
plot(tvms, Sound_contra)
title(‘Carrier’)
xlabel (‘Time / ms’)
ylabel(‘Amplitude’) Hello,
I would like to program a Amplitude modulated tone according to the formula:
stim = sqrt(2) * LvPa_ipsi * SoundEnv.*Carri_ipsi.*[2.*m.*(((1-cos(2.*pi.*fm))./2).^n-0.5)+1];
Since I am not an expert into math and signal processing, I only get an array of zeros. This formula will come in the last line before plotting. Can someone help me finding the bug in the code?
Best,
Paul
Here is my Code:
%% simulation parameters
clear
close all
clc
% stimulus sound parameters
Fq_ipsi = 2000; % [Hz] low-frequency stimulation
LvdB_ipsi = 80; % sound level [dBSPL]
LvPa_ipsi = 10^(LvdB_ipsi/20)*20e-6; % [Pa] calculated from dB SPL re 20 µPa
phase_ipsi = 0; % [rad] initial phase
Fq_contra = 2000; % [Hz] high-frequency stimulation
LvdB_contra = 80; % sound level [dBSPL]
LvPa_contra = 10^(LvdB_contra/20)*20e-6; % [Pa] calculated from dB SPL re 20 µPa
phase_contra = 0; % [rad] initial phase
% time steps
DTms = 0.01; % [ms] time step — 100kHz sampling rate
% time lengths
Tall = 50; % [ms] entire duration of simulation
Tinit = 15; % [ms] starting time of stimulus
Tstim = 25; % [ms] duration of entire stimulus
Tramp = 3.9;% [ms] duration of stimulus ramp
Tlast = 10; % [ms] time after stimulus
Nall = round(Tall /DTms);
Ninit = round(Tinit/DTms);
Nstim = round(Tstim/DTms);
Nramp = round(Tramp/DTms);
Nlast = round(Tlast/DTms);
tvms = (0:Nall-1)*DTms-Tinit; % time vector (stimulus starts at time zero)
lmain = logical( [zeros(1,Ninit),ones(1,Nstim),zeros(1,Nlast)] );
% constructing sound stimuli
disp(‘Making sound stimuli’);
% stimulus sound envelope (ramp)
SoundEnv = zeros(1,Nall);
% SoundEnv(Ninit+1 :Ninit+Nramp+1) = (0:Nramp)/Nramp; % upward ramp
SoundEnv(Ninit+1 :Ninit+Nstim+1) = 1; % stimulus
% SoundEnv(Ninit+Nstim-Nramp+1:Ninit+Nstim+1) = (Nramp:-1:0)/Nramp; % downward ramp
% Set-up for Amplitde modulated tone
fm = 128; % modulation frequency [Hz]
n = 1; % exponent
m = 1; % modulation depth
% stimulus sound waveforms
Carri_ipsi = sin( 2 * pi * Fq_ipsi * ((tvms-Tinit)/1000) + phase_ipsi); % carrier sine wave
Carri_contra = sin( 2 * pi * Fq_contra * ((tvms-Tinit)/1000) + phase_contra); % carrier sine wave
Sound_ipsi = sqrt(2) * LvPa_ipsi * SoundEnv .* Carri_ipsi; % apply ramp and scale to Pa
Sound_contra = sqrt(2) * LvPa_contra * SoundEnv .* Carri_contra; % apply ramp and scale to Pa
% Make the Signal Amplitude modulated tone
stim = sqrt(2) * LvPa_ipsi * SoundEnv.*Carri_ipsi.*[2.*m.*(((1-cos(2.*pi.*fm))./2).^n-0.5)+1];
figure()
subplot(2,1,1)
plot(tvms, stim)
subplot(2,1,2)
plot(tvms, Sound_contra)
title(‘Carrier’)
xlabel (‘Time / ms’)
ylabel(‘Amplitude’) acoustics, signal processing MATLAB Answers — New Questions
Find the equations of Motion
For a base excitation single DOF oscillatory system (mass-spring-damper) (like an Earthquake): Period of pi/2 sec; m = 1 kg; Spring coefficient (k) = 100 N/m; Damping Ratio = 0.15; Damper coefficient (c) = 3 N-s/m; Natural Frequency = 10 rad/s.
I want to find the equations of motion and the response given these properties and I need to use MatLab for simualtion. I’m not completely sure how to go about this with the functions, independent variable (t), and maybe ode45 to make this a consistent equation. The Equation of Motion that’s for the system is at the bottom of my script. I’m just a little lost and would appreciate some guidance. Here’s my code so far:
% For the response of a damped system under the harmonic motion of the base
k = 100 % N/m
m = 1 % kg
DR = 0.15 % Damping Ratio
wn = (k/m)^(1/2) % rad/s
w = ???
t = % independent ???
Y = % Big Y is Maximum Amplitude of Base Motion Test Bed (Unknown)
c = DR*2*m*wn %N-s/m
alpha = arctan((-c*w)/k)
A = Y*((k^2)+(c*w)^2)^(1/2)
EOM1 = A*sin(w*t-alpha) % External ForceFor a base excitation single DOF oscillatory system (mass-spring-damper) (like an Earthquake): Period of pi/2 sec; m = 1 kg; Spring coefficient (k) = 100 N/m; Damping Ratio = 0.15; Damper coefficient (c) = 3 N-s/m; Natural Frequency = 10 rad/s.
I want to find the equations of motion and the response given these properties and I need to use MatLab for simualtion. I’m not completely sure how to go about this with the functions, independent variable (t), and maybe ode45 to make this a consistent equation. The Equation of Motion that’s for the system is at the bottom of my script. I’m just a little lost and would appreciate some guidance. Here’s my code so far:
% For the response of a damped system under the harmonic motion of the base
k = 100 % N/m
m = 1 % kg
DR = 0.15 % Damping Ratio
wn = (k/m)^(1/2) % rad/s
w = ???
t = % independent ???
Y = % Big Y is Maximum Amplitude of Base Motion Test Bed (Unknown)
c = DR*2*m*wn %N-s/m
alpha = arctan((-c*w)/k)
A = Y*((k^2)+(c*w)^2)^(1/2)
EOM1 = A*sin(w*t-alpha) % External Force For a base excitation single DOF oscillatory system (mass-spring-damper) (like an Earthquake): Period of pi/2 sec; m = 1 kg; Spring coefficient (k) = 100 N/m; Damping Ratio = 0.15; Damper coefficient (c) = 3 N-s/m; Natural Frequency = 10 rad/s.
I want to find the equations of motion and the response given these properties and I need to use MatLab for simualtion. I’m not completely sure how to go about this with the functions, independent variable (t), and maybe ode45 to make this a consistent equation. The Equation of Motion that’s for the system is at the bottom of my script. I’m just a little lost and would appreciate some guidance. Here’s my code so far:
% For the response of a damped system under the harmonic motion of the base
k = 100 % N/m
m = 1 % kg
DR = 0.15 % Damping Ratio
wn = (k/m)^(1/2) % rad/s
w = ???
t = % independent ???
Y = % Big Y is Maximum Amplitude of Base Motion Test Bed (Unknown)
c = DR*2*m*wn %N-s/m
alpha = arctan((-c*w)/k)
A = Y*((k^2)+(c*w)^2)^(1/2)
EOM1 = A*sin(w*t-alpha) % External Force vibrations, differential equations, equations of motion, eom MATLAB Answers — New Questions
How to turn S11 to time domain by Matlab
Hi,everyone.I run HFSS to get S11 for my circuit,HFSS also provide time domain for S11.I want to obtain the same time domain response by Matlab.However the result is not even close.Can anyone help~Thx!
The input signal is an impulse and I perform the frequency domain simulation from 0~7.5GHz.
And both attached files are the result from HFSS.
Here’s my code:
load S11_re.txt -ascii
load S11_im.txt -ascii
freq=1e+9*S11_re(:,1);
S11=S11_re(:,2)+1i*S11_im(:,2);
TDR=ifft(S11);
Fs=2*max(freq);
Ts=1/Fs;
N=numel(TDR);
tvec=(0:(N-1))*Ts;
plot(tvec,abs(TDR))Hi,everyone.I run HFSS to get S11 for my circuit,HFSS also provide time domain for S11.I want to obtain the same time domain response by Matlab.However the result is not even close.Can anyone help~Thx!
The input signal is an impulse and I perform the frequency domain simulation from 0~7.5GHz.
And both attached files are the result from HFSS.
Here’s my code:
load S11_re.txt -ascii
load S11_im.txt -ascii
freq=1e+9*S11_re(:,1);
S11=S11_re(:,2)+1i*S11_im(:,2);
TDR=ifft(S11);
Fs=2*max(freq);
Ts=1/Fs;
N=numel(TDR);
tvec=(0:(N-1))*Ts;
plot(tvec,abs(TDR)) Hi,everyone.I run HFSS to get S11 for my circuit,HFSS also provide time domain for S11.I want to obtain the same time domain response by Matlab.However the result is not even close.Can anyone help~Thx!
The input signal is an impulse and I perform the frequency domain simulation from 0~7.5GHz.
And both attached files are the result from HFSS.
Here’s my code:
load S11_re.txt -ascii
load S11_im.txt -ascii
freq=1e+9*S11_re(:,1);
S11=S11_re(:,2)+1i*S11_im(:,2);
TDR=ifft(S11);
Fs=2*max(freq);
Ts=1/Fs;
N=numel(TDR);
tvec=(0:(N-1))*Ts;
plot(tvec,abs(TDR)) ifft, time domain MATLAB Answers — New Questions
Assistance Required for Clustering Code Implementation
Dear Matlab experts,
I am experiencing some issues with my clustering code, and I would like assistance in resolving these problems.
Thank you very much in advance.
Best regards,
J1
% MATLAB 코드 – 데이터 로드 및 클러스터링
% 1. 데이터 로드
dataPath = "C:UsershhyanDesktop분배이론그림2GPT data_1.csv";
opts = detectImportOptions(dataPath); % 데이터 가져오기 옵션 감지
data = readtable(dataPath, opts); % 테이블 형식으로 데이터 읽기
% 2. 분석에 사용할 컬럼 선택
selectedCols = ["GDPpercapita", "GDPgrowth", "Gini"]; % 원하는 컬럼 선택
selectedData = data(:, selectedCols); % 해당 컬럼만 추출
% 3. 데이터 전처리
selectedData = rmmissing(selectedData); % 결측치 제거
% 4. 숫자 데이터로 변환
selectedData.GDPpercapita = str2double(strrep(selectedData.GDPpercapita, ‘,’, ”));
selectedData.GDPgrowth = str2double(selectedData.GDPgrowth);
selectedData.Gini = str2double(selectedData.Gini);
% 5. 클러스터링 수행 (예: K-Means)
k = 3; % 클러스터의 수
[idx, centroids] = kmeans(table2array(selectedData), k); % kmeans 클러스터링
% 6. 클러스터 결과를 데이터에 추가
idx_table = array2table(idx, ‘VariableNames’, {‘Cluster’}); % 클러스터 번호를 테이블로 변환
if height(idx_table) == height(data) % 행 개수 일치 확인
data = [data idx_table]; % 기존 데이터와 병합
else
error("클러스터링 결과의 길이가 데이터셋의 행 개수와 일치하지 않습니다.");
end
% 7. 클러스터 결과 시각화
figure; % 새로운 그래프 창 열기
scatter(selectedData.GDPpercapita, selectedData.GDPgrowth, 50, idx, ‘filled’);
hold on;
scatter(centroids(:, 1), centroids(:, 2), 100, ‘kx’, ‘LineWidth’, 3); % 센트로이드 표시
xlabel(‘1인당 GDP’);
ylabel(‘GDP 성장률’);
title(‘국가별 클러스터링’);
hold off;
% 8. 클러스터 결과 저장
writetable(data, "C:UsershhyanDesktop분배이론그림2Clustered_data.csv"); % 클러스터 결과 저장Dear Matlab experts,
I am experiencing some issues with my clustering code, and I would like assistance in resolving these problems.
Thank you very much in advance.
Best regards,
J1
% MATLAB 코드 – 데이터 로드 및 클러스터링
% 1. 데이터 로드
dataPath = "C:UsershhyanDesktop분배이론그림2GPT data_1.csv";
opts = detectImportOptions(dataPath); % 데이터 가져오기 옵션 감지
data = readtable(dataPath, opts); % 테이블 형식으로 데이터 읽기
% 2. 분석에 사용할 컬럼 선택
selectedCols = ["GDPpercapita", "GDPgrowth", "Gini"]; % 원하는 컬럼 선택
selectedData = data(:, selectedCols); % 해당 컬럼만 추출
% 3. 데이터 전처리
selectedData = rmmissing(selectedData); % 결측치 제거
% 4. 숫자 데이터로 변환
selectedData.GDPpercapita = str2double(strrep(selectedData.GDPpercapita, ‘,’, ”));
selectedData.GDPgrowth = str2double(selectedData.GDPgrowth);
selectedData.Gini = str2double(selectedData.Gini);
% 5. 클러스터링 수행 (예: K-Means)
k = 3; % 클러스터의 수
[idx, centroids] = kmeans(table2array(selectedData), k); % kmeans 클러스터링
% 6. 클러스터 결과를 데이터에 추가
idx_table = array2table(idx, ‘VariableNames’, {‘Cluster’}); % 클러스터 번호를 테이블로 변환
if height(idx_table) == height(data) % 행 개수 일치 확인
data = [data idx_table]; % 기존 데이터와 병합
else
error("클러스터링 결과의 길이가 데이터셋의 행 개수와 일치하지 않습니다.");
end
% 7. 클러스터 결과 시각화
figure; % 새로운 그래프 창 열기
scatter(selectedData.GDPpercapita, selectedData.GDPgrowth, 50, idx, ‘filled’);
hold on;
scatter(centroids(:, 1), centroids(:, 2), 100, ‘kx’, ‘LineWidth’, 3); % 센트로이드 표시
xlabel(‘1인당 GDP’);
ylabel(‘GDP 성장률’);
title(‘국가별 클러스터링’);
hold off;
% 8. 클러스터 결과 저장
writetable(data, "C:UsershhyanDesktop분배이론그림2Clustered_data.csv"); % 클러스터 결과 저장 Dear Matlab experts,
I am experiencing some issues with my clustering code, and I would like assistance in resolving these problems.
Thank you very much in advance.
Best regards,
J1
% MATLAB 코드 – 데이터 로드 및 클러스터링
% 1. 데이터 로드
dataPath = "C:UsershhyanDesktop분배이론그림2GPT data_1.csv";
opts = detectImportOptions(dataPath); % 데이터 가져오기 옵션 감지
data = readtable(dataPath, opts); % 테이블 형식으로 데이터 읽기
% 2. 분석에 사용할 컬럼 선택
selectedCols = ["GDPpercapita", "GDPgrowth", "Gini"]; % 원하는 컬럼 선택
selectedData = data(:, selectedCols); % 해당 컬럼만 추출
% 3. 데이터 전처리
selectedData = rmmissing(selectedData); % 결측치 제거
% 4. 숫자 데이터로 변환
selectedData.GDPpercapita = str2double(strrep(selectedData.GDPpercapita, ‘,’, ”));
selectedData.GDPgrowth = str2double(selectedData.GDPgrowth);
selectedData.Gini = str2double(selectedData.Gini);
% 5. 클러스터링 수행 (예: K-Means)
k = 3; % 클러스터의 수
[idx, centroids] = kmeans(table2array(selectedData), k); % kmeans 클러스터링
% 6. 클러스터 결과를 데이터에 추가
idx_table = array2table(idx, ‘VariableNames’, {‘Cluster’}); % 클러스터 번호를 테이블로 변환
if height(idx_table) == height(data) % 행 개수 일치 확인
data = [data idx_table]; % 기존 데이터와 병합
else
error("클러스터링 결과의 길이가 데이터셋의 행 개수와 일치하지 않습니다.");
end
% 7. 클러스터 결과 시각화
figure; % 새로운 그래프 창 열기
scatter(selectedData.GDPpercapita, selectedData.GDPgrowth, 50, idx, ‘filled’);
hold on;
scatter(centroids(:, 1), centroids(:, 2), 100, ‘kx’, ‘LineWidth’, 3); % 센트로이드 표시
xlabel(‘1인당 GDP’);
ylabel(‘GDP 성장률’);
title(‘국가별 클러스터링’);
hold off;
% 8. 클러스터 결과 저장
writetable(data, "C:UsershhyanDesktop분배이론그림2Clustered_data.csv"); % 클러스터 결과 저장 clustering, code MATLAB Answers — New Questions
Highlighted numbers in Matlab
Hello :), I am new in Matlab, and I’d like to know if there is a way to highlight numbers so that it can be easily differentiated from the rest of the characters.
I am referring to this:
Numbers in Matlab:
Highlighted numbers:Hello :), I am new in Matlab, and I’d like to know if there is a way to highlight numbers so that it can be easily differentiated from the rest of the characters.
I am referring to this:
Numbers in Matlab:
Highlighted numbers: Hello :), I am new in Matlab, and I’d like to know if there is a way to highlight numbers so that it can be easily differentiated from the rest of the characters.
I am referring to this:
Numbers in Matlab:
Highlighted numbers: transferred MATLAB Answers — New Questions
How can I purchase a new Student License?
How can I purchase a new Student License?How can I purchase a new Student License? How can I purchase a new Student License? MATLAB Answers — New Questions
checking PSO code quality and goodness
i have made my PSO code for my research in fog computing networks…..
i have my result and curves…
my question is —— how can i be sure that my code results are accepted ???
is there a general way for checking it?
is there any steps i can do to check it?
i need to check it because i need to proceed my research steps…
i hope you help me
thanksi have made my PSO code for my research in fog computing networks…..
i have my result and curves…
my question is —— how can i be sure that my code results are accepted ???
is there a general way for checking it?
is there any steps i can do to check it?
i need to check it because i need to proceed my research steps…
i hope you help me
thanks i have made my PSO code for my research in fog computing networks…..
i have my result and curves…
my question is —— how can i be sure that my code results are accepted ???
is there a general way for checking it?
is there any steps i can do to check it?
i need to check it because i need to proceed my research steps…
i hope you help me
thanks pso coding, fog computing MATLAB Answers — New Questions
Error in PSAT software usage
I am research scholar from India. I am using PSAT software for my research work. I had used the same software for my M.Tech project which worked very well at that time.
Now I am coming across following error when I load data file and run power flow.
Newton-Raphson Method for Power Flow Computation
Data file "C:UsersEXAMDesktopMANJULAexample1(mdl)"
Writing file "fm_call" …
??? Error using ==> fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in ==> fm_wcall at 49
count = fprintf(fid,’function fm_call(flag)nn’);
Error in ==> fm_spf at 41
fm_wcall;
Error in ==> fm_set at 720
fm_spf
??? Error while evaluating uicontrol Callback
kindly help me to debug this error which will be great help for me.I am research scholar from India. I am using PSAT software for my research work. I had used the same software for my M.Tech project which worked very well at that time.
Now I am coming across following error when I load data file and run power flow.
Newton-Raphson Method for Power Flow Computation
Data file "C:UsersEXAMDesktopMANJULAexample1(mdl)"
Writing file "fm_call" …
??? Error using ==> fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in ==> fm_wcall at 49
count = fprintf(fid,’function fm_call(flag)nn’);
Error in ==> fm_spf at 41
fm_wcall;
Error in ==> fm_set at 720
fm_spf
??? Error while evaluating uicontrol Callback
kindly help me to debug this error which will be great help for me. I am research scholar from India. I am using PSAT software for my research work. I had used the same software for my M.Tech project which worked very well at that time.
Now I am coming across following error when I load data file and run power flow.
Newton-Raphson Method for Power Flow Computation
Data file "C:UsersEXAMDesktopMANJULAexample1(mdl)"
Writing file "fm_call" …
??? Error using ==> fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in ==> fm_wcall at 49
count = fprintf(fid,’function fm_call(flag)nn’);
Error in ==> fm_spf at 41
fm_wcall;
Error in ==> fm_set at 720
fm_spf
??? Error while evaluating uicontrol Callback
kindly help me to debug this error which will be great help for me. psat, matlab MATLAB Answers — New Questions
How do I incorporate a scheduling algorithm in ifogsim in fog computing?
I am currently working on optimized task scheduling in fog computing domain. I have developed a scheduling algorithm in MATLAB. I am using ifogsim for simulation purpose. I have embedded a module called scheduling algorithm inside the scheduler device in ifogsim. But how do I actually call the module from MATLAB where I have developed the scheduling algorithm. I am stuck here.I am currently working on optimized task scheduling in fog computing domain. I have developed a scheduling algorithm in MATLAB. I am using ifogsim for simulation purpose. I have embedded a module called scheduling algorithm inside the scheduler device in ifogsim. But how do I actually call the module from MATLAB where I have developed the scheduling algorithm. I am stuck here. I am currently working on optimized task scheduling in fog computing domain. I have developed a scheduling algorithm in MATLAB. I am using ifogsim for simulation purpose. I have embedded a module called scheduling algorithm inside the scheduler device in ifogsim. But how do I actually call the module from MATLAB where I have developed the scheduling algorithm. I am stuck here. matlab MATLAB Answers — New Questions
Is it possible to change color of executed codes for easily identify dead codes
Hi everyone:
I think when taking over large projects, we’ve all encountered the experience where there are sections of code left behind by predecessors that are never executed. However, due to the sheer number of lines of code and the disorganized structure, it’s often difficult to pinpoint the locations of dead code. So, I wanted to ask if there’s a feature in MATLAB that can colorize executed code, making it easy for us to identify dead code by recognizing sections that remain uncolored.Hi everyone:
I think when taking over large projects, we’ve all encountered the experience where there are sections of code left behind by predecessors that are never executed. However, due to the sheer number of lines of code and the disorganized structure, it’s often difficult to pinpoint the locations of dead code. So, I wanted to ask if there’s a feature in MATLAB that can colorize executed code, making it easy for us to identify dead code by recognizing sections that remain uncolored. Hi everyone:
I think when taking over large projects, we’ve all encountered the experience where there are sections of code left behind by predecessors that are never executed. However, due to the sheer number of lines of code and the disorganized structure, it’s often difficult to pinpoint the locations of dead code. So, I wanted to ask if there’s a feature in MATLAB that can colorize executed code, making it easy for us to identify dead code by recognizing sections that remain uncolored. dead code, change color, color MATLAB Answers — New Questions
Enforce Kinematic Constraint in Initial Value Problem ode45()
I have the following non-linear system:
I had originally solved for the displacement of each mass using ode45() (see https://www.mathworks.com/matlabcentral/answers/2107866-find-state-space-representation-of-linearized-non-linear-system-to-find-state-space-representation-i?s_tid=srchtitle). I had set the initial displacement and velocity of each mass to zero as my initial values. My confusion is with how my kinematic constraint (i.e. zero displacement at each wall) is accounted for or enforced in the ode45() solution. Is my ode45() solution valid for the system shown or do I need to form this as a boundary value problem with the boundary conditions as x(0) = 0 and x(l) = 0 instead of an initial value problem as I have done with ode45()? Another reason I bring this up is because my ode45() solver frequently fails after t<10^-5 s when solving. Is this because there are are singularities at the walls that I am not accounting for with my ode45() solution?I have the following non-linear system:
I had originally solved for the displacement of each mass using ode45() (see https://www.mathworks.com/matlabcentral/answers/2107866-find-state-space-representation-of-linearized-non-linear-system-to-find-state-space-representation-i?s_tid=srchtitle). I had set the initial displacement and velocity of each mass to zero as my initial values. My confusion is with how my kinematic constraint (i.e. zero displacement at each wall) is accounted for or enforced in the ode45() solution. Is my ode45() solution valid for the system shown or do I need to form this as a boundary value problem with the boundary conditions as x(0) = 0 and x(l) = 0 instead of an initial value problem as I have done with ode45()? Another reason I bring this up is because my ode45() solver frequently fails after t<10^-5 s when solving. Is this because there are are singularities at the walls that I am not accounting for with my ode45() solution? I have the following non-linear system:
I had originally solved for the displacement of each mass using ode45() (see https://www.mathworks.com/matlabcentral/answers/2107866-find-state-space-representation-of-linearized-non-linear-system-to-find-state-space-representation-i?s_tid=srchtitle). I had set the initial displacement and velocity of each mass to zero as my initial values. My confusion is with how my kinematic constraint (i.e. zero displacement at each wall) is accounted for or enforced in the ode45() solution. Is my ode45() solution valid for the system shown or do I need to form this as a boundary value problem with the boundary conditions as x(0) = 0 and x(l) = 0 instead of an initial value problem as I have done with ode45()? Another reason I bring this up is because my ode45() solver frequently fails after t<10^-5 s when solving. Is this because there are are singularities at the walls that I am not accounting for with my ode45() solution? matlab, ode, ode45, matlab code, solve, model, system, nonlinear MATLAB Answers — New Questions
Can i use the student license as master of science student?
Hello,
As a master of science student, can I use the student license for my master of science degree?
I’ll utilize it for my thesis as well as for the publication of two thesis-related research papers.
Thanks :)Hello,
As a master of science student, can I use the student license for my master of science degree?
I’ll utilize it for my thesis as well as for the publication of two thesis-related research papers.
Thanks 🙂 Hello,
As a master of science student, can I use the student license for my master of science degree?
I’ll utilize it for my thesis as well as for the publication of two thesis-related research papers.
Thanks 🙂 student license MATLAB Answers — New Questions
Unable to fully filter out a tone with a notch filter.
I am working on coding a matlab notch filter that is supposed to fitler out a tone in the audio file listed in the code. The Notch Filter works as it is supposed to except at the very beginning and at the very end the tone is still there and not filtered out and I need to have the tone completely gone. I am unable to figure out what to change in my code I have tried changing the frequencies I have tried changing where my filter starts and my notch width but nothing has solved my issue. Any help or suggestions is appreciated Thanks!
Code here below
% Load input sound
[Sound, fs] = audioread(‘SunshineSquare.wav’);
figure(1);
% Plot specgram of input sound
specgram(Sound, 512, fs);
title(‘Spectrogram of Input Sound (SunshineSquare.wav)’);
% Parameters of Notch Filter
frequencies = [1574.99, 3149.97, 4724.96];
notchwidth = 10;
% Tone Removal
a_total = 1;
b_total = 1;
for i = 1:length(frequencies)
Wn = [(frequencies(i) – notchwidth/2) / (fs/2), (frequencies(i) + notchwidth/2) / (fs/2)];
Wn = max(min(Wn, 0.99), 0.01);
[b, a] = butter(2, Wn, ‘stop’);
b_total = conv(b_total, b);
a_total = conv(a_total, a);
end
filteredAudio = filter(b_total, a_total, Sound);
% Play filtered sound
soundsc(filteredAudio, fs);
figure(2);
% Plot specgram of output sound after using notch filter
specgram(filteredAudio, 512, fs);
title(‘Specgram after Notch Filter’);
% Plot SunshineSquare sound
figure(3);
t = (0:length(Sound)-1)/fs;
plot(t, Sound);
xlabel(‘Time (sec)’);
ylabel(‘Amplitude’);
title(‘Notch-Filtered SunshineSquare Sound Plot’);
figure(4);
plot (ww,abs(HH));
zplane(bb,aa)
xlabel(‘Real’);
ylabel(‘Imaginary’);
title(‘Magnitude IIR Frequency Response (Z-Plane)’);
grid on
figure(5);
% Plot Notch-filtered sound
t = (0:length(Sound)-1)/fs;
plot(t, filteredAudio);
xlabel(‘Time (sec)’);
ylabel(‘Amplitude’);
title(‘Notch-Filtered Z-Plot’);
figure(6);
sgtitle(‘Redo Tone Removal Step 2: Magnitude Response for Notch Filter’);
f1 = 1574.99/fs * 2 * pi;
f2 = 3149.97/fs * 2 * pi;
f3 = 4724.96/fs * 2 * pi;
% Plot nulling filter frequency response and Z-plane representation
ww = -pi:pi/100:pi;
HH = freqz(bb,aa,ww);
bb = poly([exp(1j*f1) exp(-1j*f1) exp(1j*f2) exp(-1j*f2) exp(1j*f3) exp(-1j*f3)]);
aa = poly(0.80*[exp(1j*f1) exp(-1j*f1) exp(1j*f2) exp(-1j*f2) exp(1j*f3) exp(-1j*f3)]);
y = filteredAudio;
% Display the nulling filter frequency response
subplot(1,1,1);
plot(ww, abs(HH));
title(‘Notch Filter Frequency Response’);
xlabel(‘Frequency (Hz)’);
ylabel(‘Magnitude’);
fout = filter(bb,aa,y);
% Calculate the DC gain of the IIR Notch filter
ww_low = -pi:pi/10000:pi; % Frequencies close to zero
HH_low = freqz(b_total, a_total, ww_low, fs);
% Display the DC gain
dc_gain_iir = abs(HH_low(1));
disp([‘DC Gain of IIR Notch Filter: ‘, num2str(dc_gain_iir)]);
Specgrams of the input and output of the file from matlab for reference are attached.I am working on coding a matlab notch filter that is supposed to fitler out a tone in the audio file listed in the code. The Notch Filter works as it is supposed to except at the very beginning and at the very end the tone is still there and not filtered out and I need to have the tone completely gone. I am unable to figure out what to change in my code I have tried changing the frequencies I have tried changing where my filter starts and my notch width but nothing has solved my issue. Any help or suggestions is appreciated Thanks!
Code here below
% Load input sound
[Sound, fs] = audioread(‘SunshineSquare.wav’);
figure(1);
% Plot specgram of input sound
specgram(Sound, 512, fs);
title(‘Spectrogram of Input Sound (SunshineSquare.wav)’);
% Parameters of Notch Filter
frequencies = [1574.99, 3149.97, 4724.96];
notchwidth = 10;
% Tone Removal
a_total = 1;
b_total = 1;
for i = 1:length(frequencies)
Wn = [(frequencies(i) – notchwidth/2) / (fs/2), (frequencies(i) + notchwidth/2) / (fs/2)];
Wn = max(min(Wn, 0.99), 0.01);
[b, a] = butter(2, Wn, ‘stop’);
b_total = conv(b_total, b);
a_total = conv(a_total, a);
end
filteredAudio = filter(b_total, a_total, Sound);
% Play filtered sound
soundsc(filteredAudio, fs);
figure(2);
% Plot specgram of output sound after using notch filter
specgram(filteredAudio, 512, fs);
title(‘Specgram after Notch Filter’);
% Plot SunshineSquare sound
figure(3);
t = (0:length(Sound)-1)/fs;
plot(t, Sound);
xlabel(‘Time (sec)’);
ylabel(‘Amplitude’);
title(‘Notch-Filtered SunshineSquare Sound Plot’);
figure(4);
plot (ww,abs(HH));
zplane(bb,aa)
xlabel(‘Real’);
ylabel(‘Imaginary’);
title(‘Magnitude IIR Frequency Response (Z-Plane)’);
grid on
figure(5);
% Plot Notch-filtered sound
t = (0:length(Sound)-1)/fs;
plot(t, filteredAudio);
xlabel(‘Time (sec)’);
ylabel(‘Amplitude’);
title(‘Notch-Filtered Z-Plot’);
figure(6);
sgtitle(‘Redo Tone Removal Step 2: Magnitude Response for Notch Filter’);
f1 = 1574.99/fs * 2 * pi;
f2 = 3149.97/fs * 2 * pi;
f3 = 4724.96/fs * 2 * pi;
% Plot nulling filter frequency response and Z-plane representation
ww = -pi:pi/100:pi;
HH = freqz(bb,aa,ww);
bb = poly([exp(1j*f1) exp(-1j*f1) exp(1j*f2) exp(-1j*f2) exp(1j*f3) exp(-1j*f3)]);
aa = poly(0.80*[exp(1j*f1) exp(-1j*f1) exp(1j*f2) exp(-1j*f2) exp(1j*f3) exp(-1j*f3)]);
y = filteredAudio;
% Display the nulling filter frequency response
subplot(1,1,1);
plot(ww, abs(HH));
title(‘Notch Filter Frequency Response’);
xlabel(‘Frequency (Hz)’);
ylabel(‘Magnitude’);
fout = filter(bb,aa,y);
% Calculate the DC gain of the IIR Notch filter
ww_low = -pi:pi/10000:pi; % Frequencies close to zero
HH_low = freqz(b_total, a_total, ww_low, fs);
% Display the DC gain
dc_gain_iir = abs(HH_low(1));
disp([‘DC Gain of IIR Notch Filter: ‘, num2str(dc_gain_iir)]);
Specgrams of the input and output of the file from matlab for reference are attached. I am working on coding a matlab notch filter that is supposed to fitler out a tone in the audio file listed in the code. The Notch Filter works as it is supposed to except at the very beginning and at the very end the tone is still there and not filtered out and I need to have the tone completely gone. I am unable to figure out what to change in my code I have tried changing the frequencies I have tried changing where my filter starts and my notch width but nothing has solved my issue. Any help or suggestions is appreciated Thanks!
Code here below
% Load input sound
[Sound, fs] = audioread(‘SunshineSquare.wav’);
figure(1);
% Plot specgram of input sound
specgram(Sound, 512, fs);
title(‘Spectrogram of Input Sound (SunshineSquare.wav)’);
% Parameters of Notch Filter
frequencies = [1574.99, 3149.97, 4724.96];
notchwidth = 10;
% Tone Removal
a_total = 1;
b_total = 1;
for i = 1:length(frequencies)
Wn = [(frequencies(i) – notchwidth/2) / (fs/2), (frequencies(i) + notchwidth/2) / (fs/2)];
Wn = max(min(Wn, 0.99), 0.01);
[b, a] = butter(2, Wn, ‘stop’);
b_total = conv(b_total, b);
a_total = conv(a_total, a);
end
filteredAudio = filter(b_total, a_total, Sound);
% Play filtered sound
soundsc(filteredAudio, fs);
figure(2);
% Plot specgram of output sound after using notch filter
specgram(filteredAudio, 512, fs);
title(‘Specgram after Notch Filter’);
% Plot SunshineSquare sound
figure(3);
t = (0:length(Sound)-1)/fs;
plot(t, Sound);
xlabel(‘Time (sec)’);
ylabel(‘Amplitude’);
title(‘Notch-Filtered SunshineSquare Sound Plot’);
figure(4);
plot (ww,abs(HH));
zplane(bb,aa)
xlabel(‘Real’);
ylabel(‘Imaginary’);
title(‘Magnitude IIR Frequency Response (Z-Plane)’);
grid on
figure(5);
% Plot Notch-filtered sound
t = (0:length(Sound)-1)/fs;
plot(t, filteredAudio);
xlabel(‘Time (sec)’);
ylabel(‘Amplitude’);
title(‘Notch-Filtered Z-Plot’);
figure(6);
sgtitle(‘Redo Tone Removal Step 2: Magnitude Response for Notch Filter’);
f1 = 1574.99/fs * 2 * pi;
f2 = 3149.97/fs * 2 * pi;
f3 = 4724.96/fs * 2 * pi;
% Plot nulling filter frequency response and Z-plane representation
ww = -pi:pi/100:pi;
HH = freqz(bb,aa,ww);
bb = poly([exp(1j*f1) exp(-1j*f1) exp(1j*f2) exp(-1j*f2) exp(1j*f3) exp(-1j*f3)]);
aa = poly(0.80*[exp(1j*f1) exp(-1j*f1) exp(1j*f2) exp(-1j*f2) exp(1j*f3) exp(-1j*f3)]);
y = filteredAudio;
% Display the nulling filter frequency response
subplot(1,1,1);
plot(ww, abs(HH));
title(‘Notch Filter Frequency Response’);
xlabel(‘Frequency (Hz)’);
ylabel(‘Magnitude’);
fout = filter(bb,aa,y);
% Calculate the DC gain of the IIR Notch filter
ww_low = -pi:pi/10000:pi; % Frequencies close to zero
HH_low = freqz(b_total, a_total, ww_low, fs);
% Display the DC gain
dc_gain_iir = abs(HH_low(1));
disp([‘DC Gain of IIR Notch Filter: ‘, num2str(dc_gain_iir)]);
Specgrams of the input and output of the file from matlab for reference are attached. matlab MATLAB Answers — New Questions
what is this errol
Error(s) encountered while building simulation target MEX-file for model ‘TEST’.
Caused by:
Microsoft (R) Program Maintenance Utility Version 14.39.33523.0 Copyright (C) Microsoft Corporation. All rights reserved. ### Compiling "TEST_cgxe.c" cl.exe /c /Zp8 /GR /w /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2018a /DMATLAB_MEX_FILE /nologo /MD /I "D:Program FilesMATLABR2024aexterninclude" /I "D:Program FilesMATLABR2024asimulinkinclude" /I "D:Program FilesMATLABR2024artwcsrc" /I "D:downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "C:UsersASUSdocumentsMATLAB" /I "D:downloadssimu_lik1" /I "D:Downloadssimu_lik1slprjslprj_cprj" /I "D:Downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "D:Downloadssimu_lik1slprj" "TEST_cgxe.c" TEST_cgxe.c ### Compiling "TEST_cgxe_registry.c" cl.exe /c /Zp8 /GR /w /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2018a /DMATLAB_MEX_FILE /nologo /MD /I "D:Program FilesMATLABR2024aexterninclude" /I "D:Program FilesMATLABR2024asimulinkinclude" /I "D:Program FilesMATLABR2024artwcsrc" /I "D:downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "C:UsersASUSdocumentsMATLAB" /I "D:downloadssimu_lik1" /I "D:Downloadssimu_lik1slprjslprj_cprj" /I "D:Downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "D:Downloadssimu_lik1slprj" "TEST_cgxe_registry.c" TEST_cgxe_registry.c ### Compiling "m_sTa6ArGkvwlqBJMSyhiANF.c" cl.exe /c /Zp8 /GR /w /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2018a /DMATLAB_MEX_FILE /nologo /MD /I "D:Program FilesMATLABR2024aexterninclude" /I "D:Program FilesMATLABR2024asimulinkinclude" /I "D:Program FilesMATLABR2024artwcsrc" /I "D:downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "C:UsersASUSdocumentsMATLAB" /I "D:downloadssimu_lik1" /I "D:Downloadssimu_lik1slprjslprj_cprj" /I "D:Downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "D:Downloadssimu_lik1slprj" "m_sTa6ArGkvwlqBJMSyhiANF.c" m_sTa6ArGkvwlqBJMSyhiANF.c NMAKE : fatal error U1073: don’t know how to make ‘D:Program’ Stop.Error(s) encountered while building simulation target MEX-file for model ‘TEST’.
Caused by:
Microsoft (R) Program Maintenance Utility Version 14.39.33523.0 Copyright (C) Microsoft Corporation. All rights reserved. ### Compiling "TEST_cgxe.c" cl.exe /c /Zp8 /GR /w /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2018a /DMATLAB_MEX_FILE /nologo /MD /I "D:Program FilesMATLABR2024aexterninclude" /I "D:Program FilesMATLABR2024asimulinkinclude" /I "D:Program FilesMATLABR2024artwcsrc" /I "D:downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "C:UsersASUSdocumentsMATLAB" /I "D:downloadssimu_lik1" /I "D:Downloadssimu_lik1slprjslprj_cprj" /I "D:Downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "D:Downloadssimu_lik1slprj" "TEST_cgxe.c" TEST_cgxe.c ### Compiling "TEST_cgxe_registry.c" cl.exe /c /Zp8 /GR /w /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2018a /DMATLAB_MEX_FILE /nologo /MD /I "D:Program FilesMATLABR2024aexterninclude" /I "D:Program FilesMATLABR2024asimulinkinclude" /I "D:Program FilesMATLABR2024artwcsrc" /I "D:downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "C:UsersASUSdocumentsMATLAB" /I "D:downloadssimu_lik1" /I "D:Downloadssimu_lik1slprjslprj_cprj" /I "D:Downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "D:Downloadssimu_lik1slprj" "TEST_cgxe_registry.c" TEST_cgxe_registry.c ### Compiling "m_sTa6ArGkvwlqBJMSyhiANF.c" cl.exe /c /Zp8 /GR /w /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2018a /DMATLAB_MEX_FILE /nologo /MD /I "D:Program FilesMATLABR2024aexterninclude" /I "D:Program FilesMATLABR2024asimulinkinclude" /I "D:Program FilesMATLABR2024artwcsrc" /I "D:downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "C:UsersASUSdocumentsMATLAB" /I "D:downloadssimu_lik1" /I "D:Downloadssimu_lik1slprjslprj_cprj" /I "D:Downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "D:Downloadssimu_lik1slprj" "m_sTa6ArGkvwlqBJMSyhiANF.c" m_sTa6ArGkvwlqBJMSyhiANF.c NMAKE : fatal error U1073: don’t know how to make ‘D:Program’ Stop. Error(s) encountered while building simulation target MEX-file for model ‘TEST’.
Caused by:
Microsoft (R) Program Maintenance Utility Version 14.39.33523.0 Copyright (C) Microsoft Corporation. All rights reserved. ### Compiling "TEST_cgxe.c" cl.exe /c /Zp8 /GR /w /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2018a /DMATLAB_MEX_FILE /nologo /MD /I "D:Program FilesMATLABR2024aexterninclude" /I "D:Program FilesMATLABR2024asimulinkinclude" /I "D:Program FilesMATLABR2024artwcsrc" /I "D:downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "C:UsersASUSdocumentsMATLAB" /I "D:downloadssimu_lik1" /I "D:Downloadssimu_lik1slprjslprj_cprj" /I "D:Downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "D:Downloadssimu_lik1slprj" "TEST_cgxe.c" TEST_cgxe.c ### Compiling "TEST_cgxe_registry.c" cl.exe /c /Zp8 /GR /w /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2018a /DMATLAB_MEX_FILE /nologo /MD /I "D:Program FilesMATLABR2024aexterninclude" /I "D:Program FilesMATLABR2024asimulinkinclude" /I "D:Program FilesMATLABR2024artwcsrc" /I "D:downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "C:UsersASUSdocumentsMATLAB" /I "D:downloadssimu_lik1" /I "D:Downloadssimu_lik1slprjslprj_cprj" /I "D:Downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "D:Downloadssimu_lik1slprj" "TEST_cgxe_registry.c" TEST_cgxe_registry.c ### Compiling "m_sTa6ArGkvwlqBJMSyhiANF.c" cl.exe /c /Zp8 /GR /w /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMX_COMPAT_64 /DMATLAB_MEXCMD_RELEASE=R2018a /DMATLAB_MEX_FILE /nologo /MD /I "D:Program FilesMATLABR2024aexterninclude" /I "D:Program FilesMATLABR2024asimulinkinclude" /I "D:Program FilesMATLABR2024artwcsrc" /I "D:downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "C:UsersASUSdocumentsMATLAB" /I "D:downloadssimu_lik1" /I "D:Downloadssimu_lik1slprjslprj_cprj" /I "D:Downloadssimu_lik1slprjslprj_cgxeTESTsrc" /I "D:Downloadssimu_lik1slprj" "m_sTa6ArGkvwlqBJMSyhiANF.c" m_sTa6ArGkvwlqBJMSyhiANF.c NMAKE : fatal error U1073: don’t know how to make ‘D:Program’ Stop. fatal error u1073: don’t know how to make ‘d:pro MATLAB Answers — New Questions
While Loop not running
The following is while loop code that I have written for a project. No errors are popping up when and everything with the code appears to be fine but it never actually completes running. I am very stuck and would greatly appreciate some help. Here is my code:
i=3;
while i <= length(Datamatrix)
if isTwoInsideDays == true
L_entry_price = prevInsideDayHigh(i) + 0.0010;
L_stop_loss = prevInsideDayLow(i) – 0.0010; % Stop 10 pips below
L_take_profit = L_entry_price + 2 * (L_stop_loss – L_entry_price);
i=i+1;
while Close>L_entry_price==false;
i=i+1;
end
Signal(i)=1;
i=i+1;
while (Close(i) > L_take_profit || Close(i) < L_stop_loss) == false
i=i+1;
end
Signal(i)=-1;
end
endThe following is while loop code that I have written for a project. No errors are popping up when and everything with the code appears to be fine but it never actually completes running. I am very stuck and would greatly appreciate some help. Here is my code:
i=3;
while i <= length(Datamatrix)
if isTwoInsideDays == true
L_entry_price = prevInsideDayHigh(i) + 0.0010;
L_stop_loss = prevInsideDayLow(i) – 0.0010; % Stop 10 pips below
L_take_profit = L_entry_price + 2 * (L_stop_loss – L_entry_price);
i=i+1;
while Close>L_entry_price==false;
i=i+1;
end
Signal(i)=1;
i=i+1;
while (Close(i) > L_take_profit || Close(i) < L_stop_loss) == false
i=i+1;
end
Signal(i)=-1;
end
end The following is while loop code that I have written for a project. No errors are popping up when and everything with the code appears to be fine but it never actually completes running. I am very stuck and would greatly appreciate some help. Here is my code:
i=3;
while i <= length(Datamatrix)
if isTwoInsideDays == true
L_entry_price = prevInsideDayHigh(i) + 0.0010;
L_stop_loss = prevInsideDayLow(i) – 0.0010; % Stop 10 pips below
L_take_profit = L_entry_price + 2 * (L_stop_loss – L_entry_price);
i=i+1;
while Close>L_entry_price==false;
i=i+1;
end
Signal(i)=1;
i=i+1;
while (Close(i) > L_take_profit || Close(i) < L_stop_loss) == false
i=i+1;
end
Signal(i)=-1;
end
end while loop MATLAB Answers — New Questions