How to use ouput of a function as input of second function

2 ビュー (過去 30 日間)
moonman
moonman 2011 年 10 月 18 日
I have written a function
function [dtmf]=dtmfseg(x);
Now i want to use the output of this fuction as input to second function
fucntion ss=dtmfscor(dtmf,freq,L,fs)
How it is possible

回答 (4 件)

Fangjun Jiang
Fangjun Jiang 2011 年 10 月 18 日
Well, if you have those two functions defined, you can use:
dtmf=dtmfseg(x);
ss=dtmfscor(dtmf,freq,L,fs);
or one line
ss=dtmfscor(dtmfseq(x),freq,L,fs);

Michael
Michael 2011 年 10 月 18 日
[dtmf]=dtmfseg(x); ss=dtmfscor(dtmf,freq,L,fs);
or dtmfscor(dtmfseg(x),freq,L,fs);

moonman
moonman 2011 年 10 月 18 日
Can u help me for this part of book, I have written the code but i am stuck now
The next objective is decoding - a process that requires a binary decision on the presence or absence of the individual frequencies. In order to make the signal detection an automated process, we need a score function that rates the different possibilities. (a) Complete the dtmfscor function based on the skeleton given in Table 2. Assume that the input signal xx to the dtmfscor function is actually a short segment from the DTMF signal. The task of breaking up the signal so that each segment corresponds to one key will be done by another function prior to calling dtmfscor. The implementation of the FIR bandpass filter is done with the conv function. The running time of the convolution function is proportional to the filter length L. Therefore, the filter length L must satisfy two competing constraints: L should be large so that the bandwidth of the band pass filter is narrow enough to isolate individual DTMF frequencies, but making it too large will cause the program to run slowly.
Table 2: Skeleton of the dtmfscor.m function
function ss = dtmfscor(xx, freq, L, fs)
%DTMFSCOR
% ss = dtmfscor(xx, freq, L, [fs])
% returns 1 (TRUE) if freq is present in xx
% 0 (FALSE) if freq is not present in xx
% xx = input DTMF signal
% freq = test frequency
% L = length of FIR bandpass filter
% fs = sampling freq (DEFAULT is 8000)
% The signal detection is done by filtering xx with a length L
% BPF, hh, squaring the output, and comparing with an arbitrary
% setpoint based on the average power of xx.
if (nargin < 4), fs = 8000; end;
hh = % define the bandpass filter coeffs here
ss = (mean(conv(xx,hh).^2) > mean(xx.^2)/5);
Here is my effort
function [dtmfseg]=dtmfseg(x);
%This function produces DTMF Tone corresponding to given
%key number
low_fg = [697 770 852 941]; % Low frequency group
high_fg = [1209 1336 1477]; % High frequency group
f = [];
seg=[];
for a=1:4,
for b=1:3,
f = [ f [low_fg(a);high_fg(b)] ];
end
end
disp('Table of Frequencies is shown')
table=f'
dur=.5; %Duration for each tone is .5 sec
fs=8000; % Sampling Freq is 8000 Hz for tones
tt=0:(1/fs):dur;
n=length(x);
D=cell(1,n);
xx=cell(1,n);
for k=1:n % This loop will continue for number of keys
if x(k)==1
freqa=table(1,1); %Freq is picked from table(row1,col1)
freqb=table(1,2); %Freq is picked from table(row1,col2)
else if x(k)==2
freqa=table(2,1);
freqb=table(2,2);
else if x(k)==3
freqa=table(3,1);
freqb=table(3,2);
else if x(k)==4
freqa=table(4,1);
freqb=table(4,2);
else if x(k)==5
freqa=table(5,1);
freqb=table(5,2);
else if x(k)==6
freqa=table(6,1);
freqb=table(6,2);
else if x(k)==7
freqa=table(7,1);
freqb=table(7,2);
else if x(k)==8
freqa=table(8,1);
freqb=table(8,2);
else if x(k)==9
freqa=table(9,1);
freqb=table(9,2);
else if x(k)=='*'
freqa=table(10,1);
freqb=table(10,2);
else if x(k)==0
freqa=table(11,1);
freqb=table(11,2);
else x(k)='#';
freqa=table(12,1);
freqb=table(12,2);
end
end
end
end
end
end
end
end
end
end
end
% Both the tones are generated
tone1=sin(2*pi*freqa*tt); % Tone of First Frequency
tone2=sin(2*pi*freqb*tt); % Tone of Second Frequency
tone=tone1+tone2; % Now both tones are added
%***** We are making this loop to pick the segment of tone of each %key*****
for w=1:500
seg(w)=tone(w); % making segment
sil_dur=.1; % Defining silence duration between tones
sil_freq=0; % Since we want to keep silence, so frequency is zero
sil_tt=0:(1/fs):sil_dur;
sil_tone=sin(2*pi*sil_freq*sil_tt); % Generating silence tone
D{k} = [tone,sil_tone]; % Concatinatiing tones and then silence
xx{k}=[seg];
end %end of for loop
dtmfseg = cat(2, xx{:})
Plz Plz guide me and help me

moonman
moonman 2011 年 10 月 18 日
Wayne King plz help me I am badly stuck with this portion

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by