Explore BrainMass
Share

Matlab Program Example Problem

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

Problem Statement:

1) Prompt a user to enter a .wav filename where the DTMF tones are stored. Load the recorded tones. Use the .wav file provided called project5.wav. (NOTE: this file is on my computer and is not presented.), but the file contains simulated tones for the numbers 24680 which where generated using a previous program which is not important.
2) Plot the signal representing the tones versus time.
3) Use the command ginput to determine the number of tones and set break points to separate the individual tones.
4) Use Matlab's fft function to calculate the magnitude spectrum for each digit.
5) Plot the signals for each digit and their magnitude spectrum. Arrange the graphs so that each page (figure window) contains six graphs labeled. A signal and its magnitude must be displayed next to each other(1st pane has a signal and 2nd pane has its spectrum)

THE code I have that may help:

clear,clc,close all;
filename=input('Enter wavfilname, project5.wav','S');
%>>project5.wav
(y,fs)=wavread(filename)
fs=4000; %sampling freq
dt=1/fs; %time step
fo=1000; % signal frequency
T=1/fo;
t=[0:dt:200*T-dt]
x=sin2*pi*10*t
plot(t,x)
(x,y)=ginput(6) % 6 means 6 mouse clicks only to work on plot
%then on command window see x= a number
a number, etc.
y= a number
a number etc.
% only want x axis, so ignore y axis and to do so...
index1=round(1)/dt
f=g(1:index1);
f1=t(1:index)
plot(t,f)

OK, other code have to use the fft function to find the amplitude spectrum of a sinusoid. Here it is:
clear, clc, close all;
fs=4000;
dt=1/fs;
fo=1000;
T=1/fo;
t=[0:dt:200*T-dt];
x=sin(2*pi*fo*t);
N=length(x);
XF=fft(x)/N;
XFM=abs(fftshift(XF));
freq=[-N/2:N/2-1]*fs/N;
plot(freq,XFM)
figure
stem(freq,XFM) % to get rid of extra little side spectrum's due to the way Matlab uses math to calculate a spectrum...

© BrainMass Inc. brainmass.com October 24, 2018, 8:30 pm ad1c9bdddf
https://brainmass.com/computer-science/matlab/matlab-program-example-problem-98766

Solution Preview

Please see the attachment for solution.

Also attached is the wav file of the number 12345 that is used in ...

Solution Summary

This solution provides assistance with the Matlab program problem.

$2.19
See Also This Related BrainMass Solution

MATLAB Code Debugging

Without changing the codes, the errors boxed is what I am getting when I run these codes. I am not sure if I am supposed to create files first. I would like codes that are basic and running.

function out=bisect_1(fname, a, b, eps)
% bisection algorithm
% fname must be a function handle (if you want to use a string instead,
% use eval)
% sign(fa)*sign(fb) must be negative where fa=feval(fname,a) and
% fb=feval(fname,b)
%
% Example:
% fname=@(x)(exp(-cos(x))-1);
% root1=bisect_1(fname, 1, 2, 1e-3);
% root1
%
% To find the second root, use a=4 and b=5
% To find the third root, use a=7 and b=8
%
% Now to compare the results, use fzero() function
% first root-->fzero(fname, 1)
% second root-->fzero(fname, 5)
% third root-->fzero(fname, 8)
%
% You could add more codes to check the inputs to the function
% and act accordingly.
%
out='root not found';
if sign(feval(fname,a))*sign(feval(fname,b)) > 0
disp('function doesn''t cross zero betwenn the specified interval!!');
return ;
end
N=100; %to avoid infinite loop
found=false;
iter=0;
while(iter<N)
iter=iter+1;
c=(a+b)/2;
fa=feval(fname,a);
fb=feval(fname,b);
fc=feval(fname,c);
if (fc==0 || (b-a)/2<eps)
out=c;
found=true;
break;
else
if sign(fc)==sign(fa)
a=c;
else
b=c;
end
end
end
if found==false
disp('Root not found!')
end

The error Iam getting for the above code
??? Input argument "fname" is undefined.

Error in ==> bisect_1 at 25
if sign(feval(fname,a))*sign(feval(fname,b)) > 0

function out=insertionSort(inArray)
% insertion sort algorithm
% inArray must be a vector
% out is the result of insertion sort
% Example:
% a=round(10*rand(1,10)+1);
% a_sorted=insertionSort(a);
% a_sorted
%

for i=1:length(inArray)
temp=inArray(i);
j=i;
while (j>1 && inArray(j-1)>temp)
inArray(j)=inArray(j-1);
j=j-1;
end
inArray(j)=temp;
end
out=inArray;

??? Input argument "inArray" is undefined.

Error in ==> insertionSort at 11
for i=1:length(inArray)

function out=my_cos(x, N, varargin)

%check for eps
if length(varargin)>1
disp('number of arguments must be 2 or 3!!')
return;
elseif length(varargin)==1
eps=varargin{1};
else
eps=0;
end

%start estimation
result=0;
for i=0:N-1
%calculate i-th term
numerator=(-1)^i;
denom=factorial(2*i);
factor=x^(2*i);
temp=(numerator/denom)*factor;
%compare to eps
if abs(temp)>eps
result=result+temp;
else
break;
end
end
out=result;

error for the above code
??? Input argument "N" is undefined.

Error in ==> my_cos at 15
for i=0:N-1

View Full Posting Details