% my_script.m     Example of sound effect.
% by Neil Cotter
% script file example
% Reverse the frequencies in snippet of handel so low freq becomes high.
%
% Inputs: none
% Outputs: s = sound waveform of first sec of handel
%              with frequencies inverted

load handel   % puts handel snippet in y
y = y(1:8000);   % extract 1 sec of y
spec = fft(y);   % 8000 pt fft = frequency content of y

% Specify that the plot is to be put in Figure 1 window.
figure(1)

% Plot the spectrum of y.  The fft is complex, so we take the absolute value.
plot(abs(spec))

% The fft is symmetrical around the midpoint frequency.  So reverse each half.
spec(1:4000)=spec(4000:-1:1);

% Now reverse the frequencies in the 2nd half.
spec(4001:8000)=spec(8000:-1:4001);

% Specify that the reversed spectrum plot is to be put in Figure 2 window.
figure(2)
plot(abs(spec))

% Turn the modified spectrum back into a sound using the inverse fft.  The
%  result might be complex, so take the absolute value.
s = abs(ifft(spec))

% Play the modified sound.
sound(y)
