Explore BrainMass

# Matlab Program Revisions

Not what you're looking for? Search our solutions OR ask your own Custom question.

This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

Here is the program I tweaked, but I seriously need you to comment every line including and below this code piece (index=round(x*fs); ) what each line does and how it works. The more explanation the better. I do not understand how the index works, everything. I need step by step how all the numbers flow so to say from variable to variable like a flow chart. Finally, the code below for the five plots was great, but can you make a for loop or something to plot nth plots. Notice the input used to be 6 for 6 clicks of the mouse, now it is () to signify infinite clicks of the mouse, so need a for loop instead of plotting one at a time for t1,t2.....

CODE BELOW:

%Gregory Leist/Dr. Saed/Project 5 takes a wav file Dr. Saed created for

%tones, read file and plot the file. Use ginput to take 6 data points.

%Plot waveforms.

clear,clc,close all;

%get project5.wav file from moodle, right click, save and drag to m file

%directory used in matlab so matlab can find it.

filename=input('Enter wavfilname: "project5.wav" > ','s');

%enter at prompt>> project5.wav

%-------------------------------------------------------------------------

[wav,fs]=wavread(filename);

t=(0:length(wav)-1)/fs;

plot(t,wav);

[x,y]=ginput(); % 6 means 6 mouse clicks only to work on plot

%Be sure to click on 6 different places on plot

%cause if plot on same waveform("square wave")

%twice the final plots are messed up.

%-------------------------------------------------------------------------

%then on command window see x = a number

% a number, etc.

% y = a number

% a number etc.

%but actually do not cause added a ";" to code to

%supress all the numbers being placed on the

%command window.

%only want x axis, so ignore y axis and to do so..

%--------------------------------------------------------------------------

index=round(x*fs);

figure; %so plots will not override

t1=t(index(1):index(2)-1);

sig1=wav(index(1):index(2)-1); %wav is variable for x plot values

N=length(t1); %take clicked portion length

fft1=abs(fftshift(fft(sig1)))/N; %get spectrum

freq1=[-N/2:N/2-1]'*fs/N;

t2=t(index(2):index(3)-1);

sig2=wav(index(2):index(3)-1);

subplot(5,2,2);plot(sig2);

N=length(t2);

fft2=abs(fftshift(fft(sig2)))/N;

freq2=[-N/2:N/2-1]'*fs/N;

t3=t(index(3):index(4)-1);

sig3=wav(index(3):index(4)-1);

subplot(5,2,3);

plot(sig3);

N=length(t3);

fft3=abs(fftshift(fft(sig3)))/N;

freq3=[-N/2:N/2-1]'*fs/N;

t4=t(index(4):index(5)-1);

sig4=wav(index(4):index(5)-1);

subplot(5,2,4);

plot(sig4);

N=length(t4);

fft4=abs(fftshift(fft(sig4)))/N;

freq4=[-N/2:N/2-1]'*fs/N;

t5=t(index(5):index(6));

sig5=wav(index(5):index(6));

subplot(5,2,5);

plot(sig5);

N=length(t5);

fft5=abs(fftshift(fft(sig5)))/N;

freq5=[-N/2:N/2-1]'*fs/N;

subplot(5,2,1);plot(t1,sig1);

subplot(5,2,2);plot(freq1,fft1);

subplot(5,2,3);plot(t2,sig2);

subplot(5,2,4);plot(freq2,fft2);

subplot(5,2,5);plot(t3,sig3);

subplot(5,2,6);plot(freq3,fft3);

subplot(5,2,7);plot(t4,sig4);

subplot(5,2,8);plot(freq4,fft4);

subplot(5,2,9);plot(t5,sig5);

subplot(5,2,10);plot(freq5,fft5);

© BrainMass Inc. brainmass.com March 4, 2021, 7:24 pm ad1c9bdddf
https://brainmass.com/computer-science/matlab/matlab-program-revisions-99374

#### Solution Preview

%Gregory Leist/Dr. Saed/Project 5 takes a wav file Dr. Saed created for

%tones, read file and plot the file. Use ginput to take 6 data points.

%Plot waveforms.

clear,clc,close all;

%get project5.wav file from moodle, right click, save and drag to m file

%directory used in matlab so matlab can find it.

filename=input('Enter wavfilname: "project5.wav" > ','s');

%enter at prompt>> project5.wav

%-------------------------------------------------------------------------

[wav,fs]=wavread(filename);

t=(0:length(wav)-1)/fs;

plot(t,wav);

[x,y]=ginput(); % 6 means 6 mouse clicks only to work on plot

%Be sure to click on 6 different places on plot

%cause if plot on same waveform("square wave")

%twice the final plots are messed up.

%-------------------------------------------------------------------------

%then on command window see x = a number

% a number, etc.

% y = a number

% a number etc.

%but actually do not cause added a ";" to code to

%supress all the numbers being placed on the

%command window.

%only want x axis, so ignore y axis and to do so..

%--------------------------------------------------------------------------

index=round(x*fs);

figure; %creates a new figure window

t1=t(index(1):index(2)-1); % elements from t[index(1)] to t[index(2)-1] are saved in array ...

#### Solution Summary

The expert examines MATLAB program revisions. A plot of the waveforms are determined.

\$2.49