MATLAB: Hello everyone, I am using rectpuls function to generate a bandpass filter. I got a rectangle with a width at the top different from that at the bottom. anyone can help please!!

frequencyrectpuls

below is the used code:
close All
clear All
% Part 1
Ts=0.001;Fs=1/Ts;
frequency_axis=-Fs/2:Fs/2;
F1firsthalf=rectpuls(frequency_axis-10,5);
figure,plot(frequency_axis,F1firsthalf),grid
axis([-100 100 0 2]);
title('Ideal bandpass filters')
xlabel('Angular Frequency(rd/s)')
ylabel('Amplitude')

Best Answer

>> find(F1firsthalf,1)
ans =
509
>> F1firsthalf(505:515)
ans =
0 0 0 0 1 1 1 1 1 0 0
>>
It's just a fignewton of the amplified x-axis scale -- the pulse is discrete but you plotted a continuous line between points -- can't have a 0 and a 1 at the same element in the pulse train.
There's a special plotting function to fix the visual for just such purpose, however...try
stairs(frequency_axis,F1firsthalf),grid
axis([-100 100 0 2]);
instead.