Code covered by the BSD License  

Highlights from
MatLab Solutions: "Introduction to Digital Signal Processing: A Computer Laboratory Textbook".

image thumbnail

MatLab Solutions: "Introduction to Digital Signal Processing: A Computer Laboratory Textbook".

by

 

29 Oct 2012 (Updated )

These files are the MatLab solutions of exercises contained in the above DSP lab textbook.

my_CTFT(x,dt,freq_type)
function [freq X] = my_CTFT(x,dt,freq_type)
% Continuous Time Fourier Transform Approximation.
%
% Inputs:
% x  : the "analog" signal
% dt : the sampling interval in seconds for the simulated analog signal xa
% freq_type: a string containing the selected type of frequency. i.e. 'Hz' or 'rad/sec'.
% 
% Outputs:
% X : vector containing the "continuous FT" of "analog" signal " x(t).
% freq: vector containing the "analog" frequency values where the CTFT was computed.
L = length(x);
Nfft = 2^(nextpow2(L)+2); % Choose the (nearest Power + 2) of 2
X = fftshift(fft(x,2*Nfft+1));
range = -Nfft:Nfft; 

% sampling rate
ff = range/(2*Nfft+1)/dt; % frequencies in Hz
Omega = 2*pi*ff;  % frequencies in rad/sec

if strcmp(freq_type,'Hz')
    freq = ff; 
    % plot(ff,abs(X),'r')
    % xlabel('Analog Frequency f (Hz)');
 elseif strcmp(freq_type,'rad/sec') 
    freq = Omega;
    % plot(Omega,abs(X),'r')
    % xlabel('Analog Frequency \Omega (rad/sec)');
end

 % title('Continuous-Time Fourier Transform (CTFT) Magnitude');
 % hold on;
 % grid
 % axis tight;

Contact us