Thread Subject: Filter a sinusoidal signal

Subject: Filter a sinusoidal signal

From: Simon Luk

Date: 4 Jun, 2009 12:21:01

Message: 1 of 3

Hi All..

I'm currently trying to filter a FM signal... the code is below

clear all
close all
echo on
t0=.2; % signal duration
ts=0.001; % sampling interval
fc=250; % carrier frequency
fs=1/ts; % sampling frequency
t=[-t0/2:ts:t0/2]; % time vector
kf=100; % deviation constant
m=cos(2*pi*10*t); % the message signal
int_m(1)=0;
for i=1:length(t)-1 % integral of m
  int_m(i+1)=int_m(i)+m(i)*ts;
  echo off ;
end
echo on ;
u=cos(2*pi*fc*t+2*pi*kf*int_m); % modulated signal

%now lets filter the signal
[z,p] = butter(1,2*50/fs,'low');
filter_out = filter(50,[1 50],u); %this damn filter doesn't work!

subplot(2,1,1);
plot(t,u);
hold on;
plot(t,m,'r');

subplot(2,1,2);
plot(t,filter_out);
hold on;
plot(t,m,'r');


The plots are all there and stuff, all you need to do is to run the above code.
As you can see, the filter output gives me like a weird response, does anyone know why and what Im doing wrong?

I think im somehow implementing the butter function wrong..


Thanks in advance.

Regards,
Simon

Subject: Filter a sinusoidal signal

From: Wayne King

Date: 4 Jun, 2009 12:48:01

Message: 2 of 3

Hi Simon, without going through your code line by line, one thing that stands out is
the following portion:

%now lets filter the signal
[z,p] = butter(1,2*50/fs,'low');
filter_out = filter(50,[1 50],u);

the outputs of your call to butter, (in your code, z and p), are the numerator and denominator coefficients of the filter respectively. You should use these coefficients in your call to filter. For example:

[z,p] = butter(1,2*50/fs,'low');
filter_out = filter(z,p,u);

 Also, you don't need the a0 term of one, notice that p(1)=1. The call to butter() has already included the zero-th order term. You can look at the response of your filter with

fvtool(z,p)

Hope that helps,
wayne


"Simon Luk" <simon.luk@student.uts.edu.au.REMOVETHIS> wrote in message <h08e7d$rls$1@fred.mathworks.com>...
> Hi All..
>
> I'm currently trying to filter a FM signal... the code is below
>
> clear all
> close all
> echo on
> t0=.2; % signal duration
> ts=0.001; % sampling interval
> fc=250; % carrier frequency
> fs=1/ts; % sampling frequency
> t=[-t0/2:ts:t0/2]; % time vector
> kf=100; % deviation constant
> m=cos(2*pi*10*t); % the message signal
> int_m(1)=0;
> for i=1:length(t)-1 % integral of m
> int_m(i+1)=int_m(i)+m(i)*ts;
> echo off ;
> end
> echo on ;
> u=cos(2*pi*fc*t+2*pi*kf*int_m); % modulated signal
>
> %now lets filter the signal
> [z,p] = butter(1,2*50/fs,'low');
> filter_out = filter(50,[1 50],u); %this damn filter doesn't work!
>
> subplot(2,1,1);
> plot(t,u);
> hold on;
> plot(t,m,'r');
>
> subplot(2,1,2);
> plot(t,filter_out);
> hold on;
> plot(t,m,'r');
>
>
> The plots are all there and stuff, all you need to do is to run the above code.
> As you can see, the filter output gives me like a weird response, does anyone know why and what Im doing wrong?
>
> I think im somehow implementing the butter function wrong..
>
>
> Thanks in advance.
>
> Regards,
> Simon

Subject: Filter a sinusoidal signal

From: Simon Luk

Date: 5 Jun, 2009 04:13:01

Message: 3 of 3

Hi Wayne,

Thanks for your help, I've made the changes you said. I think it's working..

[z,p] = butter(1,2*50/fs,'low');
filter_out = filter(z,p,u);

Is this sending the signal 'u' through a first order low pass filter with a cut off at 50Hz?

When I used fvtool(z,p), I have a normalized requency which I don't know how to interpret.

Can you/someone please confirm?


Thanks again.


Regards,
Simon

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
butter Simon Luk 4 Jun, 2009 08:24:03
filter Simon Luk 4 Jun, 2009 08:24:03
fm Simon Luk 4 Jun, 2009 08:24:03
rssFeed for this Thread

Contact us at files@mathworks.com