|
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
|