Thread Subject: Using Low pass filter in Matlab

Subject: Using Low pass filter in Matlab

From: guj

Date: 12 Nov, 2009 06:49:02

Message: 1 of 1

Can any one show me an example where low pass filter is been applied to cut the high frequencies .... below is my code i am trying to reconstruct the figure b with applying box car ...it will be great if i can get some help

As i dont know how i can construct my frequency spectra back ..... i am just trying to create a simple demonstration here ...I created a sinc filter and box car filter in last two figures but i dont know how to apply.....

I will really appreciate your guidance

Thanks

%Showing the Uniform sampling reconstruction
close all;
clear all;
N=64;
Fs=100; %Sampling frequency
Ts=1/Fs; %Sampling time
t=Ts*[-N/2:N/2-1]
fo=2;%Fundamental frequency
f1=4;%Fundamental frequency
s=2*sin(2*pi*fo*t)+2*sin(2*pi*f1*t);


subplot(5,2,1)
  plot(t,s)
  xlabel('t(Seconds)','fontsize',10)
  ylabel('Amplitude','fontsize',10)
  axis([-0.33 0.31 -3.6 3.6])
  text(-0.37,4.2,'(a)')
  box on
  grid on

% Plotting the Frequency spectra
f=1/Ts/N/2*[-N:2:N-1];
s_f=fft(s);
subplot(5,2,2)
  plot(f,fftshift(abs(s_f/max(s_f))))
  xlabel('f (Hertz)','fontsize',10)
  ylabel('Amplitude','fontsize',10)
 axis([ -40 40 0 1])
  text(-45,1.25,'(b)')
  box on
  grid on

%Creating train of impulses
x_range=[0:1:63];
  imp_train=zeros(1,64);
  select=find(rem(x_range,4)==0);
imp_train(select)= ones(size(select));

subplot(5,2,3)
  bar(t,imp_train)
  xlabel('t(Seconds)','fontsize',10)
  ylabel('Amplitude','fontsize',10)
  axis([-0.33 0.31 -3.6 3.6])
  text(-0.38,4.0,'(c)')
  box on
  grid on
 

%Creating frequeny spectra of the spikes
imp_train_f=fft(imp_train);

subplot(5,2,4)
  bar(f,fftshift(abs(imp_train_f/max(imp_train_f))))
   xlabel('f (Hertz)','fontsize',10)
  ylabel('Amplitude','fontsize',10)
  text(-64,1.25,'(d)')
   axis([ -44 40 0 1])
  box on
  grid on
  

%Multiplying spikes with signal in time domain
  imp_train_s=imp_train.*s;
 
subplot(5,2,5)
hold on
bar(t,imp_train_s)
  plot(t,s,'--r')
hold off
 xlabel('t(Seconds)','fontsize',10)
  ylabel('Amplitude','fontsize',10)
  axis([-0.33 0.31 -3.6 3.6])
  text(-0.39,4.5,'(e)')
  box on
  grid on



%Convolving the Frequency spectra of the spike and frequency spectra of signal

Conv_imp_s_f=conv(s_f(:),imp_train_f(:))

  length_output=length(s_f)+length(imp_train_f)-1;
k=linspace(-2*N/2,2*N/2,length_output);
  subplot(5,2,6)
      plot(k,abs(Conv_imp_s_f/max(Conv_imp_s_f)))
  
xlabel('f (Hertz)','fontsize',10)
  ylabel('Amplitude','fontsize',10)
  text(-72,1.25,'(f)')
  axis([-65 65 0 1.0])
  box on
  grid on
%Constructing a sinc function


%Constructing a Box car function
x_range=[0:1:63]
rec= zeros(1,64);
select =find(x_range>26 & x_range<38);
rec(select) = ones(size(select));
subplot(5,2,8)
  plot(f,rec,'r-')
  xlabel('f (Hertz)','fontsize',10)
  ylabel('Amplitude','fontsize',10)
axis([ -40 40 0 1])
   %axis([-25 25 0 1])
   text(-28,1.25,'(h)')
   box on
   grid on
   


%Constructing a sinc function
subplot(5,2,7)
  sinc = real(fftshift(ifft(fftshift(rec))));
plot([-32:31], sinc, 'r')
xlabel('t(Seconds)','fontsize',10)
  ylabel('Amplitude','fontsize',10)
  axis([-38 38 -0.4 0.4])
  text(-45,.5,'(g)')
  box on
  grid on

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
low pass filter guj 12 Nov, 2009 01:54:07
filtering guj 12 Nov, 2009 01:54:07
rssFeed for this Thread

Contact us at files@mathworks.com