Time scaling with IFFT
조회 수: 7 (최근 30일)
이전 댓글 표시
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)');
댓글 수: 0
채택된 답변
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.
댓글 수: 0
추가 답변 (2개)
Sk Group
2021년 10월 25일
For detailed post with complete code visit: https://www.swebllc.com/time-scaling-in-matlab-code-output/
댓글 수: 1
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 Center 및 File Exchange에서 Frequency Transformations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!