1
$\begingroup$

What does the output signal look like when you insert $2000 Hz$ square pulses to chebyshev filter with parameters: (Matlab syntax). I tried to do it like this but I don't understand where it goes wrong.

%Making the square pulses

Fs = 1000000;
t = [0:1/Fs:50e-4]; 
f = 2000;

%square pulse with 50% duty cycle

xt = 1*square(2*pi*f*t, 50);

%Making the filter

Wp = [1000 3000]; 
Ws = [100 3900]; 
[n,Wn] = cheb1ord(Wp,Ws,3,20,'s');
[b,a] = cheby1(n,3,Wn,'s');



%Filtering with the coefficient 

xt_filtered = filter(b,a,xt);

%Plotting the filtered signal

plot(t,xt_filtered);

But I get something like this which doesn't make sense..? enter image description here

$\endgroup$
  • $\begingroup$ I think this is a duplicate of dsp.stackexchange.com/a/8420/29 Basically you want to use oversampling to make the digital filter approximate the analog filter more closely, and you want to generate a bandlimited square wave for your input signal (with highest harmonic significantly below the sampling frequency) $\endgroup$ – endolith Nov 20 '14 at 14:39
  • $\begingroup$ Your plot is wrong because you're generating analog filter coefficients and then using them in a digital filter. you need to remove 's'. You can generate the bandlimited square using additive synthesis: gist.github.com/endolith/407991 $\endgroup$ – endolith Nov 20 '14 at 21:21
  • $\begingroup$ Thank's for the link! I'll try it when I have more time to get to know it for sure. My matlab script gets error if I lose the 's' from cheb1ord and cheby1 functions. Wp = [1000 3000]; Ws = [100 3900]; [n,Wn] = cheb1ord(Wp,Ws,3,20,'s'); [b,a] = cheby1(n,3,Wn); What would be the correct syntax then? $\endgroup$ – ELEC Nov 20 '14 at 22:19
  • $\begingroup$ @ELEC - What error do you get if you remove 's' ? $\endgroup$ – JRE Nov 21 '14 at 10:58
  • $\begingroup$ Your square wave generator doesn't seem to generate a square wave. When I do "Plot(t,xt)" I get a straight line at level 1.0 (DC signal that stays put at 1.0) This may be a difference between Gnu Octave and Matlab - I will see what Octave needs to generate a square wave. $\endgroup$ – JRE Nov 21 '14 at 11:01
0
$\begingroup$

Allowing for differences between Matlab and Octave ( I only have Gnu Octave to play with,) and correcting the errors noted in the comments, I get the following:squarewave Needed fixes:

  1. Values for Wp and Ws divided by half of sampling rate - the cheb1ord function requires frequencies be given relative to the Nyquist frequency.
  2. Removed 's' (not allowed for Octave anyway.)

To make the code work for Octave, I had to make the following changes:

  1. Remove duty cycle value from square
  2. Remove 's' from cheb1ord and cheby1

Code for Octave (should run under Matlab as well:)

%Making the square pulses
Fs = 1000000;
nyq=Fs/2;
t = 0:1/Fs:50e-4; 
f = 2000;

%square pulse with 50% duty cycle
xt = square(2*pi*f*t);

%Making the filter
Wp = [1000/nyq 3000/nyq]; 
Ws = [100/nyq 3900/nyq];
[n,Wn] = cheb1ord(Wp,Ws,3,20);
[b,a] = cheby1(n,3,Wn,'s');

%Filtering with the coefficients 
xt_filtered = filter(b,a,xt);

%Plotting the filtered signal
subplot (211);
plot(t,xt);
subplot(212);
plot(t,xt_filtered);    
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.