%INEL 4102 - BASIC ENGINEERING CIRCUITS %CAUSAL FIRST ORDER RC-FILTER %Ideal Low-pass filter versus RC-filter %Prof. Domingo Rodriguez % %PARAMETER SETTINGS************************************** Fs=10000; %Sampling Frequency Ts=1/Fs; %Sampling Period or Sampling Time N=300; %Length of each discrete signal or vector V=N*Ts; %Time duration (in seconds) for each signal fm=2000; %Cuttoff frequency Wn=2*fm/Fs; %Normalized frequency M=300; %Length of the impulse response signal R=10000; %Value of Resistor C=1/(2*pi*fm*R); %Value of Capacitor a=1/(R*C); %Time Constant Parameter h0=a; %Initial Condition Parameter t=0:Ts:V-Ts; %General time axis th=0:Ts:M*Ts-Ts; %Time axis for plotting impulse response signal f=-Fs/2:Fs/M:Fs/2-Fs/M; %Frequency axis %******************************************************** %RC-FILLTER hRC=h0*exp(-a*th); %RC-Filter impulse response function hmax=max(hRC); %Maximum value of impulse response function hRC=(hRC/hmax); %Normalized impulse response function fhRC=fft(hRC); %Fourier Transform of impulse response function sfhRC=fftshift(fhRC); %Frequency shift for two sided spectrum plot asfhRC=abs(sfhRC); %Absolute value calculation Hmax=max(asfhRC); %Maximum value of frequency response function asfhRC=(asfhRC/Hmax); %Normilized frequency response function % %******************************************************** %MATLAB FIR1 FILTER Wn=(2*fm)/Fs; %Normilized cut-off frequency for ideal filter h=fir1(N-1,Wn); %Impulse response function of ideal filter fh=fft(h); %Fourier transform of impulse response function sfh=fftshift(fh); %Frequency shift for two sided spectrum plot msfh=abs(sfh); %Absolute value calculation % %******************************************************** %PLOTS %******************************************************** plot(f,asfhRC,f,msfh,'r') %Plots of RC and Ideal filters grid xlabel('Frequency in Hz.') %Horizontal axis ylabel('Magnitude') %Vertical axis title('HL(f) and HRC(f)') %Title of plot