Question

In: Electrical Engineering

The MATLAB routine analog _ filter1.m is a simulated analog filter. (Calling structure: output = analog...

The MATLAB routine analog _ filter1.m is a simulated analog filter. (Calling structure: output = analog _ filter1(input);). Repeat the strategy used in Problem 1.2, but generate the input sine waves in MATLAB and plot the output. Make Ts = 0.001 s and the number of points N = 1000. To generate sine waves, defne the time vector t = (0:999)*Ts as in Example 1.3. Use this vector to generate the input sine waves at various frequencies: input = sin(2*pi*f*t);. Use frequencies of 2, 10, 15, 20, 30, 40, 50, 60, 80, 90, 100, 150, 200, 300, and 400 Hz.

Find the amplitude of the output of analog _ filter1.m using MATLAB’s max operator and plot the resulting values in dB versus log frequency. This gives an approximation of the flter’s frequency characteristics or spectrum. Use this spectrum with the grid function enabled to determine the type, bandwidth, and attenuation slope of the flter. [Hint: Put the desired input frequencies in an array and use a for-loop to generate the input sine waves. Store the maximum values of the flter’soutput in an array for plotting. Plot the 20 log of the output values against the frequency array using the semilogx routine.

I'd like to know the code from the beginning until end for my self-study because my instructor didnt teach me this even once. Thank you so much.

analog_filter1.m -> https://pastebin.com/htg8Yhhg (just open the link and copy-paste it into matlab)

Solutions

Expert Solution

Given That :

The MATLAB routine analog _ filter1.m is a simulated analog filter.

Repeat the strategy used in Problem 1.2, but generate the input sine waves in MATLAB and plot the output.

Make Ts = 0.001 s and the number of points N = 1000. To generate sine waves, defne the time vector t = (0:999)*Ts.

Use this vector to generate the input sine waves at various frequencies: input = sin(2*pi*f*t);. Use frequencies of 2, 10, 15, 20, 30, 40, 50, 60, 80, 90, 100, 150, 200, 300, and 400 Hz.

Solution :

Given simulated Filter code is written in a seperate file with name analog_filter1.m

function output=analog_filter1(input)
[b,a]=butter(4,0.2,'High');
[b1,a1]=butter(2,0.12);
input=filter(b1,a1,input);
output=filter(b,a,input);
end

%----APPROXIMATE FILTER CHARACTERSTICS USING MATLAB----%

clear all; close all;

%______PROGRAM STARTS____%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%---Genetarion of Input Sine Waves----%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Ts=0.001; %The sample interval is taken as given in the problem
N=1000; %No.of Samples is taken as 1000 as given in the problem
t=(0:N-1)*Ts; %Form the time scale with the choosen values of N and Ts

%---Taking all the frequency values in an array----%
f=[2 10 15 20 30 40 50 60 70 80 90 100 150 200 300 400];
filter_response=zeros(1,length(f));

for i=1:length(f)
input=sin(2*pi*f(i)*t);
subplot(4,4,i),plot(t,input);title(['i/p for f=',num2str(f(i))],'FontSize',18);
  
%---Get the output of the simulated filter given---%
output=analog_filter1(input);
%----Take the maximum value of the Output of the filter for a particular input frequency f(i)----%
output_max=max(abs(output));
filter_response(i)=output_max;
end

%----Plot the Filter characterstics with amplitude taken in dB on a log plot---%
figure,
semilogx(f,20*log(filter_response));
title('Filter Frequency Characterstics in log plot','FontSize',18);
xlabel('Frequency','FontSize',18); ylabel('Output in dB','FontSize',18);
grid on;

%____PROGRAM ENDS____%

The Grid is On.

And if we observe the Output Filter Characterstics,

It looks like a bandpass filter with central frequency of 100Hz.

The Bandwidth is approximately 185Hz (which is the frequency range where the Output is not less than 3dB of the Max value)

Let us consider two points which are at a distance of a decade, (-29.37dB,100Hz) and (-98.02dB, 10Hz) => The Attenuation slope is (98.02-29.37)db/decade=68.65dB/decade.

All the values are only approximate as we have taken very less number of frequency values as given in the problem statement.


Related Solutions

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.
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 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)...
a Matlab code for Kalman Filter to combine GPS and Odometer
a Matlab code for Kalman Filter to combine GPS and Odometer
please Use Matlab to plot simulated results and to plot and conduct the mathematical analysis of...
please Use Matlab to plot simulated results and to plot and conduct the mathematical analysis of the data below: note: I only need these things 1- simulate the RC filter in the frequency domain in order to obtain magnitude and phase response plots. 2-obtain the transient response plots of the capacitor voltage and the current as functions of time. Channel 2 Data Time Scale: 0.002 seconds/div Voltage Scale: 2.0 volts/div Waveform Data: 500 points Time Voltage --------------------- -0.01 2.68675 -0.00996...
An amplifier with an output impedance of 75 ? is connected to a filter with a...
An amplifier with an output impedance of 75 ? is connected to a filter with a characteristic impedance of 60 – 20j ?. Design a single shunt stub matching network using an open circuit for a frequency of 500 MHz. Show ALL calculations. a) Calculate the normalized load admittance. b) Determine the distance (in ?) to the stub in the direction of the generator. c) Determine the normalized input admittance of the stub. d) Calculate the susceptance of the stub....
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
How to design FIR lowpass filter using matlab. Note : Do not write matlab code. Only...
How to design FIR lowpass filter using matlab. Note : Do not write matlab code. Only explain the steps of designing filter
1. We want to design a discrete-time bandpass filter that samples and processes analog signals. The...
1. We want to design a discrete-time bandpass filter that samples and processes analog signals. The frequency response is 0 at 0 Hz and 500 Hz, and resonant occurs at 125 Hz. The sampling interval T= 1 msec. Find the transfer function H[z] of these filters and mark the poles and zeros on the complex plane.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT