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.
MATLAB QUESTION: I have to write a function that pretty much cleans number. these are the...
MATLAB QUESTION: I have to write a function that pretty much cleans number. these are the instructions Inputs: number1 - a 1d of array of number, size doesn't matter outputs: number2 - all number in number1 that are 0 need to be set to nan and return via number2. data - storing the number of 0's in number1 that pretty much are being set to nans here's the code: function [number2, data] = cleanNumber(number1) %add your code below.. end code...
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 have been working on this assignment in Java programming and can not get it to...
I have been working on this assignment in Java programming and can not get it to work. This method attempts to DECODES an ENCODED string without the key.    public static void breakCodeCipher(String plainText){ char input[]plainText.toCharArray(); for(int j=0; j<25; j++){ for(int i=0; i<input.length; i++) if(input[i]>='a' && input[i]<='Z') input[i]=(char)('a'+((input[i]-'a')+25)%26); else if(input[i]>='A'&& input[i]<='Z') input[i]=(char)('A'+ ((input[i]-'A')+25)%26); } System.out.println(plainText)    }
Hello, I have this question that I have been trying to solve for days. I am...
Hello, I have this question that I have been trying to solve for days. I am always able to solve the first part of the question, but I am never able to get the second part. Please help me understand how to set up this problem so I am able to solve it! Q: Let's revisit the banked curves from earlier to see another reason they are useful.We are building a road, and at one place we need to make...
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
MATLAB Coding. Please answer with respected Matlab code format HW 2_5 Determine the two roots of...
MATLAB Coding. Please answer with respected Matlab code format HW 2_5 Determine the two roots of f(x) = 2x cos(2x) − (x − 2)^2 , using falsepos.p, accurate to 3 sig figs. Plot these points on the graph with a star marker.
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...
I have to create a light dispersion prism animation in Matlab. I need a well-explained Matlab...
I have to create a light dispersion prism animation in Matlab. I need a well-explained Matlab script which works.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT