In: Electrical Engineering
Matlab filter responce and magnitude of filter question.
I have been working on this HW and I am not sure if I did something wrong. Here is my code.
%y[n]=x[n]+x[n-1]-x[n-4]-x[n-5];
%y[n]=y[n-1]-.9*y[n-2]+x[n]+x[n-1]
clear
clc
[x,fs] = audioread('toto.wav');
x = x(:,1);
dt = 1/fs;
t = 0:dt:(length(x)*dt)-dt;
plot(t,x); xlabel('Seconds'); ylabel('Amplitude');
num=[1 1 -.9];
den=[1 1 0 0 -1 -1];
sys=tf(num,den);
k=filter(num,den,x);
subplot(3,1,1);
plot(t,k);
title('filter response');
w=0:0.001:pi;
[h,om]=freqz(num,den,w)
m=20*log10 (abs(h))
an=angle(h)
subplot(3,1,2)
plot(om/pi,m)
title('mag spectrum of filter')
xlabel('freq')
ylabel('mag in db')
subplot(3,1,3)
plot(om/pi,an)
title('phase spectrum of filter')
xlabel('freq')
So I was playing around and when I use the 2nd equation at the top like in this code my filter response or the magnitude don't change. Why is that? Did I do something wrong? It doesn't even change if I change the values of the den either.
Dear user,
I think you are doing mistake in num ,den remaining code seems to be good
For this equation y[n]=x[n]+x[n-1]-x[n-4]-x[n-5];
use num=[1 1 0 0 0 -1 -1];den=[1];
For other equation
use
num=[1 1]; den=[1 -1 0.9];
%%
When these two edits are made code is working fine
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%y[n]=x[n]+x[n-1]-x[n-4]-x[n-5];
%y[n]=y[n-1]-.9*y[n-2]+x[n]+x[n-1]
clear
clc
t=0:1/44100:2;
fs=44100;
%x=cos(2*pi*5*t)+cos(2*pi*4*t)+cos(2*pi*15*t)+cos(2*pi*20*t);
%x=x';
x = x(:,1);
dt = 1/fs;
t = 0:dt:(length(x)*dt)-dt;
plot(t,x); xlabel('Seconds'); ylabel('Amplitude');
num=[1 1 0 0 0 -1 -1];
den=[1 ];
sys=tf(num,den);
k=filter(num,den,x);
subplot(3,1,1);
plot(t,k);
title('filter response');
w=0:0.001:pi;
[h,om]=freqz(num,den,w)
m=20*log10 (abs(h))
an=angle(h)
subplot(3,1,2)
plot(om/pi,m)
title('mag spectrum of filter')
xlabel('freq')
ylabel('mag in db')
subplot(3,1,3)
plot(om/pi,an)
title('phase spectrum of filter')
xlabel('freq')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Outputs:
for
y[n]=y[n-1]-.9*y[n-2]+x[n]+x[n-1]
and
for y[n]=x[n]+x[n-1]-x[n-4]-x[n-5];
note: I have used sinusoidal signals sampled at 44.1kHz to simulate above .I have commented them just use my code and pass your signal.
So i think mistake is in num ,den
Please let me know if you have any doubts
Thank You.