Time scaling with IFFT

9 views (last 30 days)
Ali
Ali on 24 Feb 2012
Commented: Walter Roberson on 25 Oct 2021
Hello all,
I'm working on an assignment that involves computing the output generated by a filter for arbritrary inputs. To demonstrate this, I have implemented a 4th-order low-pass butterworth filter, H(F), and apply a period square wave to it, x(t). I figured the simplest way of going about this is to take the fft of the square wave and then just multiply the individual frequency components by H(F). I am fairly confident that I have done this correctly since the plots generated for the output make perfect sense to me.
I then take the ifft of the product to see the output in time domain, however the results do not make sense to me. How can i properly scale the output in time? I know that there are several similar questions online however I am unable to find a solution. Any help would be greatly appreciated.
P.s. I also noticed that the output seems to have a DC bias but can't figure out why. Any ideas?
clc; close all; clear all;
Fs = 20000; %sampling frequency
Av = 2.57472; %amplifier gain
fo = 2650; %filter cut-off frequency
%vector for positive frequencies
for f=1:Fs/2
H_pos(f) = Av./(((-(f./fo).^2)+(0.7658j.*(f./fo))+1).*((-(f./fo).^2)+(1.848j.*(f./fo))+1));
end
H_neg = flipdim(H_pos,2); %vector for negative frequencies
H_f = horzcat(H_pos, H_neg); %combine positive and negative frequencies
H_mag = abs(H_f);
%now setup input signal x(t) and get X(F)
fr = 2000; %freq of square wave
t = 0:1/Fs:1; %one second time interval
x = square(t); %sqaure wave
X_f = fft(x);
X_f(1) = 0; %remove DC component
X_mag = abs(X_f);
%Y(F) is product of X(F) and H(F)
for i=1:length(X_f)
Y(i) = X_f(i)*H_f(i);
end
y = ifft(Y); %output in time-domain
plot(H_mag);
title('|H(F)|');
figure;
plot(X_mag);
title('|X(F)|');
figure;
plot(abs(Y));
title('|Y(F)|');
figure;
subplot(2,1,1);
plot(t,x);
subplot(2,1,2);
plot(abs(y));
title('y(t)');

Accepted Answer

Wayne King
Wayne King on 24 Feb 2012
Hi, I see a number of issues here. One issue you have right away is that your H_f is not conjugate-symmetric and therefore is the not the Fourier transform of a real-valued impulse response.
Here is your code:
for f=1:Fs/2
H_pos(f) = Av./(((-(f./fo).^2)+(0.7658j.*(f./fo))+1).*((-(f./fo).^2)+(1.848j.*(f./fo))+1));
end
H_neg = flipdim(H_pos,2); %vector for negative frequencies
H_f = horzcat(H_pos, H_neg); %combine positive and negative frequencies
You cannot just copy the Fourier transform values at the "positive" frequencies into the negative frequency bins.

More Answers (2)

Ali
Ali on 24 Feb 2012
thanks for the input Wayne. I have modified the code so now the negative frequencies are conjugates of the positive frequencies.
I was taught previously that for FFT, you need to setup your vector such that the positive frequencies are from 0 to Fs/2 and then the nagative frequencies follow from Fs/2 to Fs. So that is how I have setup the filter vector. Please let me know if this correct.
You also mentioned that there are other issues with this code, could you please elaborate on that. Thanks in advance.
  1 Comment
Ali
Ali on 25 Feb 2012
Nevermind, I got it working now. Thanks for the help, it actually made all the difference.

Sign in to comment.


Sk Group
Sk Group on 25 Oct 2021
  1 Comment
Walter Roberson
Walter Roberson on 25 Oct 2021
The code at that article only passes a single parameter to the graphics function, and so is unable to do time scaling.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!