Question

In: Electrical Engineering

Matlab filter responce and magnitude of filter question. I have been working on this HW and...

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.

Solutions

Expert Solution

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.


Related Solutions

Code in Matlab for a low pass filter and a high pass filter. Each filter must...
Code in Matlab for a low pass filter and a high pass filter. Each filter must show the frequency response (magnitude and phase) in graphs properly labelled.
What I am trying to do is to design a Butterworth Bandpass filter using Matlab, High...
What I am trying to do is to design a Butterworth Bandpass filter using Matlab, High frequency must equal to 16 Hz and lower frequency must be 10Hz (passBand). and the input signal must be a white noise signal. here is my code : mu=0; sigma=2; X= sigma*randn(500,1)+mu; %Generating White Noise signal Fs=500;%Sampling Frequency Fh= 16; Fl=10; order=6; [b,a]=butter(order,[Fh Fl]/(Fs/2),'bandpass');%Butterworth BandPass filter XX=filtfilt(b,a,X);%filter the signal both forward and backword in time Actually, I am not sure about Fs value that...
I operate a small company specializing in manufactured housing. I have been working with the XX...
I operate a small company specializing in manufactured housing. I have been working with the XX Small Business Development Center and they thought you might be able to help me since you are completing a course in strategic management. I am not sure if strategic planning would benefit me. What do you think? I also have a couple of specific questions for you. 1) Did you learn anything that would help me analyze my business environment? 2) Someone told me...
a Matlab code for Kalman Filter to combine GPS and Odometer
a Matlab code for Kalman Filter to combine GPS and Odometer
This is the HW question I cannot get the correct answer for. I've completed the first...
This is the HW question I cannot get the correct answer for. I've completed the first step but I cannot seem to get the correct numbers for EFN for 20, 25 and 30%!?!? See below for given financial statements and my table with the pro forma of 20, 25 and 30% numbers The most recent financial statements for Scott, Inc., appear below. Interest expense will remain constant; the tax rate and the dividend payout rate also will remain constant. Costs,...
Diabetes question You are a nurse working in the accident and emergency department and have been...
Diabetes question You are a nurse working in the accident and emergency department and have been allocated to assess and care for Jack. Jack is a 27 years old, single man of Asian heritage who is homeless. He was diagnosed with Type 1 diabetes 12 months ago. He has a history of bipolar disorder. He has presented to the emergency department feeling unwell An assessment finding reveals the following on Jack Visually, Jack looks unwell and complains of nausea, abdominal...
Hi, I am taking stats class and I have one question. I have been struggling with...
Hi, I am taking stats class and I have one question. I have been struggling with it for few hours. To investigate the fluid mechanics of swimming, twenty swimmers each swam a specified distance in a water-filled pool and in a pool where the water was thickened with food grade guar gum to create a syrup-like consistency. Velocity, in meters per second, was recorded and the results are given in a table below. The researchers concluded that swimming in guar...
Matlab Design a FIR filter directly using fir1 function in matlab with parameter M = 50....
Matlab Design a FIR filter directly using fir1 function in matlab with parameter M = 50. Design FIR filters with different M = 5, 10, 50, 100, 500 and plot their frequency responses H(e j?) on the same figure.
In Matlab, Design a model for a bandpass filter with a bandwidth of 4000 Hz, and...
In Matlab, Design a model for a bandpass filter with a bandwidth of 4000 Hz, and a center frequency as specied below. Once you have the model, it is easy to programmatically change the center frequency. center frequency: 20 KHz, 24.5 KHz, 29 KHz, 33.5 KHz, 38 KHz, 42.5 KHz, 47 KHz
In Matlab, Design a model for a bandpass filter with a bandwidth of 4000 Hz, and...
In Matlab, Design a model for a bandpass filter with a bandwidth of 4000 Hz, and a center frequency as specied below. Once you have the model, it is easy to programmatically change the center frequency. center frequency: 20 KHz, 24.5 KHz, 29 KHz, 33.5 KHz, 38 KHz, 42.5 KHz, 47 KHz
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT