Demonstration of an Oversampling FIR Filter: Difference between revisions

From Class Wiki
Jump to navigation Jump to search
(Created page with "This is a demo of oversampling. You can use the three term average filter, <math>1/2 \delta (t+T/(greg T)) + \delta (t) + 1/2 \delta (t-T/(greg T))</math>, or a filter from...")
 
No edit summary
Line 1: Line 1:
This is a demo of oversampling. You can use the three term average filter,
This is a demo of oversampling. You can use the three term average filter,
<math>1/2 \delta (t+T/(greg T)) + \delta (t) + 1/2 \delta (t-T/(greg T))</math>, or a filter from the inverse Fourier transform of a brick wall filter.
<math>1/2 \delta (t+T/(N T)) + \delta (t) + 1/2 \delta (t-T/(N T))</math>, or a filter from the inverse Fourier transform of a brick wall filter.


<nowiki>
<nowiki>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Coders: Nory Salsbery, Carlos Flores, Austin von Pohle
%
% Class: Signals and Systems (Hang out With Dr. Frohne Time)
%
% Description: This is an FIR filter that over samples by
% a variable amount.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



close all
close all

Revision as of 22:07, 9 November 2017

This is a demo of oversampling. You can use the three term average filter, , or a filter from the inverse Fourier transform of a brick wall filter.

close all clear all clf; average = false; %Oversamples, N, (Integers Only) N=2; sum=0; % Sample rates Ts=1/1000; %Filter Sample Rate T=(1/N)*Ts; Totaltime = .1; % For the frequency response delta_f=1/(1000*Ts); f=-1/T:delta_f:1/T; if (average) display("Using Cheesy Average Filter") hf=[.5,1,.5]; sum=1+cos(pi*f*T); M=1; N=2; else %Discrete number of sample points M=1; %Creating Filter Funtion hf=[]; for m=-M:M; if (m==0) h=1/N; else h=sin(pi*m/N)/(pi*m); endif hf=[hf h]; sum=sum+h*exp(-i*2*pi*f*m*T); endfor endif %Filter impulse response. plot(hf,'r*') title('Filter impulse response') xlabel('n') %Frequency Response of our filter figure() plot(f,20*log10(abs(sum))) title('Frequency Response of Our FIR Filter') xlabel('Frequency (Hz)') ylabel('Response (db)') text(-1.5,-5,['M = ',num2str(M)]) % We want to see what this looks like. % Make a signal that is swept in frequency t = 0:Ts:Totaltime; f=600*t;%Frequency of sandy patty %Sandy Patty. xs = sin(2*pi*f.*t); figure() % Plots Sandy Patty scatter(t,xs) xn=zeros(1,N*length(xs)); xn(1:N:length(xn))=xs(1:1:length(xs)); % FIR filter hp=fliplr(hf); for j=2*M+1:length(xn) y(j-2*M)=xn(j-2*M:j)*hp'; endfor % for c=1:(length(xs)) % xn=[xn xs(c) zeros(1,N-1)]; % end % Filtered Sandy Patty %y=filter(real(hf),1/N,xn); %t2 = 0:T:(Totaltime+(N-1)*T); t2 = 0:T:T*(length(y)-1); figure()%Plot Filtered Sandy Patty scatter(t2,y) title('Oversampled Signal') xlabel("time (s)")