Borrar filtros
Borrar filtros

I cant work out whick way to structure this code. Multiple functions with multiple inputs/outputs

1 visualización (últimos 30 días)
function [ fs, f0, d, t, y, call ] = CallingFunction()
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
end
function [ f0,fs,d ] = Funktion1 ( )
% This function reads in Duration, Fundamental & Sample frequencies
% Accepts inputs
f0 = input('Enter the Fundamental frequency, :');
fs = input('Enter the Sample frequency, :');
d = input('Enter the Duration, :');
end
function [ t, y ] = Funktion2( f0 , fs , d )
%UNTITLED4 Summary of this function goes here
% Creates Time vector & Sinusoid vector
t=0:1/fs:d;
y1=sin(2*pi*f0*t);
y2=sin(2*pi*2*f0*t);
y3=sin(2*pi*3*f0*t);
y=y1+y2+y3;
end
function [ ] = Funktion3( fs , t , y )
%%Plot & play results
% Read in decay parameters
K = input('Value of K; :');
%%Create exp decay fn
A=(K*exp(-1.5*t)).*sin(2*pi*0.65*t);
call=A.*y;
%%Play through sound card & plot
soundsc(call,fs)
plot(t,call)
end

Respuesta aceptada

Star Strider
Star Strider el 16 de Feb. de 2015
Editada: Star Strider el 16 de Feb. de 2015
Just guessing here, because I’m not certain what you’re doing.
Perhaps this will do what you want:
function [ fs, f0, d, t, y, call ] = CallingFunction()
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
[ f0,fs,d ] = Funktion1;
[ t, y ] = Funktion2( f0 , fs , d );
Funktion3( fs , t , y );
end
Also, define whatever you want your ‘call’ variable to be, somewhere in ‘CallingFunction’. If you don’t, it will throw an error that ‘call’ is unassigned.
  4 comentarios
Star Strider
Star Strider el 16 de Feb. de 2015
You most likely need to suggest a range of sample rates and check to be certain the sample rate is correct. See the documentation for soundsc for details.
The sample rate (sampling frequency) needs to be at least twice the highest frequency of the signal.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Signal Generation and Preprocessing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by