Time scaling with IFFT
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ali
am 24 Feb. 2012
Kommentiert: Walter Roberson
am 25 Okt. 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)');
0 Kommentare
Akzeptierte Antwort
Wayne King
am 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.
0 Kommentare
Weitere Antworten (2)
Sk Group
am 25 Okt. 2021
For detailed post with complete code visit: https://www.swebllc.com/time-scaling-in-matlab-code-output/1 Kommentar
Walter Roberson
am 25 Okt. 2021
The code at that article only passes a single parameter to the graphics function, and so is unable to do time scaling.
Siehe auch
Kategorien
Mehr zu Transforms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!