Help with matlab ( contructing Low pass filter and apply it to square wave.

Thread Starter

ynaji

Joined Jan 28, 2007
10
I am stuck can you please Help me.

The Assignement is construct a Low pass filter RC using magnitude transfer function calculated H=1/squareroot(1+(f/fo)^2). apply the filter to the square wave. the Frequency is 10 KHz. Examine the spectral output. I tried and I gave up . Any ideas What I am doing wrong ?


n = 0:255;
t = n/256;
f1 = 10000;
omega = 2*pi*f1;
x = cos(omega*t);
subplot(3,3,1);
plot(t,x)
xlabel('time (s)')
ylabel('amplitude')
title('Sine waive x(t)')
X=fft(x)/256;
subplot(3,3,2);
plot(0:63, abs(X(1:64)))
xlabel('frequency (HZ)')
ylabel('amplitud')
title('Spectrum X')
n = 0:255;
t = n/256;
x = [ ones(1,64),-ones(1,64), ones(1,64), -ones(1,64)];
subplot(3,3,3);
plot(t,x);
X=fft(x)/256;
f=0:255;
fo=10000;
H= (1/(sqrt(1+(f/fo)^2)));
H(1:3)= ones(1,3);
H(254:256)= ones(1,3);
Y= H.*X;
subplot(3,3,4);
plot(t,Y)
 

Dave

Joined Nov 17, 2003
6,969
You cannot use the mpower function (implicitly) on a matrix in the way you are doing. You must saddle it with a for-loop:

Rich (BB code):
n = 0:255;
t = n/256;
f1 = 10000;
omega = 2*pi*f1;
x = cos(omega*t);
subplot(3,3,1);
plot(t,x)
xlabel('time (s)')
ylabel('amplitude')
title('Sine waive x(t)')
X=fft(x)/256;
subplot(3,3,2);
plot(0:63, abs(X(1:64)))
xlabel('frequency (HZ)')
ylabel('amplitud')
title('Spectrum X')
n = 0:255;
t = n/256;
x = [ ones(1,64),-ones(1,64), ones(1,64), -ones(1,64)];
subplot(3,3,3);
plot(t,x);
X=fft(x)/256;
f=0:255;
fo=10000;
for i=1:(size(f,2))
    H(i) = (1/(sqrt(1+(f(i)/fo)^2)));
end
H(1:3)= ones(1,3);
H(254:256)= ones(1,3);
Y= H.*X;
subplot(3,3,4);
plot(t,Y)
Dave
 

Thread Starter

ynaji

Joined Jan 28, 2007
10
Thank you very much dave for your response. but I have another question regarding matlab code. When I created Square wave, I have to put 10 Khz frequency not 2 cycle.
 
Top