Demonstration of an Oversampling FIR Filter: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
Note that the "brick wall" filter (average=false) has a problem where the points that start at zero don't come up high enough. For example, try M=1, N=2, and average = false. What is this from and how do you suppose you might fix this? |
Note that the "brick wall" filter (average=false) has a problem where the points that start at zero don't come up high enough. For example, try M=1, N=2, and average = false. What is this from and how do you suppose you might fix this? |
||
<nowiki> |
<nowiki> |
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|||
% Coders: Nory Salsbery, Carlos Flores, Austin von Pohle |
% Coders: Nory Salsbery, Carlos Flores, Austin von Pohle |
||
% |
% |
||
Line 13: | Line 12: | ||
% a variable amount. |
% a variable amount. |
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||
close all |
close all |
||
clear all |
clear all |
||
Line 30: | Line 27: | ||
delta_f=1/(1000*Ts); |
delta_f=1/(1000*Ts); |
||
f=-1/T:delta_f:1/T; |
f=-1/T:delta_f:1/T; |
||
if (average) |
if (average) |
||
display("Using Cheesy Average Filter") |
display("Using Cheesy Average Filter") |
||
Line 52: | Line 48: | ||
endfor |
endfor |
||
endif |
endif |
||
%Filter impulse response. |
%Filter impulse response. |
||
plot(hf,'r*') |
plot(hf,'r*') |
||
title('Filter impulse response') |
title('Filter impulse response') |
||
xlabel('n') |
xlabel('n') |
||
%Frequency Response of our filter |
%Frequency Response of our filter |
||
figure() |
figure() |
||
Line 65: | Line 59: | ||
ylabel('Response (db)') |
ylabel('Response (db)') |
||
text(-1.5,-5,['M = ',num2str(M)]) |
text(-1.5,-5,['M = ',num2str(M)]) |
||
% We want to see what this looks like. |
% We want to see what this looks like. |
||
% Make a signal that is swept in frequency |
% Make a signal that is swept in frequency |
||
t = 0:Ts:Totaltime; |
t = 0:Ts:Totaltime; |
||
f=600*t;%Frequency of |
f=600*t;%Frequency of Sandy Patty |
||
%Sandy Patty. |
%Sandy Patty. |
||
xs = sin(2*pi*f.*t); |
xs = sin(2*pi*f.*t); |
||
Line 82: | Line 74: | ||
y(j-2*M)=xn(j-2*M:j)*hp'; |
y(j-2*M)=xn(j-2*M:j)*hp'; |
||
endfor |
endfor |
||
% for c=1:(length(xs)) |
|||
% xn=[xn xs(c) zeros(1,N-1)]; |
|||
% end |
|||
% Filtered Sandy Patty |
% Filtered Sandy Patty |
||
%y=filter(real(hf),1/N,xn); |
%y=filter(real(hf),1/N,xn); |
||
Line 93: | Line 82: | ||
title('Oversampled Signal') |
title('Oversampled Signal') |
||
xlabel("time (s)") |
xlabel("time (s)") |
||
</nowiki> |
</nowiki> |
Revision as of 22:21, 9 November 2017
This is a demo of oversampling. Setting average = true, you can use the three term average filter, , or with average = false, you get a filter derived from the inverse Fourier transform of a brick wall filter.
Note that the "brick wall" filter (average=false) has a problem where the points that start at zero don't come up high enough. For example, try M=1, N=2, and average = false. What is this from and how do you suppose you might fix this?
% 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 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 % 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)")