Filter() command is not passing through sine wave

1 vue (au cours des 30 derniers jours)
Sajith Sen
Sajith Sen le 15 Nov 2022
Modifié(e) : Askic V le 16 Nov 2022
Hello, I am having a bit of trouble getting the proper output from the filter() function in matlab. I am using two filter() commands in cascade to pass through a sine function input into a given transfer function at different n values, however, the output seems to be always coming out as 0.
After messing about a bit I figured out that it is due to the first coefficient of the numerator of the second fraction in my transfer function being 0, however I do not know what I can do to fix this as I cannot change my transfer function. Is there anything I can do?
(1 - a0) (1 - b1 + b2)z^-1
Transfer function : K* ------------------ ------------------------------------
1 - (a0)z^-1 1 - (b1)z^-1 + (b2)z^-2
This is my code for passing the input through to the fiilter functions, cascaded
The calculation of the variables is pretty long but this is one set of the variable values;
K = a = 0.9589
(1 - a0) = b = 0.8137
a0 = c = 0.1863
(1 -b1 + b2) = d = 3.2863
b1 = e = -1.517
b2 = f = 0.7697
input = sin(2*pi*1000*n/48000) (n equals 1 for this set of variables)
function dissy = displacement_output(a,b,c,d,e,f,input)
lpf_n = [a*b];
lpf_d = [1 -c];
rf_n= [0 d]; % first coefficent is zero
rf_d = [1 -e f];
z = filter(lpf_n,lpf_d,input);
dissy = filter(rf_n, rf_d, z);
end
Currently dissy is producing the value 0 for all values of n, which shouldn't be the case,
If anybody could clarify any of what is happening to me that would be great ahahah, thanks
Note: All the variables are values that i have calculated and double checked
  2 commentaires
Paul
Paul le 15 Nov 2022
Hi Sajith,
Instead of screenshots, just copy and paste all of your code into your question. Preferably, click the left-most icon in the code bar in the toolstrip to format as code. That way people can copy exactly what you did and be more effective in providing help.
Sajith Sen
Sajith Sen le 16 Nov 2022
yupp sorry about that, I've edited it now

Connectez-vous pour commenter.

Réponses (1)

Askic V
Askic V le 16 Nov 2022
Modifié(e) : Askic V le 16 Nov 2022
You do understand that "input = sin(2*pi*1000*n/48000) (n equals 1 for this set of variables) " means input is not sine wave but only a number, in this case (0.1305), do you?
Without going into details of your logic about the calculating the coefficients, based on your current code, I would test it like this:
clear
clc
close all
a = 0.9589;
b = 0.8137;
c = 0.1863;
d = 3.2863;
e = -1.517;
f = 0.7697;
% make this a sine wave
n = 1:100;
input = sin(2*pi*1000*n/48000);
subplot(2,1,1)
plot(n,input);
dissy = displacement_output(a,b,c,d,e,f,input);
subplot(2,1,2)
plot(n,dissy);
function dissy = displacement_output(a,b,c,d,e,f,input)
lpf_n = [a*b];
lpf_d = [1 -c];
rf_n= [0 d]; % first coefficent is zero
rf_d = [1 -e f];
z = filter(lpf_n,lpf_d,input);
dissy = filter(rf_n, rf_d, z);
end

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by