Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Given the following code:
t = -5:.1:5;
w = pi;
x = zeros(101,1);
Xt = zeros(101,1);
for i = 1 : 101;
x = exp((-3*t)+(-1i*w*t));
Xt = trapz(t, x);
end
disp (length(x))
disp (length(Xt))
disp (Xt)
The values of Xt do not change, which is a problem.
How should this be coded in order for Xt to change when x is changed?
Side note:
Xt(i) = trapz(t,x);
Reduces the vector from length 101 to length 1 and therefore cannot be used.
i am not sure if this is what you wanted. anyways while working on imaginary numbers it is always a good idea to not use i and j as common variables, just to avoid confusion (IMO)
xt = zeros(101,1);
x = exp((-3.*t)+(-1i*w.*t));
for k=2:101
xt(k)=trapz(t(1:k),x(1:k));
end
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 months ago.
Improve this question
Hi i am trying to get two returns from the following code in MATLAB:
function [Xq, SNq] = cuantificacion(x,xmax,xmin,b)
N = input('Introduce un numero de muestras: ');
L = 2^b;
delta = (xmax-xmin)/L;
if(abs(x)<xmax)
Xq = (fix((abs(x)/delta)) + 1/2)*delta*sign(x);
else
Xq = ((L-1)/2)*delta*sign(x);
end
p = 0;
q = 0;
for i = 0:N
p = p+x^2;
q = q + (Xq - x);
end
Px = 1/N*p;
Pq = 1/N*q;
SNq = 10*log(Px/Pq);
end
But i only get one return and I don't understand why.
Thanks to Ander i was just calling it wrong. I had to call it:
[return1, return2] = cuantificacion(x,xmax,xmin,b);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have this trigonometric equation;
cos(2*pi*50*t)+cos(2*pi*100*t)
I want to graphic of equation and I want to find field for a period. How can I do?
Graph:
>> f = #(t) cos(2*pi*50*t) + cos(2*pi*100*t);
>> x = linspace(0, 1/50, 100);
>> y = f(x);
>> plot(x,y)
Area over 1 period:
>> integral(f, 0, 1/50)
or just do it manually:
∫ ( cos(2π·50t) + cos(2π·100t) ) dt =
-1/2π·( 1/50·sin(2π·50t) + 1/100·sin(2π·100t) )
which, evaluated between 0 and 1/50, equals 0.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'd like to write the Matlab code for the following equation:
z(k)=lamda*x(k)+(1-lamda)*z(k-1)
lamda can be of any value. x is a 1000x22 matrix. Z(0)=0.
Can anyone help me please?
You can use iteration function.same thing like this
function z = itrationFunctio(k,x,lambda)
if(k == 0)
z = 0;
else
z = lambda*x+(1-lambda)*itrationFunctio((k-1),x,lambda);
end
and in your code just call itrationFunctio(k,x,lambda).
Does that vectorized solution work for you?
% parameters
x = rand(10,1);
lambda = 2;
% init z, normalize with (1-lambda)
z(2:numel(x)) = lambda/(1-lambda)*x(2:end);
% cumsum, denormalize with (1-lambda)
z = cumsum(z)*(1-lambda)
However I don't get why your x is a matrix and not a vector. What is z supposed to be, in what dimension works k? So in case xrepresents a couple of vectors you want to calculate in parallel, that could work:
% parameters
x = rand(1000,22);
lambda = 2;
% init z, normalize with (1-lambda)
z(2:size(x,1),:) = lambda/(1-lambda)*x(2:end,:);
% cumsum, denormalize with (1-lambda)
z = cumsum(z,1)*(1-lambda)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have a function (the hill function) when X and K are the same (x==k) the output should be 0.5, when I test the function it gives a result of 0.5, when I try to plot it, I do not get 0.5 for my Y. Can anyone explain what I am doing wrong?
n = 1;
k = 1;
x = [0:0.01:2].';
y = (x.^n)/((x.^n)+(k.^n));
plot(x,y);
n = 1;
k = 1;
x = [0:0.01:2].';
y = (x.^n)./((x.^n)+(k.^n));
plot(x,y);
You missed a dot before the division.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to generate two signals which in the end I want to connect. The problem is that the end condition of the 1st signal can be quite different compared to the initial conditions in my 2nd signal. Subsequently it can result in a sudden and unrealistic jump in my final signal. Final signal is the 2 connected signals.
How could I smooth the connection in my final signal?
Thanks!
What about some sort of cross-fading:
S1 = rand(1000,1);
S2 = rand(1000,1) + 1;
%\\ cross-fade over last 200 elements
n = 200;
W = linspace(1,0,n)'; %'
S1(end-n+1:end) = S1(end-n+1:end).*W;
S2(1:n) = S2(1:n).*(1-W);
S12 = zeros(size(S1,1) + size(S2,1) - n, 1);
S12(1:size(S1,1)) = S1;
S12(end-size(S1,1)+1:end) = S12(end-size(S1,1)+1:end) + S2;
This was using a linear weighting for the fading, you might choose something else but I think this will sort of work.