Filter coefficients in matlab [closed] - matlab

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 6 years ago.
Improve this question
I'm learning about signal processing and currently I have to do an speech synthesizer in Matlab. For emulate the resonator system of the mouth I've this transfer function:
R(z) = 1 - z ^(-1)
Can I implement this system with filter function in Matlab? I don't know how to extract the coeficients "a" and "b"...
Note: y = filter(b, a, x), where x is the input signal that we have to filter.
Thank you all!

Consulting the documentation for filter, you represent a transfer function as a rational function of coefficients such that:
The desired transfer function you want, Y(z) / X(z) = R(z) is equal to:
R(z) = 1 - z^{-1}
Here a(1) is implicitly equal to 1. Therefore, b(1) = 1 and b(2) = -1 referring to the above equation. All of the coefficients in the denominator are 0 except for a(1) which is equal to 1.
As such, a = 1; b = [1 -1]; and so filtering your signal is simply:
a = 1; b = [1 -1];
y = filter(b, a, x);
x is the signal of interest you want to filter.

Related

Hash functions violating some pre image properties [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
Suppose H(xy) = H(x) * H(y) . Clearly preimage properties are violated. How can we find x, y such that H(x) = H(y) mod (2^k)
2^k is a very special modulus. You can prove the following strengthened version of Euler's theorem:
Suppose that x is any postive integer. Then x^phi(2^k) (mod 2^k) is equal to either 0 or 1, with 1 if and only if x is odd.
Proof:
If x is odd, then gcd(x,2^k) = 1, hence x^phi(2^k) (mod 2^k) = 1 by Euler's theorem.
Suppose that x is even. The result is trivially true if x = 0, so suppose that x > 0. Write x = (2^s)*y where y is odd and s > 0. Note that
phi(2^k)` = 2^(k-1)
But then,
x^phi(2^k) = (2^s*y)^phi(2^k)
= (2^s)^phi(2^k) * y^phi(2^k)
= 2^(s*phi(2^k)) * y^phi(2^k)
= 2^(s*2^(k-1)) * y^phi(2^k)
= 0 * y^phi(2^k) = 0 (mod 2^k)
the last line follows from the fact that s*2^(k-1) >= k hence 2^(s*2^(k-1)) is a multiple of 2^k.
Note that if x is even then you actually have x^k = 0 (mod 2^k), so raising x to the power phi(2^k) is overkill for any but the smallest k.
Given this lemma, it is now trivial to see that there exists distinct x,y with either H(x) = H(y) = 0 or H(x) = H(y) = 1. Since it seems to be homework, I'll leave the details to you.

Matlab 3x3 weighted averaging filter [closed]

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 6 years ago.
Improve this question
Following advise from another post, I created a basic 3x3 averaging filter as follows:
blurP = zeros(512, 512);
for i = 1:510
for j = 1:510
sum = 0;
for k = i:i+2
for l = j:j+2
sum = sum+P(k,l);
end
end
blurP(i+1,j+1) = mean2(P(i:i+2,j:j+2));
end
end
imshow(P), figure, imshow(blurP, []);
I need to create a weighted filter with two options: One counts the center element (of the 3x3 grid) twice, thus giving me ten elements in total. The other has sixteen elements in total, with the center element counted four times and the adjacent ones counted twice—only the corner elements of the 3x3 grid are counted once.
The easiest option is to just use convolution (via the conv2 function). Then designing your kernels is a simple as writing out exactly what you described:
kernel1 = [1 1 1
1 2 1
1 1 1]/10;
blurP1 = conv2(P, kernel1, 'same');
and
kernel2 = [1 2 1
2 4 2
1 2 1]/16;
blurP2 = conv2(P, kernel2, 'same');

How to get solution to make this determinant zero? [closed]

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 7 years ago.
Improve this question
A = [A-x(1) B-x(2) C-x(3);D-x(4) E-x(5) F-x(6); G-x(7) H-x(8) I-x(9)]
I have to obtain x(1)...x(9) for det(A) = 0.
Given a 3x3 matrix A
its determinant is
therefore you need to solve |A| = 0. For your case we are given
The easiest solution for x so that |A| = 0 is when
a - x(1) = 0
b - x(2) = 0
c - x(3) = 0
which leads to
x(1) = a
x(2) = b
x(3) = c
so
x = A
is the most trivial solution. There exists an infinite number of solutions to this problem, this is just one. You could choose another solution where
a - x(1) != 0
b - x(2) != 0
c - x(3) != 0
and then you would have to set
ei - fh = 0
di - fg = 0
dh - eg = 0
which would involve simultaneous equations.
I suggest before trying to code up a solution you work through one by hand like I've done here.

Reorder the numbers after delete some of them in matlab [closed]

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
I have a vector [1 2 3 4 ... 100] and another vector storing the numbers I want to delete like [2 3 4]. After deleting, the numbers in original vector should be mapped to another order, for example, 1->1, 5->2, 6->3, etc. Is there any efficient way to do this? Thanks a lot!
I'd use setdiff:
% original vector
A = 1:100;
% elements to be removed
B = [2 3 4 18 21];
% new order (indices)
C = randperm(numel(A)-numel(B));
% Step 1) remove the elements
[D,I] = setdiff(A,B); % ordered
D = A(I); % restore original order
% Step 2) re-order the elements
D = D(C)
You can do:
original_vector = 1:100;
delete_vector = [2 3 4];
for ii = 1:length(delete_vector)
original_vector(original_vector==delete_vector(ii)) = [];
end

set of n-linear equations in matlab [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I have some trouble on setting of n-linear equations in matlab.I don't know how can I declare in matlab.I need matlab code for setting of n-linear equations..
You can write n-linear equations as one matrix equation to solve it. Here you can find great example:
http://blogs.mathworks.com/pick/2007/09/13/matlab-basics-video-solving-linear-equations/ (video!)
See also these pages:
http://en.wikipedia.org/wiki/System_of_linear_equations
http://en.wikipedia.org/wiki/Matrix_equation
You can solve a linear system in various ways, depending on whether there exists a unique solution or not.
A simple way is by reducing it to reduced-echelon form (rref).
Consider the system:
x + 5y = 4
2x - y = 1
You can write the coefficient matrix A, and the RHS, B as follows: (' is the transpose operator)
>> A = [1 5; 2 -1]
A =
1 5
2 -1
>> B = [4 1]'
B =
4
1
You can write it as an augmented matrix (A|B):
>> horzcat(A,B)
ans =
1 5 4
2 -1 1
And then find the REF(A|B)
>> rref(ans)
ans =
1.0000 0 0.8182
0 1.0000 0.6364
And hence x ~ .8182, y ~ .6364.
The absolutely fastest way to solve linear equations in MATLAB is simply to setup your equation on the form
AX = B
and then solve by
X = A\B
You can issue
help mldivide
to find more information on matrix division and what limitations it has.
A Code for iterative method Guase Seidel
tol is error tolerance
x0 is first guess for solution
function seidel(A,b,x0,tol,itmax)
%Solve the system Ax=b using the Gauss-Seidel iteration method.
clc
% =======================================================
% Programmer : A. Ziaee mehr
%
help seidel
n=length(b);
x=zeros(n,1);
%fprintf('\n')
disp('The augumented matrix is = ')
Augm=[A b]
Y=zeros(n,1);
Y=x0;
for k=1:itmax +1
for ii=1:n
S=0;
for jj=1:ii-1
S=S+A(ii,jj)*x(jj);
end
for jj=ii+1:n
S=S+A(ii,jj)*x0(jj);
end
if (A(ii,ii)==0)
break
end
x(ii)=(-S+b(ii))/A(ii,ii);
end
err=abs(norm(x-x0));
rerr=err/(norm(x)+eps);
x0=x;
Y=[Y x];
if(rerr<tol)
break;
end
end
% Print the results
if (A(ii,ii)==0)
disp('division by zero')
elseif (k==itmax+1)
disp('No convergence')
else
%fprintf('\n')
disp('The solution vector are : ')
fprintf('\n')
disp('iter 0 1 2 3 4 ... ');
fprintf('\n')
for ii=1:n
fprintf('%1.0f= ',ii);
fprintf('%10.6f ',Y(ii,1:k+1));
fprintf('\n')
end
fprintf('\n')
disp(['The method converges after ',num2str(k),' iterations to'])
x
end