How do I correctly implement IFFT in signal generation?

7 views (last 30 days)
I'm trying to create a signal based on the frequency spectrum of a highly sampled noise signal muliplied by a gaussian window in the frequency domain centered at zero hz.
I'm multiplying the two together to create a combined frequency spectrum. Then I'm attempting to IFFT the combined spectrum to create a new signal.
Help would be greatly appreciated.
%% Highly Sampled Noise
fsamp = 32e3; %Sampling frequency
Ts = 1/fsamp; %Period of sampling
L = 3.33; % Length of signal
t1 = 0:Ts:L-Ts;%vector 0:3.33 sampled at a rate of 32khz
Noise = 10*randn(1,length(t1));
plot(t1,Noise);
title('32kHz Noise Randn')
xlabel('Time seconds')
ylabel('Amplitude')
figure
%% Frequency Spectrum of Highly Sampled Noise
N = length(t1);
k = 0:N-1;
T = N/fsamp;
freq = k/T;
NFFT = 2^(nextpow2(N)+1);
N1f = abs(fft(Noise,NFFT)/N);
cutOff = ceil(N/2);
N1f = N1f(1:cutOff);
freq = freq(1:cutOff);
% freq = fsamp*linspace(0,1-(1/NFFT),NFFT); % Frequency Vector
% mag_dB = 10*log10(N1f.^2); % Translating to Decibels
plot(freq,N1f)
title('Frequency Spectrum of the Noise');
xlabel('Frequency [Hz]');
ylabel('Normalized Magnitude |Noise(f)|');
grid on
figure
%% Gaussian Window using Custom Gauss Function Found Online
% CUSTOMGAUSS Generate a custom 2D gaussian
%
% gauss = customgauss(gsize, sigmax, sigmay, theta, offset, factor, center)
%
% gsize Size of the output 'gauss', should be a 1x2 vector
% sigmax Std. dev. in the X direction
% sigmay Std. dev. in the Y direction
% theta Rotation in degrees
% offset Minimum value in output
% factor Related to maximum value of output, should be
% different from zero
% center The center position of the gaussian, should be a
% 1x2 vector
% function ret = customgauss(gsize, sigmax, sigmay, theta, offset, factor, center)
% ret = zeros(gsize);
% rbegin = -round(gsize(1) / 2);
% cbegin = -round(gsize(2) / 2);
% for r=1:gsize(1)
% for c=1:gsize(2)
% ret(r,c) = rotgauss(rbegin+r,cbegin+c, theta, sigmax, sigmay, offset, factor, center);
% end
% end
% end
% function val = rotgauss(x, y, theta, sigmax, sigmay, offset, factor, center)
% xc = center(1);
% yc = center(2);
% theta = (theta/180)*pi;
% xm = (x-xc)*cos(theta) - (y-yc)*sin(theta);
% ym = (x-xc)*sin(theta) + (y-yc)*cos(theta);
% u = (xm/sigmax)^2 + (ym/sigmay)^2;
% val = offset + factor*exp(-u/2);
% end
%Setting variables for CustomGauss
L2 = length(freq);
stdX = length(1:Ts:1.1);
stdY = 1;
theta = 90;
Min_Val = 1;
Max_Val = 100;
Gauss_Win = customgauss([1,L2], stdX, stdY, theta, Min_Val, Max_Val, [0,-L2/2]);
plot(freq(1:L2),Gauss_Win(1:L2))
xlabel('Frequency [Hz]')
ylabel('Magnitude |W(f)| [dB]')
title('Gaussian Window in Frequency Domain')
figure
%% Tissue Spectrum: Gaussian Window and Noise Frequency Spectrum Combination
Tissue_Spec = N1f.*Gauss_Win;
stem(freq,Tissue_Spec)
title('Window & Noise Combined Frequency')
xlabel('Frequency [Hz]')
ylabel('Magnitude |T(f)|')
figure
%% IFFT and Highly Sampled Tissue Signal Creation
Tissue_Signal = ifft(Tissue_Spec,(NFFT))*L2;
LN_TS = length(Tissue_Signal);
t2 = (0:(1-Ts)/(LN_TS-1):1-Ts);
plot(t2,real(Tissue_Signal))
title('Highly Sampled Tissue Signal')
xlabel('Time Seconds')
ylabel('Amplitude')
figure

Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!