|
From: | Doug Stewart |
Subject: | Re: rebuild signal from frequency domain to time domain tia sal22 |
Date: | Wed, 9 Mar 2011 07:20:18 -0500 |
I changed the lines following your example but I get an error nonconformant argumentsdue to the fact that ya and yb_ifft are not the same size arrays did I miss somethingthe code I changed is below.thanks for the quick response :-)%signal from frequency domain to time domain
clear all
%create time domain
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sample time
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
ya = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
%create frequency domain
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
yb = fft(ya,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
%frequency back to time domain
yb_ifft=ifft(yb);
freq_to_time=ya-yb_ifft; %array size isn't the same anymore
subplot(2,2,1),plot(Fs*t(1:50),ya(1:50))
title('Signal ')
xlabel('time (milliseconds)')
% Plot amplitude spectrum.
subplot(2,2,2),plot(f,2*abs(yb(1:NFFT/2+1)))
title('Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
subplot(2,2,3),plot(Fs*t(1:50),freq_to_time(1:50))
title('rebuild Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')--On Wed, Mar 9, 2011 at 1:54 AM, Andy Buckle <address@hidden> wrote:
>y=rand(1,4)On Wed, Mar 9, 2011 at 11:45 AM, Rick T <address@hidden> wrote:
> rebuild signal from frequency domain to time domain tia sal22
> Greetings all
> I would like to rebuild a signal from the frequency domain
> can this be done using fft? If so does anyone have some
> example code?
> Here's what I have so far. I create/import a signal and plot
> using the time domain. Then I use fft to convert to
> the frequency domain and plot. What I want to do now is
> be able to convert from the frequency domain data back to the time
> domain. Then I'll be able to export the file as a wave file
> PS: I won't have an equation to work with because I'll be importing
> an audio file, and I'll be making changes when the signal is
> in the frequency domain.
> But at the moment I'm just trying to convert from the
> frequency domain back to the time domain. So the third plot
> when created would look just like the first plot in the time domain
> in the example below
>
> %time domain
> %create time domain
> Fs = 1000; % Sampling frequency
> T = 1/Fs; % Sample time
> L = 1000; % Length of signal
> t = (0:L-1)*T; % Time vector
> y = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
> %frequency domain
> NFFT = 2^nextpow2(L); % Next power of 2 from length of y
> Y = fft(y,NFFT)/L;
> f = Fs/2*linspace(0,1,NFFT/2+1);
> subplot(2,1,1),plot(Fs*t(1:50),y(1:50))
> title('Signal ')
> xlabel('time (milliseconds)')
> % Plot amplitude spectrum.
> subplot(2,1,2),plot(f,2*abs(Y(1:NFFT/2+1)))
> title('Amplitude Spectrum of y(t)')
> xlabel('Frequency (Hz)')
> ylabel('|Y(f)|')
> tia sal22
> --
y =
0.683785 0.772539 0.065463 0.410841
>f=fft(y)
f =
Columns 1 through 3:
1.93263 + 0.00000i 0.61832 - 0.36170i -0.43413 + 0.00000i
Column 4:
0.61832 + 0.36170i
>y2=ifft(f)
y2 =
0.683785 0.772539 0.065463 0.410841
>y-y2
ans =
0.0000e+000 0.0000e+000 4.1633e-017 5.5511e-017
--
/* andy buckle */
-
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
[Prev in Thread] | Current Thread | [Next in Thread] |