Help Plotting Phase and Magnitude

14 views (last 30 days)
Mitch
Mitch on 1 Jul 2013
Hello Everyone,
I just began using MATLAB for my class and have pretty much been on my own for most of this semester. I've seen the help people have gotten from members here and thought I'd give it a shot...
Cutting to the chase, I'm working on a program that is supposed to ask the end-user to type the name of a .wav file to be read (which we are given, 'Chirp.wav'). Once the .wav file is inputted and read it is then supposed to play the sound and then output plots/graphs of the magnitude/phase spectra. Once these are plotted the values of both spectras must then be saved into ASCII files. This is all done using a sampling frequency of 8192 Hz.
Later, we're supposed to create a synthesizer using the values from the magnitude and spectra plots to regenerate the original signal from the .wav file.
So far I have gotten as far as completing the Magnitude phase plot of my signal. I'm having a very difficult time trying to create the Phase plot of my signal. I'm afraid I do not fully understand how the frequency vector works for my program. This is the part I need the most help on. I have my code posted below.
%%%%%%%%%%%%%%%%% SIGNAL ANALYZER %%%%%%%%%%%%%%%%%
Fs = 8192; % Sampling frequency
file1 = input('Please type the name of the .wav file: ', 's'); % Asking the user for input file
[y, Fs, nbits] = wavread(file1); % Reading file
t = linspace(0, numel(y)/Fs, numel(y)); % Time Vector
sound(y,Fs,nbits); % Plays .wav file
subplot(2,3,1);
plot(t,y, 'black'); % Plots input signal
xlabel('Time');
ylabel('Amplitude');
title('Input Signal')
y_fft = fft(y); %Fourier Transform of Input Signal
y_fftshift = fftshift(y_fft); %FFT Shift of input signal
%%%Graph 3 (FFT - Magnitude) %%%
freq1 = linspace(1,Fs,length(y)); %%%frequency vector
subplot(2,3,3);
stem(freq1, abs(y_fft), 'r'); %%%Stem Plot
xlabel('Freq');
ylabel('Amplitude');
title('Fourier Transform (Magnitude)');
%%%Graph 4 (FFT Shift - Magnitude) %%%
subplot(2,3,4);
freq2 = linspace(-Fs/2,Fs/2,length(y)); %%%frequency vector
stem(freq2, abs(y_fftshift),'y'); %%%Stem Plot
xlabel('Freq');
ylabel('Amplitude');
title('Fourier Transform Shift (Magnitude)');
%%%Graph 5 (Phase Plot) %%%
subplot(2,3,5);
fp = linspace(-Fs/2,Fs/2,length(y(1:ptime))); %%%frequency vector
phase = angle(y(1:ptime));
plot(fp,phase);
xlabel('Freq');
ylabel('Phase (Radians)');
title('Phase Plot');
P.S.: I'm not expecting anyone to do my work but I'd like to ask for some guidance or help. I'm not exactly sure if I'm doing this right so any sort of feedback is much appreciated.
Regards, Mitch

Answers (0)

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!