Time scaling with IFFT

조회 수: 7 (최근 30일)
Ali
Ali 2012년 2월 24일
댓글: Walter Roberson 2021년 10월 25일
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)');

채택된 답변

Wayne King
Wayne King 2012년 2월 24일
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.

추가 답변 (2개)

Ali
Ali 2012년 2월 24일
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
Ali
Ali 2012년 2월 25일
Nevermind, I got it working now. Thanks for the help, it actually made all the difference.

댓글을 달려면 로그인하십시오.


Sk Group
Sk Group 2021년 10월 25일
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 10월 25일
The code at that article only passes a single parameter to the graphics function, and so is unable to do time scaling.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Frequency Transformations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by